1

This is my proguard-project.txt

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

# 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
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.

-keepattributes *Annotation*

-keep public class com.myApp.mobileApp.**
-keep public class com.myApp.mobileApp.** {
  *;
}

-keep public class com.google.vending.licensing.ILicensingService{*;}
-keep public class com.android.vending.licensing.ILicensingService{*;}
-keep public class * extends android.app.Application{*;}
-keep public class * extends android.app.Activity{*;}
-keep public class * extends android.app.MapActivity{*;}
-keep public class * extends android.app.PreferenceActivity{*;}
-keep public class * extends android.view.View{*;}
-keep public class * extends android.widget.BaseAdapter{*;}
-keep public class * extends android.app.Service{*;}
-keep public class * extends android.content.BroadcastReceiver{*;}
-keep public class * implements android.view.View.OnTouchListener{*;}
-keep public class * implements android.view.View.OnClickListener{*;}
-keep public class * extends com.actionbarsherlock.app.SherlockActivity{*;}
-keep public class * extends com.actionbarsherlock.app.SherlockFragmentActivity{*;}
-keep public class * extends com.actionbarsherlock.app.SherlockMapActivity{*;}
-keep public class * extends com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay<OverlayItem>{*;}
-keep public class * extends com.actionbarsherlock.app.SherlockFragment{*;}

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

-libraryjars libs/android-support-v4.jar
-libraryjars libs/apache-mime4j-0.6.jar
-libraryjars libs/httpmime-4.0.1.jar
-libraryjars libs/libGoogleAnalyticsV2.jar

-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(...);
}

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembers class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# 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);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-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>;
}

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**
-dontwarn org.apache.**

My idea is to remove all the Logs even if obfuscation or any other optimization doesn't work.

The .apk file size in the bin folder is 1.82mb where as the one i get after Expoting is 1.42mb. So, i thought proguard did its job. But when i installed the .apk file on the Emulator and tested, all the Logs are still there.

Am i doing something wrong?

PS: The application crashes saying :

java.lang.RuntimeException: java.lang.NoSuchMethodException: a(Activity,int)

Hence i added these two lines in the proguard-project.txt:

  • -keep public class com.myApp.mobileApp.**
  • -keep public class com.myApp.mobileApp.** { *; }

Now it works, but the Logs are still showing up in the Logcat.

Comeplete error log:

01-02 13:18:54.711: E/AndroidRuntime(585): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myApp.mobileApp/com.myApp.mobileApp.LandingActivity}: java.lang.RuntimeException: java.lang.NoSuchMethodException: a(Activity,int)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.os.Looper.loop(Looper.java:130)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-02 13:18:54.711: E/AndroidRuntime(585):  at java.lang.reflect.Method.invokeNative(Native Method)
01-02 13:18:54.711: E/AndroidRuntime(585):  at java.lang.reflect.Method.invoke(Method.java:507)
01-02 13:18:54.711: E/AndroidRuntime(585):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-02 13:18:54.711: E/AndroidRuntime(585):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-02 13:18:54.711: E/AndroidRuntime(585):  at dalvik.system.NativeStart.main(Native Method)
01-02 13:18:54.711: E/AndroidRuntime(585): Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: a(Activity,int)
01-02 13:18:54.711: E/AndroidRuntime(585):  at com.actionbarsherlock.a.a(Unknown Source)
01-02 13:18:54.711: E/AndroidRuntime(585):  at com.actionbarsherlock.app.SherlockActivity.a(Unknown Source)
01-02 13:18:54.711: E/AndroidRuntime(585):  at com.actionbarsherlock.app.SherlockActivity.setContentView(Unknown Source)
01-02 13:18:54.711: E/AndroidRuntime(585):  at com.myApp.mobileApp.LandingActivity.onCreate(Unknown Source)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-02 13:18:54.711: E/AndroidRuntime(585):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-02 13:18:54.711: E/AndroidRuntime(585):  ... 11 more
01-02 13:18:54.711: E/AndroidRuntime(585): Caused by: java.lang.NoSuchMethodException: a(Activity,int)
01-02 13:18:54.711: E/AndroidRuntime(585):  at java.lang.Class.getMatchingConstructor(Class.java:643)
01-02 13:18:54.711: E/AndroidRuntime(585):  at java.lang.Class.getConstructor(Class.java:472)
01-02 13:18:54.711: E/AndroidRuntime(585):  ... 17 more

Thank You

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226

2 Answers2

1

You only keep the SherlockActivity class, not its inner classes.

-keep class android.support.v4.app.** { *; } 
-keep interface android.support.v4.app.** { *; } 
-keep class com.actionbarsherlock.** { *; } 
-keep interface com.actionbarsherlock.** { *; } 
-keepattributes *Annotation*

From https://stackoverflow.com/a/11151367/693752.

Community
  • 1
  • 1
Snicolas
  • 37,840
  • 15
  • 114
  • 173
  • So, nothing related to sherlock is required other than these 4 lines? and remove the 2 lines which i added to avoid app crash? – Archie.bpgc Jan 02 '13 at 12:55
  • Okay i am trying. But why the **apk file got shrink my 400kb**. If its not obfuscating or removing any logs it should have the same size as in bin folder right? because i tried disabling proguard and then exporting, that way i got the same size as in bin. Any idea what it skipped? – Archie.bpgc Jan 02 '13 at 13:05
  • No idea, and I don't understand very well. But if the question is solved, consider accepting the answer and asking a new question. – Snicolas Jan 02 '13 at 13:15
  • I did changes as mentioned in the 1st comment: **Removed the 2 lines which i used to avoid crashing, and removed all the sherlock related lines, and added the 4 lines you posted**. The app isn't crashing, thanks a lot, but the logs are still there :( – Archie.bpgc Jan 02 '13 at 13:31
  • replace the log statements with -assumenosideeffects class android.util.Log { public * ; }. From http://stackoverflow.com/questions/6408574/how-to-use-assumenosideeffects-class-android-util-log-in-my-app – Snicolas Jan 02 '13 at 13:38
  • Yeah i did that, still the logs appear. Actually i also tried this, as suggested by one of the Proguard developers: http://stackoverflow.com/questions/13218772/removing-log-call-using-proguard#answers – Archie.bpgc Jan 03 '13 at 11:58
  • The post by eric lafortune right ? So please update your original post and your project.properties file. – Snicolas Jan 03 '13 at 12:06
  • Is there a way, i can tell the proguard-project.txt file just to remove logs, but don't obfuscate or shrink the byte code. – Archie.bpgc Jan 03 '13 at 12:25
  • Yes but that is a different question. @Archie.bpgc, we are already using quite a lot of comments. Please let's keep focused. Did you enable proguard file in project.properties ??`` – Snicolas Jan 03 '13 at 12:36
  • Yeah i enabled. `proguard.config=proguard-project.txt`. and you can check my project file structure here: http://stackoverflow.com/questions/14111150/application-stopped-working-after-enabling-proguard – Archie.bpgc Jan 03 '13 at 12:47
  • Since you said "Yes but that is a different question", can you please answer that here: http://stackoverflow.com/questions/14123866/how-to-config-my-proguard-project-txt-file-to-remove-just-logs – Archie.bpgc Jan 03 '13 at 13:12
0

you used: -dontoptimize

So proguard will NOT optimize the code, so log.x will NOT be removed(optimized)

bianbian
  • 548
  • 4
  • 3