Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the ProGuard in Android Studio?

This is my first project in Android Studio, and the code of my apps are not obfuscated. Im using this configuration in build.gradle file: enter image description here

I'm using the Build > Generate Signed APK... with the Run Proguard checked. And, when I have tested using the Apk_OneClick.v4.2, my code is completly easy to read:

enter image description here

Please, help-me. :(

like image 521
Felipe Porge Xavier Avatar asked Jan 02 '14 15:01

Felipe Porge Xavier


2 Answers

You're probably not actually signing the release build of the APK via the signing wizard. You can either build the release APK from the command line with the command:

./gradlew assembleRelease 

or you can choose the release variant from the Build Variants view and build it from the GUI:

IDE main window showing Build Variants

like image 183
Scott Barta Avatar answered Sep 21 '22 15:09

Scott Barta


You can configure your build.gradle file for proguard implementation. It can be at module level or the project level.

 buildTypes {      debug {         minifyEnabled false         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'      }  } 

The configuration shown is for debug level but you can write you own build flavors like shown below inside buildTypes:

    myproductionbuild{         minifyEnabled true         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'     } 

Better to have your debug with minifyEnabled false and productionbuild and other builds as minifyEnabled true.

Copy your proguard-rules.txt file in the root of your module or project folder like

$YOUR_PROJECT_DIR\YoutProject\yourmodule\proguard-rules.txt

You can change the name of your file as you want. After configuration use one of the three options available to generate your build as per the buildType

  1. Go to gradle task in right panel and search for assembleRelease/assemble(#your_defined_buildtype) under module tasks

  2. Go to Build Variant in Left Panel and select the build from drop down

  3. Go to project root directory in File Explorer and open cmd/terminal and run

Linux ./gradlew assembleRelease or assemble(#your_defined_buildtype)

Windows gradlew assembleRelease or assemble(#your_defined_buildtype)

You can find apk in your module/build directory.

More about the configuration and proguard files location is available at the link

http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Running-ProGuard

like image 23
Piyush Agarwal Avatar answered Sep 19 '22 15:09

Piyush Agarwal