Ant seems to ignore jar generated by Proguard while packaging apk - android

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/

Related

Setting up Proguard with a Library project that depends on external jars

My android project has many dependencies, one of them has a libs folder with some jars, and everything is working fine until i try using proguard.
When running proguard i got an error with this log:
Warning: [!!few lines like this!!]: can't find superclass or interface [...]
Warning: [!!many lines like this!!]: can't find referenced class [...]
You should check if you need to specify additional program jars.
Warning: there were 190 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
Warning: there were 6 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile them and try again.
Alternatively, you may have to specify the option
'-dontskipnonpubliclibraryclassmembers'.
java.io.IOException: Please correct the above warnings first.
then i tried to add the -libraryjars flag in my proguard config file, resulting in this additional warning, above the others:
Note: there were 698 duplicate class definitions.
The library project i cannot proguard is ShowcaseView (com.espian.showcaseview).
The jars in its library's libs folder are:
android-support-v4.jar
mockito-all-1.9.5.jar
nineoldandroids-2.4.0.jar
What should i do?!
EDIT
here's my proguard.cfg
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
#-libraryjars ../ShowcaseView-master/library/libs/android-support-v4.jar
#-libraryjars ../ShowcaseView-master/library/libs/mockito-all-1.9.5.jar
#-libraryjars ../ShowcaseView-master/library/libs/nineoldandroids-2.4.0.jar
-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
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
public static *** i(...);
public static *** w(...);
}
-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 is a try for all assets and res/raw/*html!
-keepclassmembers class **.R$* {
public static <fields>;
}
-keep class **.R$*
#ACRA specifics
# Restore some Source file names and restore approximate line numbers in the stack traces,
# otherwise the stack traces are pretty useless
-keepattributes SourceFile,LineNumberTable
# ACRA needs "annotations" so add this...
# Note: This may already be defined in the default "proguard-android-optimize.txt"
# file in the SDK. If it is, then you don't need to duplicate it. See your
# "project.properties" file to get the path to the default "proguard-android-optimize.txt".
-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 {
*;
}
-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);
}
Try this
-libraryjars /libs/mail.jar
-libraryjars /libs/activation.jar
-libraryjars /libs/additionnal.jar
Write your jar file path into the progurd.cfg or proguard-project.txt
You should add these lines for your libraries. They will don't warn for can't find reference class
-keep class com.nineoldandroids.** { *; }
-dontwarn -com.nineoldandroids.**

How can I obfuscate my code in Eclipse? (Android)

I am new in android application. I write an application and need to obfuscate it in eclipse. I tried to use following tutorial:
http://developer.android.com/tools/help/proguard.html
but when i created my project the eclipse did not produce any "proguard.cfg" file. I just have a "project.properties" that uncomment the following line of that.
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
I put instead of {sdk.dir} path to sdk. I don't have progurd-android.txt as well. is there any clear step by step for beginner how to obfuscate code in android?
or is it possible to you to explain it for me?
Thanks for help.
First, you should comment out this line on project.ptoperties:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
Then you should write your rules to proguard-project.txt This is an example from http://proguard.sourceforge.net/#manual/examples.html:
-injars bin/classes
-injars libs
-outjars bin/classes-processed.jar
-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-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>;
}
And then you should sign and export your apk. If you dont sign obfuscation does not work.
The tutorial is not up to date.
The proguard-project.txt is the correct proguard config file (which used to be "proguard.cfg" ).
I don't know though what the proguard-android.txt is supposed to be...
In my project.properties it only says:
"proguard.config=proguard-project.txt" (proguard.project.txt is in the same folder as the the properties file) and it works...
To enable ProGuard so that it runs as part of an Ant or Eclipse build, set the proguard.config property in the project.properties file.
proguard.config=proguard.cfg
Add this to a file called proguard.cfg to your projects root folder. It' s the basic configuration from the example (proguard-android.txt).
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-dontoptimize
-dontpreverify
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
-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.**
Then run your application.
Proguard configuration is not easy especially when you have several libraries.
See the documentation here Proguard and on the android developers page Android Proguard Description.

How to use Proguard with Android Annotations?

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.

Android: proguard is not obfuscating the source

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.

Android LVL - after proguard, answers Not_Market_Managed

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?

Categories

Resources