-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Remove keep rules mentioning kotlinx.coroutines.android #2061
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
Conversation
The rule -keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {} is present in kotlinx.coroutines.android/META-INF/proguard/coroutines.pro and should therefore not be needed. If the -keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {} is needed, it should go into kotlinx.coroutines.android/META-INF/proguard/coroutines.pro
I'm not sure I understand why it should not be needed? Can you please elaborate? |
The type kotlinx.coroutines.android.AndroidDispatcherFactory do not exist in the kotlinx-coroutines-core package, it is a type that is found in the kotlinx-coroutines-android package (as far as I can see). When proguard or R8 reads kotlinx-coroutines-core for projects where kotlinx-coroutines-android is not referenced, the shrinkers will see the rule -keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {} but since that type is missing it will have no effect - and R8 will print information about the rule being unused. For android projects, where kotlinx-coroutines-android is referenced, it could have an effect. But kotlinx-coroutines-android defines its own META-INF/proguard/coroutines.pro file, that includes the rule: As a result, removing the above rule should not make any difference except that warnings are no longer printed from R8. Now, the kotlinx-coroutines-android do not define: However, the type is only defined in the kotlinx-coroutines-android package, so if it is important for kotlinx-coroutines-android to function correctly, it should be defined there and not in kotlinx-coroutines-core. |
Could you then, please, add the missing |
Just checked again and that rule should not be necessary - for one, the -keepnames will only keep the name if the class survives the shrinking phase and there seem to not be any reflective call in the codebase to kotlinx.coroutines.android.AndroidExceptionPreHandler. Additionally, the class itself is marked with @keep: kotlinx.coroutines/ui/kotlinx-coroutines-android/src/AndroidExceptionPreHandler.kt Line 13 in 583ec6e
and that is why the class stays in the output, and not because of the -keepnames rule. Rebased on the developer branch. |
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.
👍 Looks good.
This change broke the minified builds of our Android app. As a workaround we added the rules to our own ProGuard config. Might be nice to either document this or add the rules to a more suitable place, like kotlinx-coroutines-android. |
Can you share the build files that would reproduce the problem? What version of AGP and what kind of minifier are you using? |
I'm not allowed to share the build files, but I will try to make a sample project that reproduces it later today. |
…ule (Kotlin#2061) The rule -keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {} is present in kotlinx.coroutines.android/META-INF/proguard/coroutines.pro and should therefore is not needed.
The rule -keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {} is present in kotlinx.coroutines.android/META-INF/proguard/coroutines.pro and should therefore not be needed. If the -keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {} is needed, it should go into kotlinx.coroutines.android/META-INF/proguard/coroutines.pro