Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use proguard in debug mode?

In my android app, i want to test some features with proguard on.

I don't need to really "debug" it, but i want proguard to run when i hit run in eclipse. I don't want to export the binary every time (so, in release mode) and save as apk and get it to the device to test.

Is there any way to run proguard in this way?

Update:

It seems like this is possible if you are not using Eclipse; as question title does not include Eclipse, there are multiple correct answers to this question.

like image 743
frankish Avatar asked May 15 '13 07:05

frankish


People also ask

How do I run a ProGuard in debugging?

If you want to make the whole build process easier for you, you should switch over to gradle and Android Studio IDE. This will run ProGuard on your debug build, configured with the file "proguard-android. txt", which should be put at your project's root folder.

Is ProGuard enabled by default?

When you create a new module using Android Studio, the IDE creates a proguard-rules.pro file in the root directory of that module. By default, this file does not apply any rules. So, include your own ProGuard rules here, such as your custom keep rules.

How do you test ProGuard rules?

In Android Studio 4.1 you can do this by going to Build > Analyze APK and then selecting your APK that should have had Proguard run with it. You can then inspect the classes. dex file and check its contents. You can see which classes have been obfuscated and removed by directly traversing the file structure.

Does ProGuard obfuscate code?

You can obfuscate Android code to provide security against reverse engineering. You can use the Android ProGuard tool to obfuscate, shrink, and optimize your code.


1 Answers

If you want to make the whole build process easier for you, you should switch over to gradle and Android Studio IDE.

Then you could easily add the following to your build.gradle file to run ProGuard:

android {     buildTypes {         release {         }         debug {             minifyEnabled true             proguardFile 'proguard-android.txt'             zipAlignEnabled true         }     } } 

This will run ProGuard on your debug build, configured with the file "proguard-android.txt", which should be put at your project's root folder. And in addition your apk is being zip aligned (Just remove "zipAlignEnabled true", if you don't want that to happen). If you want to do the same for your release build, just add those three lines under "release".

Slightly off-topic: Stuff like adding dependencies, signing your apk or adding other custom tasks to your build process is also way more uncomplicated with gradle. In addition you'll be able to not only build your apk via Android Studio IDE, but also via a simple command on the command line (e.g. ./gradlew assembleDebug). So if you are working on a team, the setup process for new members is just one "./gradlew assembleDebug" away. Without the need for any IDE configuration at all. Importing your project including all dependencies is as simple as a one-click process

EDIT: As of Gradle Android Build Tools version 0.14.0 the property names have changed (http://tools.android.com/tech-docs/new-build-system):

  • BuildType.runProguard -> minifyEnabled
  • BuildType.zipAlign -> zipAlignEnabled

I've updated the above code.

like image 68
MrMaffen Avatar answered Sep 18 '22 17:09

MrMaffen