How to enable ProGuard obfuscation in Android Studio?
if you are building the android project with jack, then it will automatically do the shrinking, obfuscation, repackaging and multidex. Just add below in :
defaultConfig {
jackOptions {
enabled true
}
}
and in build types, mention the project proguard
file :
buildTypes {
release {
// Jack build environment does not require minifyEnabled or shrinkResources.
// Conceptually, the jack compiler consolidates the functionality of javac, ProGuard, and dex in a single conversion step
//minifyEnabled = true
//shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
debug {
...................
}
}
To disable the ProGuard obfuscation, it is required to add below line in your proguard-project.txt file
####No obfuscation
-dontobfuscate
I figured out the problem:
Open up the proguard-rules.pro for your project and add this to the bottom:
-dontwarn java.nio.file.Files
-dontwarn java.nio.file.Path
-dontwarn java.nio.file.OpenOption
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Basically how I solved it was this I tried to run my app in 'release' mode and got a bunch of errors similar to this guy here: https://github.com/square/okio/issues/144
I pretty much followed what he said and fixed it.
Hope this can help others with generating their APK's!
visit more detail here :
Error:Execution failed for task ':app:packageRelease'. > Unable to compute hash of /../AndroidStudioProjects/../classes.jar
To enable ProGuard in Android Studio.
Below is the sample how to enable default ProGuard in Android Studio.
- Go to the build.gradle file of app
- enable the minifyEnabled true
- enable shrinkResources true to reduce the APK size
proguardFiles getDefaultProguardFile('proguard-android.txt')
to enable the default one. If you want to use your own proguard file then use the below rules.buildTypes { release { debuggable false minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { debuggable true minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }
The link with ProGuard settings for Android and other settings are available in these links:
- Default ProGuard file
- Gist with example
For more detail go through this link