Optimize apk size (#263)

This commit is contained in:
vvb2060 2021-03-04 18:00:22 +08:00 committed by GitHub
parent 490aeae95d
commit cb5940bc1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 33 deletions

View File

@ -81,7 +81,8 @@ android {
named("release") {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
signingConfig = signingConfigs.named("debug").get()
proguardFiles("proguard-rules.pro")
}
named("debug") {
isMinifyEnabled = false
@ -90,17 +91,36 @@ android {
}
applicationVariants.all {
outputs.map { it as BaseVariantOutputImpl }.forEach { output ->
output.outputFileName = "LSPosedManager-${defaultConfig.versionName}-${defaultConfig.versionCode}-${buildType.name}.apk"
output.outputFileName = "LSPosedManager-${verName}-${verCode}-${buildType.name}.apk"
}
}
}
val optimizeReleaseResources = task("optimizeReleaseRes").doLast {
val aapt2 = Paths.get(project.android.sdkDirectory.path, "build-tools", project.android.buildToolsVersion, "aapt2")
val zip = Paths.get(project.buildDir.path, "intermediates", "processed_res", "release", "out", "resources-release.ap_")
val optimizeReleaseRes = task("optimizeReleaseRes").doLast {
val aapt2 = Paths.get(
project.android.sdkDirectory.path,
"build-tools",
project.android.buildToolsVersion,
"aapt2"
)
val zip = Paths.get(
project.buildDir.path,
"intermediates",
"optimized_processed_res",
"release",
"resources-release-optimize.ap_"
)
val optimized = File("${zip}.opt")
val cmd = exec {
commandLine(aapt2, "optimize", "--collapse-resource-names", "-o", optimized, zip)
commandLine(
aapt2,
"optimize",
"--collapse-resource-names",
"--enable-sparse-encoding",
"-o",
optimized,
zip
)
isIgnoreExitValue = false
}
if (cmd.exitValue == 0) {
@ -110,8 +130,8 @@ val optimizeReleaseResources = task("optimizeReleaseRes").doLast {
}
tasks.whenTaskAdded {
if (name == "shrinkReleaseRes") {
finalizedBy(optimizeReleaseResources)
if (name == "optimizeReleaseResources") {
finalizedBy(optimizeReleaseRes)
}
}

View File

@ -1,28 +1,12 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
-renamesourcefileattribute
-keep class io.github.lsposed.manager.Constants { *; }
-keepclasseswithmembers class io.github.lsposed.manager.receivers.LSPosedManagerServiceClient {
private static android.os.IBinder binder;
}
-keepclassmembers class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
public static void check*(...);
public static void throw*(...);
@ -31,3 +15,6 @@
public static *** v(...);
public static *** d(...);
}
-repackageclasses
-allowaccessmodification

View File

@ -120,7 +120,7 @@ android {
}
named("release") {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
proguardFiles("proguard-rules.pro")
externalNativeBuild {
cmake {

View File

@ -22,13 +22,16 @@
-keep class de.robv.android.xposed.** {*;}
-keep class android.** { *; }
-keepclassmembers class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-keepclasseswithmembers class io.github.lsposed.lspd.core.Main {
public static void forkSystemServerPost(android.os.IBinder);
public static void forkAndSpecializePost(java.lang.String, java.lang.String, android.os.IBinder);
public static void main(java.lang.String[]);
}
-keepnames class io.github.lsposed.lspd.hooker.HandleBindAppHooker
-keepclasseswithmembers class io.github.lsposed.lspd.nativebridge.* {
-keepclasseswithmembers,includedescriptorclasses class * {
native <methods>;
}
-keepclasseswithmembers class io.github.lsposed.lspd.nativebridge.ClassLinker {
@ -45,3 +48,5 @@
public static *** v(...);
public static *** d(...);
}
-repackageclasses
-allowaccessmodification

View File

@ -41,7 +41,7 @@ android {
buildTypes {
named("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
proguardFiles("proguard-rules.pro")
}
}

View File

@ -19,4 +19,7 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keepclasseswithmembers class io.github.lsposed.lspd.Application { *; }
-keepclasseswithmembers class io.github.lsposed.lspd.Application { *; }
-keepclassmembers class * implements android.os.Parcelable {
public static final ** CREATOR;
}