Optimize Proguard rules (#4291)
Using saner defaults for R8 while reducing the app size even further. - Add Kotlin compiler options to skip adding assertions in release builds - Remove `optimizations`, `optimizationpasses` and `dontpreverify` rules that are ignored by R8 - Only keep runtime annotations by default. If other attributes are needed by a specific library, these will already be provided by the library rules (for example Retrofit or coroutines) - Remove the obsolete rule allowing a View to reflectively call any arbitrary public Activity method accepting a View as argument. This has always been a bad practice and is not used in this project anyway - Remove the rules related to enums. R8 already optimizes enums properly out-of-the-box and keeping these rules may prevent some of these optimizations - Add support for the `@Keep` annotation. Even if it's not currently used in the code base, it can be handy in the future - Add a missing rule to prevent generic signature of `NetworkResult` class from being removed in `MastodonApi` so Retrofit works - Allow obfuscation and shrinking of `kotlin.coroutines.Continuation`, matching the rule defined in the next release of Retrofit - Remove the rule forcing the removal of `String.format()`. This method is actually used in the code (and in third-party libraries) for other things than logging so forcing its removal can do more harm than good.
This commit is contained in:
parent
40fde54e0b
commit
722b75e5c2
2 changed files with 28 additions and 27 deletions
|
@ -48,6 +48,14 @@ android {
|
||||||
minifyEnabled true
|
minifyEnabled true
|
||||||
shrinkResources true
|
shrinkResources true
|
||||||
proguardFiles 'proguard-rules.pro'
|
proguardFiles 'proguard-rules.pro'
|
||||||
|
|
||||||
|
kotlinOptions {
|
||||||
|
freeCompilerArgs = [
|
||||||
|
"-Xno-param-assertions",
|
||||||
|
"-Xno-call-assertions",
|
||||||
|
"-Xno-receiver-assertions"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
47
app/proguard-rules.pro
vendored
47
app/proguard-rules.pro
vendored
|
@ -1,42 +1,36 @@
|
||||||
# GENERAL OPTIONS
|
# GENERAL OPTIONS
|
||||||
|
|
||||||
# turn on all optimizations except those that are known to cause problems on Android
|
|
||||||
-optimizations !code/simplification/cast,!field/*,!class/merging/*
|
|
||||||
-optimizationpasses 6
|
|
||||||
-allowaccessmodification
|
-allowaccessmodification
|
||||||
-dontpreverify
|
|
||||||
|
|
||||||
-dontusemixedcaseclassnames
|
# Preserve some attributes that may be required for reflection.
|
||||||
-dontskipnonpubliclibraryclasses
|
-keepattributes RuntimeVisible*Annotations, AnnotationDefault
|
||||||
-keepattributes *Annotation*
|
|
||||||
|
|
||||||
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
|
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
|
||||||
-keepclasseswithmembernames class * {
|
-keepclasseswithmembernames class * {
|
||||||
native <methods>;
|
native <methods>;
|
||||||
}
|
}
|
||||||
# keep setters in Views so that animations can still work.
|
|
||||||
# see http://proguard.sourceforge.net/manual/examples.html#beans
|
|
||||||
-keepclassmembers public class * extends android.view.View {
|
|
||||||
void set*(***);
|
|
||||||
*** get*();
|
|
||||||
}
|
|
||||||
# We want to keep methods in Activity that could be used in the XML attribute onClick
|
|
||||||
-keepclassmembers class * extends android.app.Activity {
|
|
||||||
public void *(android.view.View);
|
|
||||||
}
|
|
||||||
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
|
|
||||||
-keepclassmembers enum * {
|
|
||||||
public static **[] values();
|
|
||||||
public static ** valueOf(java.lang.String);
|
|
||||||
}
|
|
||||||
-keepclassmembers class * implements android.os.Parcelable {
|
-keepclassmembers class * implements android.os.Parcelable {
|
||||||
public static final ** CREATOR;
|
public static final ** CREATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
-keepclassmembers class **.R$* {
|
# Preserve annotated Javascript interface methods.
|
||||||
public static <fields>;
|
-keepclassmembers class * {
|
||||||
|
@android.webkit.JavascriptInterface <methods>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The support libraries contains references to newer platform versions.
|
||||||
|
# Don't warn about those in case this app is linking against an older
|
||||||
|
# platform version. We know about them, and they are safe.
|
||||||
|
-dontnote androidx.**
|
||||||
|
-dontwarn androidx.**
|
||||||
|
|
||||||
|
# This class is deprecated, but remains for backward compatibility.
|
||||||
|
-dontwarn android.util.FloatMath
|
||||||
|
|
||||||
|
# These classes are duplicated between android.jar and core-lambda-stubs.jar.
|
||||||
|
-dontnote java.lang.invoke.**
|
||||||
|
|
||||||
# TUSKY SPECIFIC OPTIONS
|
# TUSKY SPECIFIC OPTIONS
|
||||||
|
|
||||||
# keep members of our model classes, they are used in json de/serialization
|
# keep members of our model classes, they are used in json de/serialization
|
||||||
|
@ -73,9 +67,8 @@
|
||||||
-keep,allowobfuscation,allowshrinking class kotlin.collections.Map
|
-keep,allowobfuscation,allowshrinking class kotlin.collections.Map
|
||||||
-keep,allowobfuscation,allowshrinking class retrofit2.Call
|
-keep,allowobfuscation,allowshrinking class retrofit2.Call
|
||||||
|
|
||||||
# https://r8.googlesource.com/r8/+/refs/heads/master/compatibility-faq.md#retrofit
|
# https://github.com/square/retrofit/pull/3563
|
||||||
-keepattributes Signature
|
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
|
||||||
-keep class kotlin.coroutines.Continuation
|
|
||||||
|
|
||||||
# preserve line numbers for crash reporting
|
# preserve line numbers for crash reporting
|
||||||
-keepattributes SourceFile,LineNumberTable
|
-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
Loading…
Reference in a new issue