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.
Related
I'm obfuscating an executable jar using ProGuard version 5.3.3.
My jar contains other libraries which I do not want to obfuscate or optimize.
This is my ProGuard config:
-libraryjars 'C:\Program Files\Java\jre1.8.0_131\lib\rt.jar'
-injars myjar-debug.jar
-outjars myjar-release.jar
-skipnonpubliclibraryclasses
-dontoptimize
-dontshrink
-useuniqueclassmembernames
-keeppackagenames org.**
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod
-ignorewarnings
-keep class org.** { *; }
-keepclassmembers class org.** { *; }
-dontwarn org.**
-keepclasseswithmembers public class * {
public static void main(java.lang.String[]);
}
-keepclasseswithmembers class * {
native <methods>;
}
-keepclasseswithmembernames class * {
native <methods>;
}
The obfuscation works perfectly fine and there are no errors in executing the jar. However, if I compare the original jar and the obfuscated jar, I can see that ProGuard has modified classes within package org.**. Most of the class files size is more than the original size.
I don't want ProGuard to modify these files at all. How can I completely exclude this package so that the binary of the class files in org.** are exactly same?
I think you need to tweak your jar building process, and obfuscate first then make executable jar.
I am not sure if you are using maven/gradle however this will make your life easy compared to using command line
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 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.
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.
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)