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.
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 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 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?
I am trying to enable ProGuard when compiling my Android application.
Below is the ProGuard configuration.
The problem I have is that I get a lot of warnings about duplicate definition (pretty much for all classes, in my app or the basic java classes) and what's worse is that when I make changes in my code, those do not get reflected when I run on the device.
I am compiling (and developing) using IntelliJ IDEA 11.1.5 (and just enable ProGuard in the project structure, I did not set it to use the system proguard configuration).
I saw that other question, but it does not help at all, I don't think my problem is limited to 3rd party libraries, I imagine it's more about setting the right input/output... ?
-injars bin/classes
-outjars bin/classes-processed.jar
-libraryjars /home/matthieu/android/platforms/android-17/android.jar
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*,SourceFile,LineNumberTable,*Annotation*
-renamesourcefileattribute SourceFile
-dontwarn java.awt.**,javax.security.**,java.beans.**,com.sun.**
-keep public class my.package.MainMenuActivity
-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*(...);
}
-keep public class * extends android.view.ViewGroup
-keep public class * extends android.support.v4.app.Fragment
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-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.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
#ACRA specifics
# keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'.
# Note: if you are removing log messages elsewhere in this file then this isn't necessary
-keep class org.acra.ACRA {
*;
}
# keep this around for some enums that ACRA needs
-keep class org.acra.ReportingInteractionMode {
*;
}
-keepnames class org.acra.sender.HttpSender$** {
*;
}
-keepnames class org.acra.ReportField {
*;
}
# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
public void addCustomData(java.lang.String,java.lang.String);
public void putCustomData(java.lang.String,java.lang.String);
public void removeCustomData(java.lang.String);
}
# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
public void handleSilentException(java.lang.Throwable);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
Assuming you are building with Ant inside IntelliJ IDEA, you mustn't add -injars, -outjars, or -libraryjars options; the Ant script already does that for you. This explains the warnings about duplicates.
Note that it's better to remove the generic part of the configuration in your proguard-project.txt and rely on the configuration of the Android SDK. The latter is partly generated by aapt (tuned for your project) and partly maintained inside the SDK.
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.