Status Update
Comments
ch...@appspot.gserviceaccount.com <ch...@appspot.gserviceaccount.com> #2
I attached a repro project. This is the stacktrace printed from the Retrofit error (I included the keep rules for the Kodein issue):
java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:365)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:4)
at retrofit2.Retrofit$1.invoke(Retrofit.java:7)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy1.getAllBreeds(Unknown Source)
at com.example.api.DogBreedApiImpl.getAllBreeds(DogBreedApi.kt:5)
at com.example.kodein7.MainActivity$onCreate$1.invokeSuspend(MainActivity.kt:5)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:3)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:18)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7660)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
ch...@appspot.gserviceaccount.com <ch...@appspot.gserviceaccount.com> #3
ch...@appspot.gserviceaccount.com <ch...@appspot.gserviceaccount.com> #4
R8 fullmode will remove all attributes for classes that are not kept. Attributes and annotations can only be read by reflection and for full mode we require an explicit keep rule to keep the signatures (and other attributes).
As you point to, adding keep rules for the types in kodein will force R8 to keep the signatures.
For retrofit, you will have to keep the api classes. Interestingly, you also have to keep the kotlin.coroutines.Continuation as well. Adding the below rules fixes the issue in the sample for me (note, you should refine the keep rule for the api to only keep what is needed).
-keep class com.example.api.** { *; }
-keep class kotlin.coroutines.Continuation
I will make a pull request on retrofit to add kotlin.coroutines.Continuation
to the rules we consume.
ch...@appspot.gserviceaccount.com <ch...@appspot.gserviceaccount.com> #5
Will R8 strip the signature even if I have -keepattributes Signature
set in my rules?
If so, is there a rule that could be used to keep the signature just for the api classes?
ch...@appspot.gserviceaccount.com <ch...@appspot.gserviceaccount.com> #6
Yes, R8 in full-mode will strip all signatures for not-kept classes if using -keepattributes Signature
. The only way to keep the generic signature for a class is if you keep it.
Having a rule for only keeping certain attributes would actually be quite nice, sort of like:
-keep,Signature class com.example.api.* { *; }
would allow developers to more fine-grained describe what they would like to keep. It would break compatibility though.
We are btw removing all attributes for not kept classes, such as InnerClasses, EnclosingMethod etc.
ch...@appspot.gserviceaccount.com <ch...@appspot.gserviceaccount.com> #7
I found that -keep, allowobfuscation, allowoptimization class com.example.api.**Endpoints { *; }
fixes the issue (at least in the sample project).
Is this new behavior for 7.0.0 (or whatever version of R8 is used with it)? In AGP 4.2.0 this wasn't happening.
Maybe somewhat related, but it looks like consumerProguardFile
isn't working on AGP 7.0.0-beta01. I tried adding these rules to the consumer-rules.pro
file in their respective modules in my real project, and it didn't work unless I put it into my app module's proguard file.
The library gradle file (technically a buildSrc precompiled script) looks like:
plugins {
id("com.android.library")
}
android {
compileSdk = project.compileSdkVersion
defaultConfig {
consumerProguardFile(project.file("consumer-rules.pro"))
minSdk = project.minSdkVersion
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
...
}
Description
Internal (Googlers-only) Reports:
- Chromium:
(Legacy) Chromeperf Report:
Top 2 regressions (out of 5, with 3 improvements) in this group:
- ChromiumPerf/mac-m1_mini_2020-perf/v8.browsing_desktop/v8:gc:cycle:full:cpp_avg/browse_media/browse_media_tumblr_2018
52.96%: 7.9245 -> 12.121500000000001 ms
- ChromiumPerf/mac-m1_mini_2020-perf/v8.browsing_desktop/v8:gc:cycle:full_avg/browse_media/browse_media_tumblr_2018
39.51%: 32.772999999999996 -> 45.722 ms
Top 2 affected measurements in mac-m1_mini_2020-perf:
- v8.browsing_desktop/v8:gc:cycle:full:cpp_avg/browse_media/browse_media_tumblr_2018
52.96%: 7.9245 -> 12.121500000000001 ms
- v8.browsing_desktop/v8:gc:cycle:full_avg/browse_media/browse_media_tumblr_2018
39.51%: 32.772999999999996 -> 45.722 ms
Regressions grouped by v8.browsing_desktop includes data from the following benchmarks with listed owners:
v8.browsing_desktop: almuthanna@chromium.org, cbruni@chromium.org, vahl@chromium.org
Commits in this range:
Chromium Git Hash:
Chromium Commit Position:
V8 Commit Position:
WebRTC Git Hash: