I have enabled proguard in project.properties:
proguard.config=proguard.cfg
My proguard.cfg does not disable obfuscation. But nothing is obfuscated.
I run the project build with
ant release.
Any bells ringing?
-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 ; }
-keepclasseswithmembers class * {
public (android.content.Context, android.util.AttributeSet); }
-keepclasseswithmembers class * {
public (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 *; }
You should make sure that your project is configured for your Android SDK:
android update project -p MyProjectDirectory
As of Android SDK r20, the ProGuard configuration file is split into several parts, which are specified in project.properties:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
The short project-specific configuration is defined in proguard-project.txt (no longer in proguard.cfg, like it was in older versions of the SDK). The SDK documentation may not be entirely up to date in this respect.
When you run ant release, you should see some logging output from ProGuard.
#Thanks Danail, Today i just overcome from this problem .Just elaborating
android:debuggable
Whether or not the application can be debugged, even when running on a device in user mode — "true" if it can be, and "false" if not. The default value is "false".
For more details you can visit
http://www.vogella.com/tutorials/AndroidDebugging/article.html
It was way more trivial than what I thought: we had (in our manifest.xml file) enabled the
android:debuggable="true"
Doh.
Related
Why android studio can´t infer which classes do we need so the other´s can be removed using shrink?
Why do we need to write manually which classes should be kept?
ProGuard is a general-purpose Java development tool. It knows nothing about classes that might be referred to from the Android manifest, layout resources, menu resources, preference XML, and so on.
More generally, ProGuard has no way of reliably determining what classes are loaded via reflection, which is how all of the above is implemented. For those classes, you need to teach ProGuard to keep them.
Also the "update project" command from /ANDROID_SDK/tools/android will generate a proguard with common classes that should be kept.
The default is enough for most applications.
You should add Innerclasses that are used as listener of JavaScript on WebViews.
And the cases you find that you will need names (reflections or anything else)
The default proguard.cfg looks like this:
-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 *;
}
Does anybody know how to use Proguard with Android Annotations?
I found this resource:
https://code.google.com/p/androidannotations/wiki/ProGuard
But when I use the proguard.cfg file from there, I get the following error:
proguard.ParseException: Unknown option '*' in line 6 of file
'/Users/jabdulius/Documents/Dropbox/workspace-tinder/Tinder/proguard.cfg'
Here's the proguard.cfg file I copied from the link:
-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>;
}
-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 *;
}
When you copy and paste from the website, you may notice your paste includes spaces before the asterisks that were not present in the original (a minor formatting error).. simply remove the two spaces, changing the following line:
-optimizations !code/simplification/arithmetic,!field/ *,!class/merging/ *
to match this:
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
You'll also note, as Eric has said (and he would know best!!) the newer versions of ADT include a default proguard configuration referenced in new project.properties:
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
Uncommenting the line (remove the #)will load the default properties (proguard-android.txt) and then override it with any changes you make in your project proguard-project.txt.
Those default properties include many of the rules that Android Annotations project recommends, and are sufficient for most basic apps.
As of Android SDK r20, the ProGuard configuration file is called proguard-project.txt, and it can be empty to start with. It only needs to contain project-specific settings. Try upgrading your SDK and your project.
I´ve always used Android LVL + proguard without issues.
After upgrading my apps to android 4 and above (V13), I´ve started having issues with LVL answers.
If I test my app straight from Eclipse, using a test signature, everything works as expected.
On the other side, after compiling using proguard Google Play answers "Market Not Managed" (code 3). I´ve verified it logging answers on com.android.vending.licensing.LicenseValidator.verify()
I haven´t changed my config.txt on proguard, I have double checked that proguard is pointing to the correct config.txt and also I´ve manually updated my android target on project.properties (this is something I haven´t found on documents but is necessary).
Any ideas on what could be causing this issue?
Just to let you know, my config.txt is almost the same google creates as standard on ADP.
Also, the apk being tested has not been uploaded to market yet, but I have always been able to test without publishing it (and it works without proguard).
My Proguard's config.txt
-target 1.6
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-libraryjars ..\libs
-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 *;
}
Thanks,
Gabriel Simões
Tried checking ProGuard's mapping.txt file to see if it really leaves all elements needed for LVL to work unobfuscated?
I have a Jenkins build server for building Android APKs with ant and Android (SDK Revision 18). Releasing APKs is working fine. However if i enable proguard by providing a proguard.cfg and pointing to it by "proguard.config=proguard.cfg" in the project.properties the following seems to happen:
Proguard is executed (as seen from shell output and the existence of mappings.txt and seeds.txt afterwards)
an apk is generated. However the Stacktraces generated by the APK are not obfuscated at all.
Anybody got an idee on this? It seems that the jar generated by proguard is for some reasons not included in the apk.
Here is my Proguard Config
-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 *;
}
#ACRA specifics
# we need line numbers in our stack traces otherwise they are pretty useless
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
# ACRA needs "annotations" so add this...
-keepattributes *Annotation*
# 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 {
*;
}
# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
public void addCustomData(java.lang.String,java.lang.String);
}
# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
public org.acra.ErrorReporter$ReportsSenderWorker handleSilentException(java.lang.Throwable);
}
The mappings.txt states that my code is obfuscated:
de.cellular.crashtest.ObfuscateThisClass -> de.cellular.crashtest.b:
However it is not obfuscated in the reported Stacktrace
It seems it was just a jenkins configuration problem: the apk was archived from the bin/ directory but the obfuscated one was in release/
Since today, something weird is happening with my application. Every time I click a button that has set the android:onClick attribute, I get an IllegalStateException: Could not find a method ...
I noticed that only happens when I enable Proguard in the file: default.properties
This is my 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
-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 *;
}
The thing is that doesn't happened last week.. (I was using proguard too). Any ideas?
EDIT
I found another solution to this problem:
The project with problems was created with an old version of the ADT plugin (Eclipse). I created a new project with the same parameters and copied the src/, res/ and Manifest, and problem solved!
in the example file in the android framework tools (YOUR_ANDROID_DIR/tools/proguard/proguard-android.txt), you can find the following rule:
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
With the comment it's quite explicit.
You need to tell proguard not to mutate the method associated with your android:onClick tag.
Here is an example rule (taken from the proguard website):
-keep class mypackage.MyCallbackClass {
void myCallbackMethod(java.lang.String);
}