Trying to build an Android app via SBT, I find that I can android:package just fine unless I add "net.databinder.dispatch" %% "dispatch-core" % "0.11.2" in to libraryDependencies. If I add it, then I get the following (extremely long) Proguard error (full text):
Note: org.jboss.netty.util.internal.ByteBufferUtil: can't find dynamically referenced class java.nio.DirectByteBuffer
Note: org.jboss.netty.util.internal.ByteBufferUtil: can't find dynamically referenced class sun.misc.Cleaner
Note: there were 2 unresolved dynamic references to classes or interfaces.
Warning: there were 1828 unresolved references to classes or interfaces.
You should check if you need to specify additional program jars.
You may need to add missing library jars or update their versions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
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 7 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: there were 8 unresolved references to library class members.
You probably need to update the library versions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
preceded by a few thousand lines. android:compile works fine with or without Dispatch added.
Looking at the dispatch-classic docs suggests that Dispatch does not work well with Android, but mentions that the "future move to a different backend" (presumably implemented in the latest versions of dispatch) will rectify this.
I can't find any information about Dispatch and Android other than what's available for dispatch-classic.
Does the issue still exist? Should I just use a different library? Is it possible to modify my proguard-sbt.txt to make sure android:package can run?
It seems that Dispatch now plays nicely with Android. My issue previously was that, unknown to me, my proguard settings were being re-generated by sbt for every compile. Adding in -donwarn ** to my proguardOptions in my .sbt file fixes the above errors (although I should probably track down the more specific packages that need to be -dontwarn'd in the future).
With that being said, it seems that Dispatch's heavy-duty dependencies do pose a problem with the Android development pipeline: running android:package maxes out all 6 of my CPUs and uses > 1 GB of memory. I'm way over the 65k dex limit. I think I'll go in a different direction.
Related
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
I have updated my support lib to 26.0.1, but release build is failed.
logs
Note: there were 3 references to unknown classes.
You should check your configuration for typos.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
Note: there were 63 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 29 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)
Note: there were 1 class casts of dynamically created class instances.
You might consider explicitly keeping the mentioned classes and/or
their implementations (using '-keep').
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclasscast)
Warning: there were 30 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.
:purplleAndroid:transformClassesAndResourcesWithProguardForRelease FAILED
Not understanding due to which library proguard is failing.
proguard file
app level build.gradle
Error log
It's not support library issue,
I using library called branch.io ,i am added it's dependency end with "+".So it's updated and that has some progaurd rules.
I have enabled minifyEnabled in my gradle file for using the feature of ProGuard to obfuscates code as a result it throwing some error.
Note: there were 1 class casts of dynamically created class instances.
You might consider explicitly keeping the mentioned classes and/or
their implementations (using '-keep').
Warning: there were 309 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)
and much more.
I have gone through the ProGuard documentation.i guess this is what happening wrong.am using third party libraries and jars.and it confuses as i have more number of libraries and jars.how can i decide which one should keep in my proguard-rules.pro and which one doesn't ? And what else need to do for using ProGuard successfully and efficiently ?
ProGuard analyzes all the code in your application (that includes libraries) and generates warnings if it sees unresolved references (or other problems, but unresolved references is the important thing here). It is very common for libraries to refer to system or library code that doesn't exist in your project.
For example: Picasso optionally integrates with OkHttp, and has code referring to that library. But if you haven't included OkHttp ProGuard will warn about unresolved references.
A successful build must not have any warnings from ProGuard. ProGuard also checks for reflection, if there are unresolved references found in reflection, ProGuard will generate notes instead of warnings. Both warnings and notes may point to issues with the classpath. You could check the code yourself to see if there's an actual problem, or trust the libraries that their code works on Android (and on your target platform version).
Kevin Schultz opened up a public collection of ProGuard configuration files. His blogpost should help you get started with your configuration file.
http://www.kevinrschultz.com/blog/2014/02/15/proguard-with-gradle/
Do double check the configurations that you copy. They can be a little aggressive sometimes. If possible you want to avoid -dontwarn/dontnote {entire-package} and instead narrow down on the actual problems.
You need to add proguard rules specific to the libraries you use. A compilation of such rules is available at https://github.com/StarWar/android-proguard-snippets/tree/master/libraries
You can also try adding dontwarn directive for packages causing issues. An example of this would be -dontwarn org.codehaus.jackson.**
After updating to ADT 20 I can no longer successfully export any of my Android projects. I get:
Proguard returned with error code 1. See console
In the console I get tons of the can't find referenced class warnings and occasionally the can't find superclass or interface warning. At the end of the warnings I get something like this:
You should check if you need to specify additional program jars.
Warning: there were 199 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
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)
Each time I attempt to build I get different numbers of warnings (it's not very consistent). Also, when I perform a clean before export, the export completes without producing any warnings, but the resulting APK crashes on launch often due to ClassNotFoundException.
My proguard-project.txt includes the necessary -keep class rules for the Android Support Library and ActionBarSherlock.
I had no problems building this project before ADT 20. I even tried building my last release (which obviously built fine when I released it), but I get the same proguard warnings and failed export.
I've tried adding -libraryjars and/or -dontwarn rules as many other SO questions suggest, but to no avail. It will sometimes build successfully, but the APK created crashes on launch.
Any suggestions?
There is a bug in AAPT where it will only process
<fragment android:name"..." />
but not
<fragment class="..." />
We'll fix AAPT but in the meantime you can use the other attribute and it'll work.
In ADT 20, we use a feature of aapt (see the -G flag) which can create a proguard file which contains keep rules for exactly the custom views used by your code.
The old proguard config files would keep all views. When you used a library project such as the compatibility library, where you might be using only a small subset of the available code, this could end up including a lot of stuff you don't need. By removing the generic keep rules, and adding a new keep file based on your application, your .apks would get smaller since a lot of unused stuff can be removed.
One area where this can go wrong is if you update to Tools 20 (so you have the new smaller proguard-android.txt file), and you continue to use ADT 18. Make sure to use ADT 20, since it will add in not just the proguard files specified in your project.properties setting, but the generated proguard file listing the keep files from aapt -G as well. I believe the ant build will also use the -G feature.
(Note - see http://code.google.com/p/android/issues/detail?id=35107 for any followups on this)
Reportedly, there are problems with a recent update of the Eclipse plugin in the ADT, which doesn't properly recompile all source code. In that case, ProGuard will print out warnings about your program classes (as opposed to the library classes). You should check if the export (and the resulting application) works without ProGuard. You should also check if the Ant build works ("ant release"). That could then be a workaround.
I used to be able to follow the guide here to set up and run Proguard as part of a build, without any problems. However, since updating to the latest version of the ADT tools, I am having trouble. The first problem I run into is:
BUILD FAILED
/home/myhome/projects/myapp/add-proguard-release.xml:14:
/home/myhome/projects/myapp/${out.classes.dir} does not exist.
So I end up having to define ${out.classes.dir} manually in either local.properties or project.properties. Not the end of the world, but a bit of a pain.
The second, more drastic problem is related to external jars. I have a small class in an external jar. When the application launches on a device, the app crashes:
11-15 18:35:30.090: E/AndroidRuntime(28258): java.lang.NoClassDefFoundError: com.mysoftware.informaltimeprovider.InformalTimeProvider
11-15 18:35:30.090: E/AndroidRuntime(28258): at com.mysoftware.pagemonitor.PrintableTimeProvider.getInformalTime(PrintableTimeProvider.java:14)
It is crashing when trying to create an instance of InformalTimeProvider, but judging by the logcat output, this class was not obfuscated, so I don't know why there is a problem.
There is a warning during the build:
[proguard] Copying resources from program jar [/home/myhome/projects/pagemonitor/libs/InformalTimeProvider.jar]
[proguard] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [InformalTimeProvider.jar:META-INF/MANIFEST.MF])
It is just a warning though - I wouldn't expect a crash.
Any help gratefully received.
Barry
Proguard minimized apps mostly do not work out-of-the-box. In most cases you have to manually specify additional classes that needs to be kept.
In your case I would start by adding the configuration line
-keep class com.mysoftware.informaltimeprovider.InformalTimeProvider
This explicitly tells proguard that this class is required and can not be removed. If afterwards your app misses another class tell proguard to keep it, too.
Step-by-step you will get closer to a fully working app. I know this try-and-error approach is not nice but optimizing Java Apps is not that simple that it can be fully automated. Especially loading classes by Strings and other run-time related tricks collide with proguard.