-
-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize Proguard rules #4291
Optimize Proguard rules #4291
Conversation
…ts for R8, add support for the @keep annotation and tweak some existing rules.
Thx!
not necessary, these rules are included in the annotation library
not necessary, that rule is included in the NetworkResult library
I disagree, it will only be removed if the result is not used. Take this line as an example: The log statement is removed, but without the |
…d restore the orphaned String.format() removal rule
I didn't know that, thanks for the info. I'll remove this from my other projects as well.
I didn't think about checking the CallAdapter library rules first, indeed it makes sense to provide the rule with the library.
Indeed, in the case of However, this also means that there are probably other kinds of String formatting code that end up orphaned after removing the Log calls. Ideally the Log calls should be replaced with Kotlin inline functions taking a lamba argument (where all the formatting takes place) and checking a global boolean constant before logging, that's the only reliable way to remove all logging code and its associated formatting. But that's another topic entirely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shaves about 200kB off the apk size, very nice.
…4299) Regression from #4291 // cc @cbeyls <details> <summary>Stacktrace</summary> ``` Process: com.keylesspalace.tusky, PID: 31230 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.keylesspalace.tusky/com.keylesspalace.tusky.components.accountlist.AccountListActivity}: java.lang.RuntimeException: java.lang.NoSuchMethodException: h4.a.values [] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3635) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7839) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: h4.a.values [] at java.lang.Enum.enumValues(Enum.java:270) at java.lang.Enum.access$000(Enum.java:61) at java.lang.Enum$1.create(Enum.java:277) at java.lang.Enum$1.create(Enum.java:275) at libcore.util.BasicLruCache.get(BasicLruCache.java:63) at java.lang.Enum.getSharedConstants(Enum.java:289) at java.lang.Enum.valueOf(Enum.java:243) at java.io.ObjectInputStream.readEnum(ObjectInputStream.java:1841) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1409) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:427) at android.os.Parcel.readSerializable(Parcel.java:3507) at android.os.Parcel.readValue(Parcel.java:3277) at android.os.Parcel.readArrayMapInternal(Parcel.java:3623) at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292) at android.os.BaseBundle.unparcel(BaseBundle.java:236) at android.os.BaseBundle.getSerializable(BaseBundle.java:1268) at android.os.Bundle.getSerializable(Bundle.java:1104) at android.content.Intent.getSerializableExtra(Intent.java:8575) at com.keylesspalace.tusky.components.accountlist.AccountListActivity.onCreate(SourceFile:23) at android.app.Activity.performCreate(Activity.java:8051) at android.app.Activity.performCreate(Activity.java:8031) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7839) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) Caused by: java.lang.NoSuchMethodException: h4.a.values [] at java.lang.Class.getMethod(Class.java:2103) at java.lang.Class.getDeclaredMethod(Class.java:2081) at java.lang.Enum.enumValues(Enum.java:267) at java.lang.Enum.access$000(Enum.java:61) at java.lang.Enum$1.create(Enum.java:277) at java.lang.Enum$1.create(Enum.java:275) at libcore.util.BasicLruCache.get(BasicLruCache.java:63) at java.lang.Enum.getSharedConstants(Enum.java:289) at java.lang.Enum.valueOf(Enum.java:243) at java.io.ObjectInputStream.readEnum(ObjectInputStream.java:1841) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1409) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:427) at android.os.Parcel.readSerializable(Parcel.java:3507) at android.os.Parcel.readValue(Parcel.java:3277) at android.os.Parcel.readArrayMapInternal(Parcel.java:3623) at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292) at android.os.BaseBundle.unparcel(BaseBundle.java:236) at android.os.BaseBundle.getSerializable(BaseBundle.java:1268) at android.os.Bundle.getSerializable(Bundle.java:1104) at android.content.Intent.getSerializableExtra(Intent.java:8575) at com.keylesspalace.tusky.components.accountlist.AccountListActivity.onCreate(SourceFile:23) at android.app.Activity.performCreate(Activity.java:8051) at android.app.Activity.performCreate(Activity.java:8031) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7839) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) ``` </details> closes #4297
Using saner defaults for R8 while reducing the app size even further.
optimizations
,optimizationpasses
anddontpreverify
rules that are ignored by R8@Keep
annotation. Even if it's not currently used in the code base, it can be handy in the futureNetworkResult
class from being removed inMastodonApi
so Retrofit workskotlin.coroutines.Continuation
, matching the rule defined in the next release of RetrofitString.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.