Proguard returned with error code 1. See console
[2013-04-04 16:25:20 - ] Note: there were 157 duplicate class definitions.
[2013-04-04 16:25:20 - ] Error: Method must be overridden in [proguard.optimize.peephole.ClassMerger] if ever called
I have tried every possible solution found on SO. There were around 2000 duplicates which now came down to 157. I have some external jars in my project too. This is my proguard.cfg file:
-dontwarn android.support.**
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keep class com.flurry.** { *; }
-dontwarn com.flurry.**
-keep class org.apache.** { *; }
-dontwarn org.apache.**
-dump proguard/class_files.txt
-printseeds proguard/seeds.txt
-printusage proguard/unused.txt
-printmapping proguard/mapping.txt
This application is for Android 4.0
Can you kindly let me know whats causing this and how do I go about in fixing it.
Merging my project's proguard config with one from ${sdk.dir}/tools/proguard/proguard-android.txt did the trick.
This error mostly happens with 3rd party build systems (e.g. Maven), which don't know about default proguard config.
UPD: ...because of the following content of default config:
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
Related
java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equals(java.lang.Object)’ on a null object reference
After debugging I have come to the conclusion that this is because that a value is not being passed from one activity to the other using putextra. This error only happens after enabling proguard. I am not aware of any keep rules to prevent this.
Currently my proguard file looks like this:
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep class * extends com.bumptech.glide.module.AppGlideModule {
<init>(...);
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep class com.bumptech.glide.load.data.ParcelFileDescriptorRewinder$InternalRewinder {
*** rewind();
}
-keep public class pl.droidsonroids.gif.GifIOException{<init>(int, java.lang.String);}
-dontwarn com.squareup.okhttp.**
-keep class com.squareup.okhttp.* { *;}
-dontwarn okio.
-dontshrink
-dontoptimize
# unknown stuff
-android
-allowaccessmodification
-dontpreverify
-keepattributes *Annotation*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * {
#android.webkit.JavascriptInterface <methods>;
}
I don't understand proguard much. I have added rules as required by third party libraries. Other than that I use firebase and some classes with getter and setter methods. Activity has all its members as private. It is my understanding that there is a null pointer exception occurring due to inability to pass values between intents using putextra after enabling proguard and so the value of variable of the second activity remains null.
How to solve this and better write proguard rules?
First of all, you should give more details.
For example, you have a folder named model and inside you have a response model class.
Your FileTree
-model
--Response.java
If you do not specify this in proguard, the release app will not be able to use it as a reference, because proguard will change keys on memory. so you should remove your models from proguard. And finally, the app cannot wrong reference key on memory, after then you will get a null pointer error.
-keep class com.name.app.model.** { *; }
Thus, the model folder will not interfere with its classes within
I have a problem with using proguard, this first time I learned proguard, I use this and more link to make proguard but I have not been able to implement to my project,in my app I use libs google_play_services and actionbarsherlock. I kept trying and the result is always error. I had 2 days looking for how I can use proguard in my project, this time I was really confused, I need proguard in my application, this screenshot of my app (app_run).
this my proguard setting
-optimizationpasses 5
#When not preverifing in a case-insensitive filing system, such as Windows. Because this tool unpacks your processed jars, you should then use:
-dontusemixedcaseclassnames
#Specifies not to ignore non-public library classes. As of version 4.5, this is the default setting
-dontskipnonpubliclibraryclasses
#Preverification is irrelevant for the dex compiler and the Dalvik VM, so we can switch it off with the -dontpreverify option.
-dontpreverify
#Specifies to write out some more information during processing. If the program terminates with an exception, this option will print out the entire stack trace, instead of just the exception message.
-verbose
#The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle. Note that the Dalvik VM also can't handle aggressive overloading (of static fields).
#To understand or change this check http://proguard.sourceforge.net/index.html#/manual/optimizations.html
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
#To repackage classes on a single package
#-repackageclasses ''
#Uncomment if using annotations to keep them.
#-keepattributes *Annotation*
#Keep classes that are referenced on the AndroidManifest
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.android.vending.licensing.ILicensingService
#To remove debug logs:
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
public static *** i(...);
}
## ActionBarSherlock 4.4.0 specific rules ##
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keepattributes *Annotation*
## hack for Actionbarsherlock 4.4.0, see https://github.com/JakeWharton/ActionBarSherlock/issues/1001 ##
-dontwarn com.actionbarsherlock.internal.**
## Google Play Services 4.3.23 specific rules ##
## https://developer.android.com/google/play-services/setup.html#Proguard ##
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames #com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
#com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
#To avoid changing names of methods invoked on layout's onClick.
# Uncomment and add specific method names if using onClick on layouts
#-keepclassmembers class * {
# public void onClickButton(android.view.View);
#}
#Maintain java native methods
-keepclasseswithmembernames class * {
native <methods>;
}
#To maintain custom components names that are used on layouts XML.
#Uncomment if having any problem with the approach below
#-keep public class custom.components.package.and.name.**
#To maintain custom components names that are used on layouts XML:
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
#Maintain enums
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#To keep parcelable classes (to serialize - deserialize objects to sent through Intents)
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
#Keep the R
-keepclassmembers class **.R$* {
public static <fields>;
}
could anyone help me to give a way how to use proguard for my application?
really need help,thanks
Proguard is going to require "rules" for the libraries you use, and possibly your own code too. Many of these rules can be found https://github.com/krschultz/android-proguard-snippets/tree/master/libraries
I am developing a android application. I obfuscates the code of the project using progaurd. I want to obfuscate the folder structure as well. anyway to do that ?
Thanks for your help
ProGuard contains various directives, for your ProGuard rules file, that can obfuscate package names, such as -flattenpackagehierarchy and -repackageclasses. Just make sure that anything referenced from AndroidManifest.xml or otherwise accessed via reflection is kept intact.
It is conceivable that the commercial, Android-tuned DexGuard tool can even let you repackage stuff in the manifest (by modifying the manifest entries as part of the obfuscation process), but I do not know if it does or not.
copy and paste this code in proguard.cfg:
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-dontoptimize
-dontpreverify
-keepattributes *Annotation*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgent
-keep public class * extends android.preference.Preference
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.support.v7.app.ActionBarActivity
-keep public class * extends android.app.Fragment
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-dontwarn android.support.**
I am working on an Android library project. I want to distribute this library as JAR to other developers.Before distributing the JAR I want to obfuscate it. I have tried using PROGUARD for this purpose, but its failing at the last step and says
The output jar is empty. Did you specify the proper '-keep' options?
Can anyone suggest what is going wrong ?
=================EDIT : Error Log =======================
ProGuard, version 4.7
Reading program jar [C:\Users\XYZ\Downloads\login.jar]
Reading library jar [D:\Softwares\Android SDK\adt-bundle-windows-x86-20130522\sdk\platforms\android-8\android.jar]
Note: the configuration refers to the unknown class 'javax.swing.plaf.ComponentUI'
Note: the configuration refers to the unknown class 'javax.swing.plaf.ComponentUI'
Note: the configuration refers to the unknown class 'javax.swing.JComponent'
Note: there were 3 references to unknown classes.
You should check your configuration for typos.
The output jar is empty. Did you specify the proper '-keep' options?
=============== Edit : proguard.cfg =====================
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep public class MyClass extends MyView {
public static String GetSessionID () {
}
}
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
Add this line in your proguard file.
-keep class <your jar file name>.** { *; }
I would like to use ProGuard to obfuscate my Android app. This works fine. But my gui classes, which extends acitvity, view and sherlockactivity are not obfuscated. Here is the proguard.cfg
-injars bin/classes
-injars libs
-outjars bin/classes-processed.jar
-libraryjars C:/Users/android-sdks/platforms/android-17/android.jar
-dontpreverify
-dontoptimize
-repackageclasses ''
-allowaccessmodification
-optimizationpasses 5
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keepattributes *Annotation*
-dontwarn sun.misc.Unsafe
-dontwarn com.actionbarsherlock.**
-dontwarn com.google.common.**
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.view.View
-keep public class * extends android.view.ViewGroup
-keep public class * extends android.support.v4.app.Fragment
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers class android.support.v4.app.Fragment {
*** getActivity();
public *** onCreate();
public *** onCreateOptionsMenu(...);
}
-keepclassmembers class * extends com.actionbarsherlock.ActionBarSherlock {
public <init>(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class com.brainyoo.brainyoo2android.ui.html.BYJavaScriptInterface {
public *;
}
First, I thought activities can´t be obfuscated because of the reflection call
myactivity.class
I've tried to add:
- keep public class mypackege.myactivity.class
But it does not solve the problem. Any ideas how to obfuscate the gui elements?
Thanks
Christine
But my gui classes, which extends acitvit, view and sherlockactivtiy are not obfusecated.
That is because your ProGuard configuration file says to not obfuscate them. Moreover, this is important, as if they are obfuscated, your app will not run, because:
Android will not find your renamed activities
Android will not find your activity lifecycle methods
Android will not find your widgets (for use with reflection in interpreting layout resources)
etc.
I´ve tried to added: -keep public class mypackege.myactivity.class But it does not solve the problem.
That is because you are telling ProGuard to not obfuscate that class.
Any ideas how to obfusecate the gui elements?
You don't, if you wish to have a working app when you are done.