Removing unused strings during ProGuard optimisation

ProGuard can remove simple constant arguments (Strings, integers, etc). So in this case, the code and the string constant should disappear completely: Log.d(“This is a debug statement”); However, you may have observed the issue with some code like this: Log.d(“The answer is “+answer); After compilation, this actually corresponds to: Log.d(new StringBuilder().append(“The answer is “).append(answer).toString()); ProGuard … Read more

Removing Log call using proguard

You shouldn’t specify the ‘*’ wildcard, because that includes methods like ‘Object#wait()’. Better explicitly list the methods: -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(…); } This option is only relevant if optimization is … Read more

How to keep/exclude a particular package path when using proguard?

You don’t specify in what way it doesn’t work. Your configuration keeps the names of all public classes in the specified package: -keep public class com.myapp.customcomponents.* The following configuration keeps the names of all public classes in the specified package and its subpackages: -keep public class com.myapp.customcomponents.** The following configuration keeps the names of all … Read more

Enabling ProGuard in Eclipse for Android

Android SDK (r20 or higher) Please check the predefined proguard.config refered in project.properties proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt More info: http://proguard.sourceforge.net/manual/examples.html#androidapplication On Gradle: buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’ … } } Here you can check a proguard “default” file that I keep updating: https://medium.com/code-procedure-and-rants/android-my-standard-proguard-ffeceaf65521 Android SDK (r19 or lower) You can add it … Read more

Hiding strings in Obfuscated code

Assuming you are happy with obscure rather than secure, there a number of mechanisms you could use, but obfuscaters like proguard are not going to be able to help you. To achieve this you will need to do encoding or encryption of the string yourself, the approach you use depends on what you are trying … Read more

DexIndexOverflowException Only When Running Tests

com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, … Read more

Best practice for storing and protecting private API keys in applications [closed]

As it is, your compiled application contains the key strings, but also the constant names APP_KEY and APP_SECRET. Extracting keys from such self-documenting code is trivial, for instance with the standard Android tool dx. You can apply ProGuard. It will leave the key strings untouched, but it will remove the constant names. It will also … Read more