How to find out which classes cannot be resolved by ProGuard Android - android

After adding ProGuard rules for all libraries I am using, I still get this warning:
Warning: there were 14 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.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
I know that I can probably use the -dontwarn option to get rid of this warning, but therefore I need to know which packages/classes/interfaces cannot be resolved. Android does not support a global "-dontwarn".
In the log file I find so many Notes and Warnings, but none of them seem to relate the above message.

If you receive a Warning: there were X unresolved references to classes or interfaces then look for lines in your build log that contain the word Warning, such as this:
Warning: com.package.Class1: can't find referenced class org.library.Class2
Lines like this will tell which classes ProGuard is trying to work on and which classes can't be found in the input jars. In the example above, class Class1 would reference Class2 of a library but Class2 was not found in the build path.
As you mentioned, you can simply add -dontwarn <class regex> to ignore those warnings but ideally you should check them one-by-one to make sure that your configuration is correct and all required dependencies are being imported correctly.

Related

Proguard broke react native android

After enabling proguard in my react native project, I've been getting countless notes and errors from all the packages, com.facebook.react, okhttp3, okio, and every other 3rd party library that I'm using including org.reactnative.camera, com.lwansbrough.RCTCamera, com.horcrux.svg and more. Shouldn't the default proguard rules already take care of some of the default packages?
After countless hours looking for solution that includes the obvious -dontnote and -dontwarn, as well as attempting to -keep all the classes mentioned, each time I manage to get rid of a couple of the warnings there is always more warnings.
Do I really have to manually go through every single reference to use proguard? Sometimes I don't even know which class to keep and ignore when using other libraries. Please help.
Note: there were 4 references to unknown classes.
You should check your configuration for typos.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
Note: there were 1 references to unknown class members.
You should check your configuration for typos.
Note: there were 835 unkept descriptor classes in kept class members.
You should consider explicitly keeping the mentioned classes
(using '-keep').
(http://proguard.sourceforge.net/manual/troubleshooting.html#descriptorclass)
Note: there were 70 unresolved dynamic references to classes or interfaces.
You should check if you need to specify additional program jars.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Warning: there were 1620 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.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 1 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.
Thread(Tasks limiter_14): destruction

Proguard warnings about duplicate class definitions, but doesn't print out the duplicate classes

I'm trying to change the version of a library in my app, but I think I'm getting some kind of conflicts with another version of some dependency that another library I'm using is trying to use. It warns me about duplicate class definitions, but then goes on only to print out specific examples of the next warning category (in this case unresolved class definitions).
...
:RedactedApp:proguardDebug
Note: there were 644 duplicate class definitions (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Warning: redacted.package.ClassName: can't find superclass or interface other.redacted.package.ClassName2
...
...
Warning: there were 12 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.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 5 unresolved references to library class members.
You probably need to update the library versions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Is there a way to force proguard to actually print out the names of detected duplicate classes? I already have -verbose enabled in my proguard file.
While I couldn't find a way to get proguard to actually print out the duplicate classes, I was able to get a good view of dependencies via a gradle (2.9) command:
gradle -q dependencies :RedactedAppName:dependencies --configuration compile
This gave me a good graphical view of a lot of redundant imports I had.

Getting "unresolved references" and "can't find superclass" warnings from Proguard

I have integrated some third-party source into my android project and I'm having trouble getting it to build with proguard enabled. The build is failing with this:
Warning: there were 123 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.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 201 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.
:app:transformClassesAndResourcesWithProguardForRelease FAILED
FAILURE: Build failed with an exception.
There are MANY notes and warnings to sort through and I can't make heads or tails of it. I have tried adding --keep class example.package.** { *; } for everything that seems to be causing warnings, but it is still failing. Can anyone suggest a strategy for dealing with issues like this? For example, if I see this:
Warning: info.guardianproject.netcipher.client.MyDefaultClientConnectionOperator: can't find superclass or interface ch.boye.httpclientandroidlib.impl.conn.DefaultClientConnectionOperator
what should I do about it?
Adding the following to your proguard-file will solve the compile problem:
-dontwarn info.guardianproject.netcipher.**
That said, you should read up on any ramifications that would come with this. Proguard is usually giving warnings for a good reason.
The reason you get those warnings is that guardianproject messed up with dependencies. As you can see here NetCipher does not have any dependencies. And httpclientandroidlib is clearly an outern project. Inside Netcipher they have built the .jar library and not packaging it into their library. Unfortunately, httpclientandroidlib is not available through jcenter dependency.
There are two solutions:
Proposed by #Tommie: add
-dontwarn info.guardianproject.netcipher.**
to you proguard-rules.pro file if those dependecies are not necessary. You just get rid of warning, sometimes it is a good way. But usually does not work. Then go to step two
You need to add httpclientandroidlib manually to your project.
Download a project from github as .zip
Add new module to your project, name it httpclientandroidlib (name is arbitrary. I name it like that just for reference)
Copy folder structure ch.boye.httpclientandroidlib to new module's src folder
Replace module's AndroidManifest with the one from httpclientandroidlib library.
Add dependecy to your main aa module:
compile project(':httpclientandroidlib')
Then you can start working with the project.

Android Studio 0.5.0 rebuild not working with Proguard

Recently I updated Android Studio from 0.4.2 to 0.5.0 and Android Gradle Plug-In from 0.7.2 to 0.9.0 as the IDE suggested. The project runs and installs good but when I press Build->Rebuild Project it throws an error, which stops the rebuild.
Here is an error in Messages tab:
Information:See complete output in console
Error:Execution failed for task ':projectName:proguardDebug'.
> java.io.IOException: Please correct the above warnings first.
And here is the problem discribed in the console:
:projectName:proguardDebug
Note: there were 2345 duplicate class definitions.
Warning: com.facebook.Settings: can't find referenced class com.facebook.android.BuildConfig
Warning: com.facebook.Settings: can't find referenced class com.facebook.android.BuildConfig
Warning: com.facebook.internal.Utility: can't find referenced class com.facebook.android.BuildConfig
Warning: com.facebook.internal.Utility: can't find referenced class com.facebook.android.BuildConfig
Warning: there were 4 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.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
:projectName:proguardDebug FAILED
FAILURE: Build failed with an exception.
As I understood, the problem is missing BuildConfig.java, which was in /gen folder before I migrated from Eclipse. But now there is not /gen folder and BuildConfig.java is in the /build/source/buildConfig/debug/ forlder.
I found the only sollution that really does something to this, it is adding the line
-dontwarn com.facebook.**
to the proguard config file, but it isn't really the sollution.
The problem is that our libraries don't package BuildConfig. This is because we allow (for now) libraries to have the same package name. we are going to change this.
This shouldn't be a problem as BuildConfig is only constants that should get inlined in the code anyway. You can do a temp fix with excluding only BuildConfig:
-dontwarn com.facebook.android.BuildConfig
We'll probably fix this soon.
From the link in the warning:
If the missing class is referenced from a pre-compiled third-party library, and your original code runs fine without it, then the missing dependency doesn't seem to hurt. The cleanest solution is to filter out the referencing class or classes from the input, with a filter like "-libraryjars mylibrary.jar(!somepackage/SomeUnusedReferencingClass.class)". ProGuard will then skip this class entirely in the input, and it will not bump into the problem of its missing reference. However, you may then have to filter out other classes that are in turn referencing the removed class. In practice, this works best if you can filter out entire unused packages at once, with a wildcard filter like "-libraryjars mylibrary.jar(!someunusedpackage/**)".
If you don't feel like filtering out the problematic classes, you can try your luck with the -ignorewarnings option, or even the -dontwarn option. Only use these options if you really know what you're doing though.

socialauth-android: proguard errors when exporting apk

Using socialauth-android, when I try to export my project I get these warnings:
Warning: org.brickred.socialauth.util.SocialAuthUtil: can't find referenced class javax.servlet.http.HttpServletRequest
Warning: there were 111 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: there were 140 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code or update the library versions.
Alternatively, you may have to specify the option
'-dontskipnonpubliclibraryclassmembers'.
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:330)
at proguard.ProGuard.initialize(ProGuard.java:212)
at proguard.ProGuard.execute(ProGuard.java:87)
at proguard.ProGuard.main(ProGuard.java:484)
Could someone help?
Problem is gone using this proguard cfg:
-keep class org.brickred.** { *; } -dontwarn org.brickred.**
Do you have the jars directly in your libs? Or are you getting them through maven? Which sdk version are you running?
If you add jars in at compile time, it might not get included in proguard processing. The jars has to be in place after pre-build target is ran.

Categories

Resources