Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ProGuard: can't find referenced class

Running ProGuard in my Android Studio Project I get warnings like this:

Warning: com.google.common.collect.Maps: can't find referenced class javax.annotation.Nullable

I might solve this with one of this variants:

1

-keep class com.google.common.collect.** { *; }
-dontwarn com.google.common.collect.**

2

-keep class javax.annotation.** { *; }
-dontwarn javax.annotation.**

What is the best way to solve the above warning? What is the difference between variant 1. and 2.?

like image 235
confile Avatar asked Oct 10 '15 00:10

confile


People also ask

How do you keep a class in ProGuard?

-keepclassmembernames. This is the most permissive keep directive; it lets ProGuard do almost all of its work. Unused classes are removed, the remaining classes are renamed, unused members of those classes are removed, but then the remaining members keep their original names.

What is Dontwarn in ProGuard?

If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options. ( http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass) Warning: there were 2 unresolved references to program class members. Your input classes appear to be inconsistent.

Is minifyEnabled true?

Code shrinking with R8 is enabled by default when you set the minifyEnabled property to true .

What is consumerProguardFiles?

consumerProguardFiles 'consumer-rules.pro'} A consumer proguard rules file is like any other proguard rules files with the caveat that the rules inside it are automatically applied to the consuming application when the application is being built in a proguard enabled mode.


1 Answers

This is the most common error beacuse of "many pre-compiled third-party libraries refer to other libraries that are not actually used and therefore not present. This works fine in debug builds, but in release builds, ProGuard expects all libraries, so it can perform a proper static analysis."

From: http://proguard.sourceforge.net/index.html#manual/examples.html

So,this javax.annotation.Nullable might not be there in your project but the libraries you are using has some classes who are internally referring to them.

However you can avoid these warnings by -dontwarn javax.annotation.** or --dontwarn com.google.common.collect.** . But I dont think -keep class javax.annotation.** { *; } and looks illogical.

So, if you do -keep class com.google.common.collect.** { *; } you skip this package from all 3 steps of Proguard execution (Shrinking,optimization and obfuscation) which makes sense according to my understanding.

like image 83
Sankalp Pandya Avatar answered Oct 05 '22 08:10

Sankalp Pandya