I am trying to obfuscate my Android App with Proguard. But I ran into a strange issue and I hope one of you guys would is able to help me out.
-keep class android.support.v4.** { *; }
-keep public class com.mysql.** {*;}
-keep class com.actionbarsherlock.** {*;}
-dontwarn android.support.v4.**
-dontwarn com.mysql.**
-libraryjars /libs/mysql-connector-java-5.1.27-bin.jar
-dontshrink
-keepattributes *Annotation*
So as you can see I already added that mysql JDBC lib as libary and as class which should be kept. But when I try to compile the project to an .apk file I am ending up with this strange Error. I don't know why as it shouldn't even be touched, according to my config.
Proguard returned with error code 1. See console
Note: there were 508 duplicate class definitions.
You should check if you need to specify additional program jars.
Unexpected error while evaluating instruction:
Class = [com/mysql/jdbc/ConnectionImpl]
Method = [isReadOnly(Z)Z]
Instruction = [77] iload v4
Exception = [java.lang.NullPointerException] (null)
Unexpected error while performing partial evaluation:
Class = [com/mysql/jdbc/ConnectionImpl]
Method = [isReadOnly(Z)Z]
Exception = [java.lang.NullPointerException] (null)
Error: null
Fixed by updating Proguard to the new 5.0 version.
Related
I've installed the Facebook SDK and has no errors but I can't seem to export it as part of my android project. I get the below error when enabling ProGuard:
Warning: com.facebook.applinks.FacebookAppLinkResolver$2: can't find referenced class bolts.Task$TaskCompletionSource
Warning: com.facebook.applinks.FacebookAppLinkResolver$2: can't find referenced class bolts.AppLink$Target
Warning: com.facebook.applinks.FacebookAppLinkResolver$2: can't find referenced class bolts.AppLink
Warning: com.facebook.applinks.FacebookAppLinkResolver$2: can't find referenced class bolts.AppLink$Target
Warning: com.facebook.messenger.MessengerUtils: can't find referenced class bolts.AppLinks
Warning: com.facebook.messenger.MessengerUtils: can't find referenced class bolts.AppLinks
You should check if you need to specify additional program jars.
Warning: there were 62 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)
I added the below to my ProGuard file but I still get the error:
-keep class com.facebook.** {
*;
}
How should I configure ProGuard to use the Facebook SDK?
I am using these settings in my proguard-project.txt:
# Facebook Audience Network
-keep class com.facebook.ads.** { *; }
-keep class com.facebook.ads.internal.** { *; }
-keep class com.google.ads.mediation.facebook.FacebookAdapter {*;}
-keep class com.google.android.exoplayer.** {*;}
-dontwarn com.facebook.ads.**
-dontwarn com.google.android.exoplayer.**
ProGuard is telling you that the Facebook SDK references classes in the bolts package but ProGuard can't find those classes because, most likely, you're not including Bolts in your application.
To fix this, you can either:
Tell ProGuard to ignore the missing dependency by adding the line
-dontwarn bolts.**
to the ProGuard configuration file. Doing this shouldn't cause a problem because the Facebook SDK can detect internally whether Bolts is present and only try to use it in that case.
Add Bolts as a dependency of your project by putting these lines in your Gradle file:
dependencies {
compile 'com.parse.bolts:bolts-tasks:1.4.0'
compile 'com.parse.bolts:bolts-applinks:1.4.0'
}
Option 1 is probably the best choice unless you actually need Bolts.
I run my ProGuard for my Android project and get the following warnings:
Note: duplicate definition of library class [org.apache.http.conn.scheme.HostNameResolver]
Note: duplicate definition of library class [org.apache.http.conn.scheme.SocketFactory]
Note: duplicate definition of library class [org.apache.http.conn.ConnectTimeoutException]
Note: duplicate definition of library class [org.apache.http.params.HttpParams]
Note: duplicate definition of library class [android.net.http.SslCertificate$DName]
Note: duplicate definition of library class [android.net.http.SslError]
Note: duplicate definition of library class [android.net.http.SslCertificate]
Note: there were 7 duplicate class definitions.
I found here to fix this with ignoring it with:
-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**
-keep class android.net.http.** { *; }
-dontwarn android.net.http.**
I do not see a way to remove the duplicates from the used libraries. Even after using dontwarn the warnings do not vanish.
Is this the right way of handling this warning in just ignoring it or could this lead to problems?
If you add a proguard option -printconfiguration config.txt you'll see proguard adds
-libraryjars 'D:\tools\android\platforms\android-23\android.jar'
-libraryjars 'D:\tools\android\platforms\android-23\optional\org.apache.http.legacy.jar'
your duplicated classes (e.g. SslError) are presented in both android.jar and org.apache.http.legacy.jar
Proguard adds second jar even if you don't useLibrary 'org.apache.http.legacy'
Here is an open bug describing the problem.
So now we can't do anything with the issue. Just ignore it:
-dontnote android.net.http.*
-dontnote org.apache.commons.codec.**
-dontnote org.apache.http.**
There is no need to keep the classes as long as they are located in library jar (phone's library actually).
dontwarn doesn't work because it's not a warning, it's a note.
Probably, you have mentioned "-injars" and -libraryjars" in your proguard-project.txt,considering the latest build system takes care of mentioning them for you ..so you dont need to mention it again.
source:
http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass
I think this will help.:)
You can tell gradle not to allow duplicate classes (take only the first) by adding the following to your build.gradle:
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
You can try this in your build.gradle for everything that is indicated as duplicate in the logs. I am not sure if this will work, so try it out and inform if it works or not.
packagingOptions {
exclude 'android.net.http.SslCertificate'
}
I am using Eclipse for Mac.
When I want to export a signed apk I get a "Proguard returned with error code 1. See console" error.
I have these 2 files in my project root folder:
"proguard-android.txt" and "project.properties"
Inside project.properties I have:
target=android-17
proguard.config=proguard-project.txt
android.library.reference.1=../google-play-services_lib
android.library.reference.2=../FacebookSDK
Among many other warnings I get when I try to create a signed apk, I get:
com.my.app.va.debug.ConfigureLog4j: can't find referenced class de.mindpipe.android.logging.log4j.LogConfigurator
com.my.app.va.debug.HockeyAppHelper: can't find referenced class net.hockeyapp.android.ExceptionHandler
I already put these lines inside "proguard-android.txt" , but the errors persist:
-keep public class de.mindpipe.android.logging.**
-dontwarn de.mindpipe.android.logging.**
-keep public class net.hockeyapp.**
-dontwarn net.hockeyapp.**
What could I be doing wrong?
UPDATE:
I have changed the filename from "proguard-android.txt" to "proguard-project" and added this to my Proguard, and the "referenced class" error messages are gone:
-dontwarn de.mindpipe.android.**
-keep public class de.mindpipe.android.**
-dontwarn net.hockeyapp.android.**
-keep public class net.hockeyapp.android.**
Neverthless... Is this an actual solution? or, am I just hiding the problem?
Other warnings still persist:
Warning: com.facebook.widget.UserSettingsFragment: can't find referenced method 'android.support.v4.app.FragmentActivity getActivity()' in class com.facebook.widget.UserSettingsFragment
Warning: there were 138 unresolved references to program class members.
The proguard file name should be defined in project.properties if using Eclipse or in build.gradle if using Gradle or Android Studio.
It usually contains proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt.
You should also include the following:
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
More official info at http://developer.android.com/tools/help/proguard.html.
Some other relevant stackoverflow discussions: How to config my proguard-project.txt file to remove just Logs and How to automatically generate proguard-android.txt?
I'm using Eclipse, And I'm using ActionBarSherlock.
Proguard was showing so many warnings for other libraries too, something about java/javax
and I fixed all of them by adding this line to Proguard:
-libraryjars C:\Program Files\Java\jre7\lib\rt.jar(java/**,javax/**)
Except this one, I don't know which library it needs and how to add it to -libraryjars:
Warning: com.actionbarsherlock.internal.view.menu.ActionMenuView$LayoutParams: can't find referenced method 'LinearLayout$LayoutParams(android.widget.LinearLayout$LayoutParams)' in class android.widget.LinearLayout$LayoutParams
I don't want to use -dontwarn option, it will cause crashes in the future. I want to fix all of the warnings. only this one left to fix.
thanks.
Add this line to the end of your proguard config file. -keep public class com.actionbarsherlock.** and -dontwarn com.actionbarsherlock.**
After exporting signed package from eclipse, application started crashing when one of activities is invoked.
05-30 23:05:43.814: E/AndroidRuntime(11578): FATAL EXCEPTION: main
05-30 23:05:43.814: E/AndroidRuntime(11578): java.lang.NoClassDefFoundError: com.encryptomatic.alockbin.ItemListActivity
I completely excluded that class from obfuscation with all members and I see it listed in seeds.txt .
Only difference from other activities is that this one extends SherlockFragmentActivity.
I excluded dependencies altogether using:
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keepattributes *Annotation*
What could be wrong here? How can I check if my class really ended in apk?
The quick answer is: ProGuard was unable to detect that the class com.encryptomatic.alockbin.ItemListActivity is used by your code and therefore has removed it. This can happen if it is loaded dynamically or in a different unusual way.
Therefore if you use ProGuard you should simply add the mentioned class as class to "keep":
-keep class com.encryptomatic.alockbin.ItemListActivity { public *; }
Then re-build the APK and try it. Test all features of your app as most likely there are other classes that has to be configured to keep. If you have identified all classes also check the ProGuard warnings as they usually contain other classes that may be wise to keep.
android-support-v4.jar was not set to export under Java Build Path in project properties:
Right click on Project -> Properties -> Java Build Path -> Order and export -> Check checkbox "Android private libraries" (the node where android-support-v4.jar resides on Library tab)