Fix release builds

This commit is contained in:
topjohnwu 2021-05-11 18:40:30 -07:00
parent 408399eae0
commit 09a294c219
2 changed files with 6 additions and 27 deletions

View File

@ -183,6 +183,8 @@ android.applicationVariants.all {
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(kotlin("stdlib"))
// Some dependencies request JDK 8 stdlib, specify manually here to prevent version mismatch
implementation(kotlin("stdlib-jdk8"))
implementation(project(":app:shared"))
implementation("com.github.topjohnwu:jtar:1.0.0")

View File

@ -1,5 +1,4 @@
import com.android.build.gradle.BaseExtension
import java.nio.file.Paths
plugins {
id("MagiskPlugin")
@ -30,24 +29,8 @@ tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
val Project.android get() = extensions.getByName<BaseExtension>("android")
fun Task.applyOptimize() = doLast {
val aapt2 = Paths.get(project.android.sdkDirectory.path,
"build-tools", project.android.buildToolsVersion, "aapt2")
val zip = Paths.get(project.buildDir.path, "intermediates",
"shrunk_processed_res", "release", "resources-release-stripped.ap_")
val optimized = File("${zip}.opt")
val cmd = exec {
commandLine(aapt2, "optimize", "--collapse-resource-names",
"--shorten-resource-paths", "-o", optimized, zip)
isIgnoreExitValue = true
}
if (cmd.exitValue == 0) {
zip.toFile().delete()
optimized.renameTo(zip.toFile())
}
}
fun Project.android(configuration: BaseExtension.() -> Unit) =
extensions.getByName<BaseExtension>("android").configuration()
subprojects {
repositories {
@ -59,7 +42,7 @@ subprojects {
afterEvaluate {
if (plugins.hasPlugin("com.android.library") ||
plugins.hasPlugin("com.android.application")) {
android.apply {
android {
compileSdkVersion(30)
buildToolsVersion = "30.0.3"
ndkPath = "${System.getenv("ANDROID_SDK_ROOT")}/ndk/magisk"
@ -86,14 +69,8 @@ subprojects {
}
}
tasks.whenTaskAdded {
if (name == "shrinkReleaseRes") {
finalizedBy(tasks.create("optimizeReleaseRes").applyOptimize())
}
}
if (name == "app" || name == "stub") {
android.apply {
android {
signingConfigs {
create("config") {
Config["keyStore"]?.also {