Skip to content

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

Merged
merged 1 commit into from
May 29, 2020

Conversation

mkj-gram
Copy link
Contributor

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

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
@elizarov
Copy link
Contributor

I'm not sure I understand why it should not be needed? Can you please elaborate?

@mkj-gram
Copy link
Contributor Author

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:
-keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {}

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:
-keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {}

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.

@elizarov
Copy link
Contributor

Could you then, please, add the missing -keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler in kotlinx-coroutines-android too, in the same PR and rebase your PR to develop branch of the library.

@mkj-gram mkj-gram changed the base branch from master to develop May 27, 2020 08:54
@mkj-gram
Copy link
Contributor Author

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:

and that is why the class stays in the output, and not because of the -keepnames rule.

Rebased on the developer branch.

@elizarov elizarov self-requested a review May 29, 2020 08:52
Copy link
Contributor

@elizarov elizarov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good.

@elizarov elizarov merged commit 3a8a0ea into Kotlin:develop May 29, 2020
@elizarov elizarov mentioned this pull request Jul 16, 2020
1 task
@OscarSpruit
Copy link
Contributor

OscarSpruit commented Jul 20, 2020

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.

@elizarov
Copy link
Contributor

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 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?

@OscarSpruit
Copy link
Contributor

I'm not allowed to share the build files, but I will try to make a sample project that reproduces it later today.
We use AGP version 4.0.1 and R8 as minifier

@OscarSpruit
Copy link
Contributor

OscarSpruit commented Jul 20, 2020

@elizarov I couldn't get a sample to reproduce it working, but I think I found the cause and fixed it with #2154

recheej pushed a commit to recheej/kotlinx.coroutines that referenced this pull request Dec 28, 2020
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants