Skip to content
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

Switching to guava 20.0 make Proguard fails when shrink and minify #2926

Closed
eldk opened this issue Aug 25, 2017 · 10 comments
Closed

Switching to guava 20.0 make Proguard fails when shrink and minify #2926

eldk opened this issue Aug 25, 2017 · 10 comments

Comments

@eldk
Copy link

eldk commented Aug 25, 2017

Hello,

Switching to Guava 20.0 as suggested in Android Studio make release build failed when it's done with Proguard shrinkRessources or/and minifyEnabled enabled.

Rollback to Guava 18.0 "solves" it.

Warning: com.google.common.util.concurrent.FuturesGetChecked$GetCheckedTypeValidatorHolder$ClassValueValidator$1: can't find superclass or interface java.lang.ClassValue Warning: com.google.common.base.AbstractIterator: can't find referenced class com.google.errorprone.annotations.CanIgnoreReturnValue
(...)
Warning: there were 696 unresolved references to classes or interfaces. You may need to add missing library jars or update their versions. If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options.

Warning: Exception while processing task java.io.IOException: Please correct the above warnings first. :app:transformClassesAndResourcesWithProguardForRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> Job failed, see logs for details

Android Studio 2.3.3
Gradle 3.3
Proguard 4.7
JRE1.8.0_122

Thanks,

Eric

@jbduncan
Copy link
Contributor

@eldk Have you tried updating to the latest version of guava-android (23.0, I believe) instead? :)

@jbduncan
Copy link
Contributor

(You can find the Maven/Gradle co-ordinates for guava-android at https://search.maven.org/#artifactdetails%7Ccom.google.guava%7Cguava%7C23.0-android%7Cbundle).

@eldk
Copy link
Author

eldk commented Aug 25, 2017

I have tryed with Guava 19.0 and 23.0-android with same result as 20.0 : Proguard complains about unresolved dependencies. Less warning for 23.0-android.

@jbduncan
Copy link
Contributor

Thanks for letting me know the results of applying 23.0-android @eldk! This is out of my league now unfortunately, so let's wait for someone from the Guava team to reply.

@eldk
Copy link
Author

eldk commented Aug 25, 2017

Thanks @jbduncan

@cpovirk
Copy link
Member

cpovirk commented Aug 28, 2017

We need to publish our Proguard configurations someday (#2117). For this particular problem, you can add:

-dontwarn java.lang.ClassValue

(We have a fallback for systems on which ClassValue isn't available.)

@eldk
Copy link
Author

eldk commented Aug 28, 2017

Hello,

With :
-dontwarn java.lang.ClassValue
Proguard (4.7) still throws errors.

In #2117 the link to that topic https://stackoverflow.com/questions/9120338/proguard-configuration-for-guava-with-obfuscation-and-optimization gives the solution for Guava 20.0 .

-dontwarn com.google.common.base.**
-keep class com.google.common.base.** {*;}
-dontwarn com.google.errorprone.annotations.**
-keep class com.google.errorprone.annotations.** {*;}
-dontwarn com.google.j2objc.annotations.**
-keep class com.google.j2objc.annotations.** { *; }
-dontwarn java.lang.ClassValue
-keep class java.lang.ClassValue { *; }
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-keep class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement { *; }

Thanks @cpovirk , @breyed, @gengjiawen

Eric

@eldk eldk closed this as completed Aug 28, 2017
@JakeWharton
Copy link

JakeWharton commented Aug 28, 2017 via email

@eldk
Copy link
Author

eldk commented Aug 28, 2017

@JakeWharton

Hello,

You are right, -keep are not needed.

I will spend more time on it.

https://www.guardsquare.com/en/proguard/manual/troubleshooting#unresolvedclass

With -keep at right, without to left :
kept-not-kept

With -keep up, without down :
kept-not-kept-count

Thanks,

Eric

@eldk eldk reopened this Aug 28, 2017
@eldk eldk closed this as completed Aug 29, 2017
@renyuneyun
Copy link

renyuneyun commented Nov 18, 2017

I'm a bit confused (maybe because my understanding is not complete): why are all the "keep"s unnecessary?

My feeling is that only those can be safely removed (i.e. have fallback) should not be "keep"(-ed), but the only one with fallback is sun.misc.Unsafe.
Why don't we need to keep others, e.g. java.lang.ClassValue or even com.google.common.base.**? Doesn't -dontwarn just supress the warning but still removes these classes (so that these classes will not be in the compiled file (.apk), and will cause errors like "ClassNotFound")?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants