diff --git a/app/build.gradle b/app/build.gradle index 500e4e3..af183d6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,3 +1,5 @@ +import java.nio.file.Paths + apply plugin: 'com.android.application' apply plugin: 'kotlin-android' @@ -11,6 +13,7 @@ if (localFile.canRead()) { android { compileSdkVersion target_sdk + buildToolsVersion build_tool_version defaultConfig { applicationId "moe.haruue.wadb" minSdkVersion min_sdk @@ -56,6 +59,29 @@ android { dependenciesInfo.includeInApk false } +def optimizeReleaseResources = task('optimizeReleaseResources').doLast { + def aapt2 = Paths.get(project.android.sdkDirectory.path, 'build-tools', project.android.buildToolsVersion, 'aapt2') + def zip = Paths.get(project.buildDir.path, 'intermediates', + 'processed_res', 'release', 'out', "resources-release.ap_") + def optimized = new File("${zip}.opt") + def cmd = exec { + commandLine aapt2, 'optimize', '--collapse-resource-names', + '--shorten-resource-paths', + '-o', optimized, zip + ignoreExitValue false + } + if (cmd.exitValue == 0) { + delete(zip) + optimized.renameTo("$zip") + } +} + +tasks.whenTaskAdded { task -> + if (task.name == 'processReleaseResources') { + task.finalizedBy optimizeReleaseResources + } +} + android.applicationVariants.all { variant -> variant.outputs.all { outputFileName = "wadb-v${variant.versionName}.apk" diff --git a/gradle.properties b/gradle.properties index bcaeb16..4b1f814 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,4 @@ #Fri Oct 21 14:57:45 CST 2016 android.useAndroidX=true android.debug.obsoleteApi=true -android.enableResourceOptimizations=true \ No newline at end of file +android.enableResourceOptimizations=false diff --git a/manifest.gradle b/manifest.gradle index ed2208e..ce6a8cf 100644 --- a/manifest.gradle +++ b/manifest.gradle @@ -1,6 +1,7 @@ ext { - gradle_plugin_version = '4.1.2' + gradle_plugin_version = '4.1.3' kotlin_version = '1.4.32' + build_tool_version = '30.0.3' min_sdk = 23 target_sdk = 30