3

I want to use proguard to only remove log statements, but now my application crashes when it is started. I am not too familiar with proguard, but I guess I have to add in some lines to keep my other classes to be fine.

This is my proguard-project.txt:

# To enable ProGuard in your project, edit project.properties # to define the proguard.config property as described in that file. # # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in ${sdk.dir}/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the ProGuard # include property in project.properties. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} -assumenosideeffects class android.util.Log { *; } #ProGuard may remove code that it thinks you don't use such as: #a class that is referenced only in the AndroidManifest.xml file #a method called from JNI #dynamically referenced fields and methods #-keep public class <MyClass> 

How would I go about adding a statement that will "disregard" proguard for all of my other classes? I just want to make sure that the removal of the logging works. I will then concentrate on obfuscation later down the road.

I am trying this, but I get an error when exporting:

-keep class com.finesspro.gui** { * } 

2 Answers 2

2

In proguard-rules.pro

-dontwarn ** -target 1.7 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose -optimizations !code/simplification/arithmetic,!code/allocation/variable -keep class ** -keepclassmembers class *{*;} -keepattributes * -assumenosideeffects class android.util.Log { public static int v(...); public static int i(...); public static int w(...); public static int d(...); } 

In gradle.build

buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } 
Sign up to request clarification or add additional context in comments.

Comments

0

You should try this to keep you classes: (different syntax with the ";")

-keep class com.finesspro.** { *; } 

And you should try the proguard-android-optimize.txt instead of this, where the optimalization is turned on! After that you can use this also:

-assumenosideeffects class android.util.Log { public static boolean isLoggable(java.lang.String, int); public static int v(...); public static int i(...); public static int w(...); public static int d(...); public static int e(...); } 

EDIT: If you would like to keep other classes you need to also add them to the proguard file. For example for the actionbarsherlock:

# For ActionbarSherlock -keep class com.actionbarsherlock.** {*;} -keep class android.support.v4.app.** { *; } -keep interface android.support.v4.app.** { *; } -keep class com.actionbarsherlock.** { *; } -keep interface com.actionbarsherlock.** { *; } 

3 Comments

I keep getting an error when I try to export. I get this in my cole:
I keep getting an error when I try to export. I get this in my console:2014-01-19 16:19:32 - Camera] R.java was modified manually! Reverting to generated version! [2014-01-19 16:19:35 - actionbarsherlock] R.java was modified manually! Reverting to generated version! [2014-01-19 16:19:36 - android-switch-backport] R.java was modified manually! Reverting to generated version! [2014-01-19 16:19:36 - google-play-services_lib] R.java was modified manually! Reverting to generated version!
If you user libs, then you should define their classes in proguard. See my edited answer, where is an example about the actionbarsherlock