Yokan / rebuild
Course 1 8624561

build.gradle.kts

vendor/kmp-mpv/android-bridge/build.gradle.kts

configuration / resource132 lines
1import java.net.URI2import java.nio.file.Files3import java.nio.file.StandardCopyOption4import java.security.MessageDigest56plugins {7    alias(libs.plugins.android.library)8    `maven-publish`9}1011data class MediaKitAndroidArtifact(12    val abi: String,13    val url: String,14    val sha256: String,15)1617val mediaKitAndroidArtifacts = listOf(18    MediaKitAndroidArtifact(19        "arm64-v8a",20        "https://github.com/Schnitzel5/libmpv-android-video-build/releases/download/0.39.0/default-arm64-v8a.jar",21        "db5cf9abd385771092921dff6db0a216a8926deba4d683698d7f8d13467063b7",22    ),23    MediaKitAndroidArtifact(24        "armeabi-v7a",25        "https://github.com/Schnitzel5/libmpv-android-video-build/releases/download/0.39.0/default-armeabi-v7a.jar",26        "130d77e4ecf9f4c83c5b49fa6f9774004bb9a6def684f4381e4a38e6e21ae752",27    ),28    MediaKitAndroidArtifact(29        "x86_64",30        "https://github.com/Schnitzel5/libmpv-android-video-build/releases/download/0.39.0/default-x86_64.jar",31        "faf41da663c2b70c11acb665918b484c28e8392e4be26fdbf8c7994af0054fd9",32    ),33    MediaKitAndroidArtifact(34        "x86",35        "https://github.com/Schnitzel5/libmpv-android-video-build/releases/download/0.39.0/default-x86.jar",36        "0bf2693c5830af3d1619b359c6d6a6eff804a9753ea31b36a2ecabc14359a44b",37    ),38)3940val mediaKitAndroidDirectory = layout.buildDirectory.dir("media-kit-mpv/android-0.39.0")41val mediaKitAndroidJars = mediaKitAndroidArtifacts.map { artifact ->42    mediaKitAndroidDirectory.map { it.file("default-${artifact.abi}.jar") }43}4445val fetchMediaKitAndroidMpv = tasks.register("fetchMediaKitAndroidMpv") {46    description = "Downloads the Lua-enabled Android libmpv artifacts pinned by media-kit."47    group = "mpv binaries"48    outputs.files(mediaKitAndroidJars)4950    doLast {51        val digest = MessageDigest.getInstance("SHA-256")52        mediaKitAndroidArtifacts.zip(mediaKitAndroidJars).forEach { (artifact, destinationProvider) ->53            val destination = destinationProvider.get().asFile54            destination.parentFile.mkdirs()5556            fun checksum(file: File): String = digest.digest(Files.readAllBytes(file.toPath()))57                .joinToString("") { byte -> "%02x".format(byte) }5859            if (destination.isFile && checksum(destination) == artifact.sha256) return@forEach6061            val temporary = destination.resolveSibling("${destination.name}.part")62            temporary.delete()63            URI(artifact.url).toURL().openStream().use { input ->64                Files.copy(input, temporary.toPath(), StandardCopyOption.REPLACE_EXISTING)65            }66            val actual = checksum(temporary)67            check(actual == artifact.sha256) {68                "SHA-256 mismatch for ${artifact.abi}: expected ${artifact.sha256}, got $actual"69            }70            Files.move(71                temporary.toPath(),72                destination.toPath(),73                StandardCopyOption.REPLACE_EXISTING,74                StandardCopyOption.ATOMIC_MOVE,75            )76        }77    }78}7980val bundledMediaKitAndroidMpv = files(mediaKitAndroidJars).builtBy(fetchMediaKitAndroidMpv)8182dependencies {83    api(bundledMediaKitAndroidMpv)84}8586android {87    namespace = "io.github.kmpmpv.bridge"88    compileSdk = 3689    buildToolsVersion = "36.1.0"90    ndkVersion = "28.2.13676358"9192    defaultConfig {93        minSdk = 2494        externalNativeBuild {95            cmake {96                // No C++ objects cross the bridge ABI, so static libc++ avoids app packaging collisions.97                arguments += "-DANDROID_STL=c++_static"98                abiFilters += listOf("arm64-v8a", "armeabi-v7a", "x86", "x86_64")99            }100        }101        consumerProguardFiles("consumer-rules.pro")102    }103104    externalNativeBuild {105        cmake {106            path = file("src/main/cpp/CMakeLists.txt")107            version = "3.22.1"108        }109    }110111    compileOptions {112        sourceCompatibility = JavaVersion.VERSION_11113        targetCompatibility = JavaVersion.VERSION_11114    }115116    publishing {117        singleVariant("release") {118            withSourcesJar()119        }120    }121}122123afterEvaluate {124    publishing {125        publications {126            register<MavenPublication>("release") {127                from(components["release"])128                artifactId = "kmp-mpv-android-bridge"129            }130        }131    }132}133

Search chapters, reference and source filenames.