Proguard error while exporting android project - android

I was trying to export android application from project (Osmand) in Eclipse, the problem is that the proguard returned error code 1. Previously it throwed multiple warnings, so I used "-dontwarn" commands. Now the console sais this:
Proguard returned with error code 1. See console
Note: there were 227 duplicate class definitions.
You should check if you need to specify additional program jars.
Unexpected error while evaluating instruction:
Class = [com/actionbarsherlock/app/SherlockFragmentActivity]
Method = [getSherlock()Lcom/actionbarsherlock/ActionBarSherlock;]
Instruction = [10] invokestatic #36
Exception = [java.lang.IllegalArgumentException] (Can't find common super class of [android/app/Activity] (with 11 known super classes) and [com/actionbarsherlock/app/SherlockFragmentActivity] (with 6 known super classes))
Unexpected error while performing partial evaluation:
Class = [com/actionbarsherlock/app/SherlockFragmentActivity]
Method = [getSherlock()Lcom/actionbarsherlock/ActionBarSherlock;]
Exception = [java.lang.IllegalArgumentException] (Can't find common super class of [android/app/Activity] (with 11 known super classes) and [com/actionbarsherlock/app/SherlockFragmentActivity] (with 6 known super classes))
java.lang.IllegalArgumentException: Can't find common super class of [android/app/Activity] (with 11 known super classes) and [com/actionbarsherlock/app/SherlockFragmentActivity] (with 6 known super classes)
...
Proguard config file:
-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
-keepclasseswithmembernames class * {
native <methods>;
}
-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 *;
}
#this part was added:
-dontwarn android.support.v4.app.Watson
-dontwarn com.actionbarsherlock.**
-dontwarn com.dropbox.client2.**
-dontwarn net.osmand.plus.activities.search.**
-dontwarn net.osmand.plus.activities.NavigatePointFragment
-dontwarn net.osmand.plus.activities.FavouritesListFragment
-dontwarn net.osmand.plus.activities.FavouritesListActivity
-dontwarn net.osmand.plus.activities.FavouritesListFragment$FavouritesAdapter
What should I do?

Related

After enabling proguard null pointer exception

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

Proguard : can't find referenced method 'android.app.DatePickerDialog access$000

I am enabling pro-guard in release mode but am getting this error after launching the app :
Warning:FormActivity$1: can't find referenced method 'android.app.DatePickerDialog access$000(FormActivity)' in program class FormActivity
Warning:FormActivity$2: can't find referenced method 'android.app.DatePickerDialog access$000(FormActivity)' in program class FormActivity
Warning:FormActivity$3: can't find referenced method 'android.app.TimePickerDialog access$100(FormActivity)' in program class FormActivity
Warning:FormActivity$4: can't find referenced method 'void access$200(FormActivity,int,android.widget.LinearLayout,boolean)' in program class FormActivity
Warning:FormActivity$4: can't find referenced method 'void access$300(FormActivity,int,android.widget.LinearLayout,boolean)' in program class FormActivity
Warning:FormActivity$5: can't find referenced method 'android.widget.LinearLayout access$400(FormActivity,int,java.lang.String,android.widget.LinearLayout)' in program class FormActivity
Warning:FormActivity$5: can't find referenced method 'void access$500(FormActivity,int,android.widget.LinearLayout,boolean,boolean[],int,int)' in program class FormActivity
Warning:FormActivity$5: can't find referenced method 'void access$600(FormActivity,int,android.widget.LinearLayout,boolean,boolean[],int,int)' in program class FormActivity
Warning:FormActivity$6: can't find referenced method 'void access$700(FormActivity,int,int)' in program class FormActivity
Warning:FormActivity$7: can't find referenced method 'boolean access$802(FormActivity,boolean)' in program class FormActivity
Warning:FormActivity$8: can't find referenced method 'boolean access$802(FormActivity,boolean)' in program class FormActivity
Here is my proguard file :
-dontobfuscate
-dontoptimize
-optimizations !code/allocation/variable
#Start Project specifics
#Keep the BuildConfig
-keep class com.alouane.beapp.BuildConfig { *; }
#Keep the support library
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
#Gson
-keepattributes Signature
-keepattributes *Annotation*
-keep class sun.misc.Unsafe { *; }
-keep class com.dubai.fa.model.** { *; }
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
#Picasso
-dontwarn com.squareup.okhttp.**
# rx_cache
-dontwarn io.rx_cache2.internal.**
-keepclassmembers enum io.rx_cache2.Source { *; }
#RxJava
-keep class rx.schedulers.Schedulers {
public static <methods>;
}
-keep class rx.schedulers.ImmediateScheduler {
public <methods>;
}
-keep class rx.schedulers.TestScheduler {
public <methods>;
}
-keep class rx.schedulers.Schedulers {
public static ** test();
}
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
rx.internal.util.atomic.LinkedQueueNode producerNode;
rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
-keep class com.google.**
-dontwarn com.google.**
-dontwarn sun.misc.**
#Timber
-dontwarn org.jetbrains.annotations.**
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
# standard
-keep public class * extends android.app.Activity
-keep public class * extends android.support.v7.app.ActionBarActivity
-keep public class * extends android.support.v4.app.Fragment
-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
-keepclasseswithmembers class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers 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 *;
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
Most of libraries I used : Rxjava, Dagger .. don't need to add proguard rules .
So .. DO you know how to solve this, as this is the first time I am using prougard for a release build. Thanks .
I hit this when I enabled Java 8 featuers for my project. Debug builds ran fine but a signed apk wouldn't build with can't find ... access$100... error.
A clean project made it work again.
In Android Studio try Project -> Clean Project - it should always be the first thing to try as it often fixes issues.
Although it's an old question it's the first thing I hit when searching for my error message - so I'll leave this fix here for other's getting here.

use proguard for android project always got error?

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

Generate a obfuscated JAR for code distribution

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>.** { *; }

Method must be overridden in [proguard.optimize.peephole.ClassMerger] if ever called

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

Categories

Resources