Skip to content

Commit

Permalink
change r8 rules to reduce apk size
Browse files Browse the repository at this point in the history
  • Loading branch information
lings03 committed Oct 29, 2024
1 parent dbaeb83 commit 114dbb1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 38 deletions.
9 changes: 8 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ android {
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
ndk {
debugSymbolLevel = "NONE"
}
signingConfig = signingConfigs.getByName("release")
}
getByName("debug") {
signingConfig = signingConfigs.getByName("release")
}

}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
Expand All @@ -99,6 +102,10 @@ android {
useLegacyPackaging = false
}
resources {
excludes += "/META-INF/DEPENDENCIES"
excludes += "/META-INF/LICENSE"
excludes += "/META-INF/NOTICE"
excludes += "/META-INF/ASL2.0"
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
Expand Down
44 changes: 7 additions & 37 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,49 +1,29 @@
# 项目特定的 ProGuard 规则
-allowaccessmodification
-repackageclasses

-keepclasseswithmembernames,includedescriptorclasses class * {
native <methods>;
-keepclassmembers class * implements android.os.Parcelable {
public static final ** CREATOR;
}
# 保留枚举类的值和 valueOf 方法

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

# 保留 Parcelable 的 CREATOR 字段
-keepclassmembers class * implements android.os.Parcelable {
public static final ** CREATOR;
-keepclasseswithmembernames,includedescriptorclasses class * {
native <methods>;
}

# 忽略特定类的警告
-dontwarn org.slf4j.impl.StaticLoggerBinder
-dontwarn org.conscrypt.Conscrypt
-dontwarn androidx.window.extensions.**
-dontwarn androidx.window.sidecar.Sidecar*

# 保留行号信息以便调试
-keepattributes LineNumberTable

# 允许访问修改和重新打包类
-allowaccessmodification
-repackageclasses

# 保留特定包下的所有类和成员
-keep class net.sf.sevenzipjbinding.** { *; }
-keep class top.laoxin.modmanager.** { *; }
-keep class com.example.model.** { *; }
-keep class okhttp3.** { *; }
-keep class com.squareup.okhttp.** { *; }
-keep class okhttp3.Call { *; }
-keep class okhttp3.Interceptor { *; }
-keep class okhttp3.Request { *; }
-keep class okhttp3.Response { *; }
-keep class okhttp3.internal.** { *; }

# 保留所有类的名称和成员
-keepnames class * { *; }
-keepclassmembers class * { *; }

# 保证 Gson 不被混淆
-keep class com.google.gson.** { *; }
-keep class com.google.gson.stream.** { *; }
-keepclassmembers class * {
Expand All @@ -52,13 +32,3 @@
-keepclassmembers class * {
@com.google.gson.annotations.Expose *;
}
-keepclassmembers class * {
@com.google.gson.annotations.Since *;
}
-keepclassmembers class * {
@com.google.gson.annotations.Until *;
}
-keepclassmembers class * {
@com.google.gson.annotations.JsonAdapter *;
}

0 comments on commit 114dbb1

Please sign in to comment.