Using Proguard with Android without obfuscation

24,217

Solution 1

Add !code/allocation/variable is workaround for ProGuard bug when -dontobfuscate is set to your -optimizations

For example

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable

Solution 2

You should make sure that you are using the latest version of the Android SDK or at least the latest version of ProGuard (version 4.7 at this time of writing) inside the SDK (android-sdk/tools/proguard/lib/proguard.jar).

Share:
24,217
theJosh
Author by

theJosh

I am a software engineer at Tesseract Mobile. We develop Android Games. Solitiare Free Pack Solitaire MegaPack GinRummy

Updated on July 09, 2022

Comments

  • theJosh
    theJosh almost 2 years

    I am getting an error "Conversion to Dalvik format failed with error 1" when using the -dontobfuscate flag. Otherwise my app exports fine. I don't want to obfuscate because I am using BugSense for error tracking and they charge $99 a month if you need to de-obfuscate your stack traces. I still want to get the file size and optimization benefits of proguard.

    If I comment out -dontobfuscate every thing works great. Except for the unreadable stack traces.

    my progaurd.cfg file:

    -dontobfuscate
    -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 *;
    }
    

    I will also accept an answer that points me in the right direction. Is there a log file I should be looking at?

  • Eric Lafortune
    Eric Lafortune over 12 years
    It could be a bug either in ProGuard or in the dex tool. If you can provide a sample that allows to reproduce the problem, on the ProGuard bug tracker, I'll look into it.
  • sherpya
    sherpya over 10 years
    yes, looks like -dontobfuscate needs !code/allocation/variable