I've been using Android Studio since the initial release without any ProGuard issues. Suddenly today it has stopped working. As far as I know any files which would interfere with Proguard have not changed. For instance my ProGuard config file remains untouched, and ActionBarSherlock (one of the modules now experiencing errors) was not changed in any way since the last successful build.
The error log recommended using -dontskipnonpubliclibraryclassmembers however that does not resolve the issue. Running ProGuard with the included default configuration rather than my own still results in the same errors.
From what I can make of it, when Android Studio is building my app, the modules are now being stripped from the app. I'm not sure if it's just not passing the appropriate flags to ProGuard or if Proguard is removing them on its own.
Some relevant logs:
ProGuard: [Meditation Assistant] Warning: com.actionbarsherlock.widget.SuggestionsAdapter: can't find referenced field 'android.content.Context mContext' in class com.actionbarsherlock.widget.SuggestionsAdapter
ProGuard: [Meditation Assistant] Warning: com.actionbarsherlock.widget.SuggestionsAdapter: can't find referenced method 'android.database.Cursor getCursor()' in class com.actionbarsherlock.widget.SuggestionsAdapter
ProGuard: [Meditation Assistant] Warning: com.actionbarsherlock.widget.SuggestionsAdapter: can't find referenced field 'android.database.Cursor mCursor' in class com.actionbarsherlock.widget.SuggestionsAdapter
--snip--
ProGuard: [Meditation Assistant] You should check if you need to specify additional program jars.
ProGuard: [Meditation Assistant] Warning: there were 10 unresolved references to classes or interfaces.
ProGuard: [Meditation Assistant] You may need to specify additional library jars (using '-libraryjars').
ProGuard: [Meditation Assistant] Warning: there were 191 unresolved references to program class members.
The message
Warning: there were 10 unresolved references to classes or interfaces.
suggests that ProGuard can't find some classes that are required. These classes are listed in ProGuard's earlier console output. You should check that all the necessary jars are in the directory 'libs'. In this case, android-support-v4.jar might be missing.
I solved it adding the following line to proguard-project.txt:
-libraryjars libs/android-support-v4.jar
In case of using Eclipse do not forget to clean the project before exporting the APK.
Related
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.
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.
I have a project that is using the new RenderScript support library and is also using proguard for obfuscation.
Proguard was working great on the code when using the normal RenderScript SDK (android.renderscript.*). And the code is working great with the RenderScript support library when compiled in a non-release build where proguard does not run.
But, bring the two together and the result is this:
Warning: android.support.v8.renderscript.RenderScript: can't find referenced class android.os.SystemProperties
Warning: android.support.v8.renderscript.RenderScript: can't find referenced class android.os.SystemProperties
Warning: android.support.v8.renderscript.RenderScriptThunker: can't find referenced method 'android.renderscript.RenderScript create(android.content.Context,int)' in class android.renderscript.RenderScript
You should check if you need to specify additional program jars.
Warning: there were 2 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
Warning: there were 1 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile them and try again.
Alternatively, you may have to specify the option
'-dontskipnonpubliclibraryclassmembers'.
I know just enough about proguard to be dangerous. One thing I have learned is that the suggestions in the warning/error messages tend not to necessarily point at the actual cause of the issue. This time is no different: implementing the suggested changes in the warnings results in no change of the output.
Can the RenderScript support library be used with proguard? And if so, is there some magic that I need to add to my proguard config to make it work?
-dontwarn android.support.v8.**
actually encountered this yesterday...
For androidX
-keep class androidx.renderscript.** { *; }
Combining the previous two ansers, in any modern app that uses Renderscript, you should add the follwing to your proguard-rules.pro file.
# Render Script
-keep class android.support.v8.renderscript.** { *; }
-keep class androidx.renderscript.** { *; }
This will take care of both apps that use the Android support library, or Android X
Have errors on exporting android app and proguard. Without using proguard, app works ok. I have com.commonsware.cwac.endless.EndlessAdapter library as third party in my code, and proguard throws that error when exporting the project...
Proguard returned with error code 1. See console
Warning: com.commonsware.cwac.endless.EndlessAdapter: can't find referenced field 'java.util.concurrent.Executor THREAD_POOL_EXECUTOR' in class android.os.AsyncTask
Warning: com.commonsware.cwac.endless.EndlessAdapter: can't find referenced method 'android.os.AsyncTask executeOnExecutor(java.util.concurrent.Executor,java.lang.Object[])' in class android.os.AsyncTask
You should check if you need to specify additional program jars.
Warning: there were 2 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile them and try again.
Alternatively, you may have to specify the option '-dontskipnonpubliclibraryclassmembers'.
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:321)
at proguard.ProGuard.initialize(ProGuard.java:211)
at proguard.ProGuard.execute(ProGuard.java:86)
at proguard.ProGuard.main(ProGuard.java:492)
Any idea? Something extra to put in my proguard-project.txt??? Thankssss
This field and this method are only available in android-11 or higher, so you should build against the target android-11 or higher. Can can still specify a different targetSdkVersion in your AndroidManifest.xml file.
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.