Reinstate Proguard/R8 (#5134)

* Reinstate Proguard/R8

According to APK analyzer
Before: 18044 classes with 113387 methods in 3 dex files
After: 12604 classes with 68010 methods in 2 dex files
APK download size is reduced by 2.8 MB

* Add debug build type without R8
This commit is contained in:
Ivan Iskandar 2021-05-23 01:47:40 +07:00 committed by GitHub
parent 147978b932
commit 89fb943733
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 44 deletions

View file

@ -55,18 +55,25 @@ android {
named("debug") { named("debug") {
versionNameSuffix = "-${getCommitCount()}" versionNameSuffix = "-${getCommitCount()}"
applicationIdSuffix = ".debug" applicationIdSuffix = ".debug"
isShrinkResources = true
isMinifyEnabled = true
proguardFiles("proguard-android-optimize.txt", "proguard-rules.pro")
}
create("debugFull") { // Debug without R8
initWith(getByName("debug"))
isShrinkResources = false
isMinifyEnabled = false
} }
named("release") { named("release") {
/*named("postprocessing") { isShrinkResources = true
postprocessing { isMinifyEnabled = true
isObfuscate = false proguardFiles("proguard-android-optimize.txt", "proguard-rules.pro")
isOptimizeCode = true
isRemoveUnusedCode = false
isRemoveUnusedResources = true
} }
setProguardFiles(listOf(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"))
}*/
} }
sourceSets {
getByName("debugFull").res.srcDirs("src/debug/res")
} }
flavorDimensions("default") flavorDimensions("default")
@ -76,9 +83,6 @@ android {
buildConfigField("boolean", "INCLUDE_UPDATER", "true") buildConfigField("boolean", "INCLUDE_UPDATER", "true")
dimension = "default" dimension = "default"
} }
create("fdroid") {
dimension = "default"
}
create("dev") { create("dev") {
resConfigs("en", "xxhdpi") resConfigs("en", "xxhdpi")
dimension = "default" dimension = "default"

View file

@ -0,0 +1,34 @@
-allowaccessmodification
-dontusemixedcaseclassnames
-verbose
-keepattributes *Annotation*
-keepclasseswithmembernames,includedescriptorclasses class * {
native <methods>;
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-keep class androidx.annotation.Keep
-keep @androidx.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <init>(...);
}

View file

@ -1,29 +1,16 @@
-dontobfuscate -dontobfuscate
# Extensions may require methods unused in the core app # Keep extension's common dependencies
-dontwarn eu.kanade.tachiyomi.** -keep,allowoptimization class eu.kanade.tachiyomi.** { public protected *; }
-keep class eu.kanade.tachiyomi.** { public protected private *; } -keep,allowoptimization class kotlin.** { public protected *; }
-keep,allowoptimization class okhttp3.** { public protected *; }
-keep,allowoptimization class rx.** { public protected *; }
-keep,allowoptimization class org.jsoup.** { public protected *; }
-keep,allowoptimization class com.google.gson.** { public protected *; }
-keep,allowoptimization class com.github.salomonbrys.kotson.** { public protected *; }
-keep,allowoptimization class com.squareup.duktape.** { public protected *; }
-keep class org.jsoup.** { *; } ##---------------Begin: proguard configuration for RxJava 1.x ----------
-keep class kotlin.** { *; }
-keep class okhttp3.** { *; }
-keep class com.google.gson.** { *; }
-keep class com.github.salomonbrys.kotson.** { *; }
-keep class com.squareup.duktape.** { *; }
# Design library
-dontwarn com.google.android.material.**
-keep class com.google.android.material.** { *; }
-keep interface com.google.android.material.** { *; }
-keep public class com.google.android.material.R$* { *; }
-keep class com.hippo.image.** { *; }
-keep interface com.hippo.image.** { *; }
-keepclassmembers class * extends nucleus.presenter.Presenter {
<init>();
}
# RxJava 1.1.0
-dontwarn sun.misc.** -dontwarn sun.misc.**
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* { -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
@ -39,30 +26,38 @@
rx.internal.util.atomic.LinkedQueueNode consumerNode; rx.internal.util.atomic.LinkedQueueNode consumerNode;
} }
# ReactiveNetwork -dontnote rx.internal.util.PlatformDependent
-dontwarn com.github.pwittchen.reactivenetwork.** ##---------------End: proguard configuration for RxJava 1.x ----------
## GSON ##
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard # Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it. # removes such information by default, so configure it to keep all of it.
-keepattributes Signature -keepattributes Signature
# Gson specific classes # For using GSON @Expose annotation
-keep class sun.misc.Unsafe { *; } -keepattributes *Annotation*
# Prevent proguard from stripping interface information from TypeAdapterFactory, # Gson specific classes
-dontwarn sun.misc.**
# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter) # JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory -keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer -keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer -keep class * implements com.google.gson.JsonDeserializer
# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}
##---------------End: proguard configuration for Gson ----------
## kotlinx.serialization ## ##---------------Begin: proguard configuration for Kotlin Serializer ----------
-keepattributes *Annotation*, InnerClasses -keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.AnnotationsKt # core serialization annotations -dontnote kotlinx.serialization.AnnotationsKt # core serialization annotations
# kotlinx-serialization-json specific. Add this if you have java.lang.NoClassDefFoundError kotlinx.serialization.json.JsonObjectSerializer
-keepclassmembers class kotlinx.serialization.json.** { -keepclassmembers class kotlinx.serialization.json.** {
*** Companion; *** Companion;
} }
@ -77,3 +72,4 @@
-keepclasseswithmembers class eu.kanade.tachiyomi.** { -keepclasseswithmembers class eu.kanade.tachiyomi.** {
kotlinx.serialization.KSerializer serializer(...); kotlinx.serialization.KSerializer serializer(...);
} }
##---------------End: proguard configuration for Kotlin Serializer ----------