ProGuard config - java

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.

Related

Using "ProGuarded" library in "ProGuarded" app fails. Non-ProGuard app or lib works fine

I have a library that has been optimized and obfuscated with ProGuard, and it works fine if I do not use ProGuard on the app. That is, I can see it making HTTP requests to the correct places and it causes the app to respond properly to certain touch events. Similarly, if I use ProGuard on the app but NOT the library, everything still works fine. I only encounter issues when both the lib and app have been "ProGuarded" separately, where the app/library no longer make any HTTP requests. Why do I encounter problems in this "double ProGuard" situation? I'm beginning to wonder if there might be class naming collisions and the library is just calling the wrong class.
My ProGuard rules file for the app looks like:
-dontwarn com.mylibrary.**
-dontwarn org.acra.**
-dontwarn org.apache.**
-dontwarn com.google.**
-keepattributes *Annotation*
-keep class com.mylibrary.** { *; }
-keep class org.acra.** {
*;
}
Edit: For clarification, this is my own library and there are no errors being thrown. Everything builds fine and the app runs as expected, with the exception of the features that the library is supposed to add.
It turns out there were rules in the app's Proguard rules file that caused the library to get obfuscated once again, breaking functionality. I added a rule to ensure the entire library was skipped during the Proguard process and everything worked itself out.

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 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.

java.lang.NoClassDefFoundError after proguard obfuscation

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)

Categories