I am using Android Studio since 0.1.0 ... I just learned yesterday that Pro Guard seems to be integrated in newly created projects. Unfortunately this is not true for my project (which was a former Eclipse project). I didn't know of Pro Guard until I started working with Android Studio. And now I am looking for examples on how to use Pro Guard with Android Studio. Unfortunately the Android Dev documentation is only mentioning situations where the configuration file is already created. Is there a possibility to get Android Studio to create a configuration file to an already existing project?
3 Answers
I was also not able to do it through Android Studio. However, this worked for me.
Add the following sections to the "android" section of your build.gradle file, filling in your own implementation details where appropriate.
android {
...
signingConfigs {
releaseConfig {
storeFile file("/dir/to/your.keystore")
storePassword "xxx"
keyAlias "yyy"
keyPassword "xxx"
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../your_proguard_file.txt'
signingConfig signingConfigs.releaseConfig
}
}
}
In your project folder, run ./gradlew clean and ./gradlew assembleRelease

- 464
- 4
- 21

- 576
- 1
- 3
- 14
-
Hi, I have applied your configuration to my project, and it doesnt work. I have posted a question there: http://stackoverflow.com/questions/18481752/gradle-failed-to-build-when-proguard-is-activated Thank you for any help. – pommedeterresautee Aug 28 '13 at 07:42
-
1It is important to say that your code should be included into android { ... } But besides that, it works now. Thanks alot! – Peter Osburg Aug 28 '13 at 14:46
-
indeed, you're correct =) it's always good to have a look at http://tools.android.com/tech-docs/new-build-system/user-guide – Ricardo Belchior Aug 29 '13 at 14:05
-
3Important, Switch your Build Variant to "Release" – Oli Aug 31 '13 at 18:04
-
runProguard true has been changed to minifyEnabled true – AgentKnopf Feb 06 '15 at 13:16
You can copy the default Proguard configuration file to your project.
sdk-location/tools/proguard/examples/android.pro — copy and paste it as proguard.cfg in your project. Then choose it when AS asks for the config file path.

- 625
- 4
- 9
-
1Also noticed another example in the Android Studio sdk. sdk-location/tools/proguard/proguard-android.txt – Geekygecko Aug 08 '13 at 01:08
-
I tried the android.pro file and put it into my project folder. Chose it during "Generate Signed APK" but no files nor directories have been created to see the output of ProGuard. Am I missing something? – Peter Osburg Aug 08 '13 at 06:21
The complete ProGuard configuration that is generated by your rules (.pro
) file can be saved by appending the -printconfiguration
command to your existing rules. i.e.
-printconfiguration 'C:\Example\File\Path\proguard-configuration.txt'

- 4,192
- 1
- 37
- 43