java.lang.NoClassDefFoundError after proguard obfuscation - java

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)

Related

Android Facebook SDK Eclipse Proguard

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.

ProGuard: duplicate definition of library class?

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'
}

Proguard returned with error code 1 error when signing apk with many external libraries

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?

ProGuard config

I use ksoap2 library in my android project. When I use ProGuard to build my app, some of ksoap2 features not work any more.
As you know progaurding app when it contains ksoap2 library makes some conflicts. For resolving this issue I used 3 different proguard-configs and then delete xmlpull in library but still soap objects in ksoap2 not working after proguarding.
So My problem is this: "ksoap2 not work correctly after proguard" and
I want :"a proguard-config or some suggestion for this issue"
Here are part of codes that I used for proguard-comfig:
-libraryjars libs\ksoap2-android-assembly.jar
-dontwarn org.kobjects.**
-dontwarn org.ksoap2.**
-dontwarn org.kxml2.**
-dontwarn org.xmlpull.v1.**
then I add this too:
-keep class org.kobjects.** { *; }
-keep class org.ksoap2.** { *; }
-keep class org.kxml2.** { *; }
-keep class org.xmlpull.** { *; }
then I add this too:
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontoptimize
-dontpreverify
and I try deleting xmlpull too, but still ksoap2 doesn't work correctly after proguarding app.
Edit:
1- I have no error and building signed apk with using ProGuard done.
2- Every thing works correct when I run app or sign apk without proguard.

Proguard google play services jar

I'm trying to obfuscate google play services jar with proguard.
I tried two versions of the proguard config file.
First one contains
-keep class ** {
public protected *;
}
And the jar stays not obfuscated. It looks ok.
Second one contains
-keep class com.** {
public protected *;
}
And proguard deletes everithing. I get an error:
Error: The output jar is empty. Did you specify the proper '-keep' options?
Why is it empty, as the main google play services package is com.google.android.gms?
The following ProGuard configuration shrinks the Google Play Services jar, without optimization or obfuscation, keeping only the ads-related API:
-injars android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar
-outjars google-play-services-ads.jar
-libraryjars android-sdk/extras/android/support/v4/android-support-v4.jar
-libraryjars android-sdk/platforms/android-20/android.jar
-verbose
-forceprocessing
-dontoptimize
-dontobfuscate
-dontwarn com.google.**.R
-dontwarn com.google.**.R$*
-dontnote
-keep public class com.google.ads.** {
public protected *;
}
-keep public class com.google.android.gms.ads.** {
public protected *;
}
-keep class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
java.lang.String NULL;
}
It reduces the original jar from 2819 classes to 409 classes (2.7M to 476K). I haven't tested the result yet. If any removed classes are accessed by reflection, they need to be kept in the configuration as well.

Categories