As my project is too large, I need to run proguard in order to compile android successfully.
But when I set android:debuggable="true" in order for me to debug easily, it turn off proguard automatically. Is there any solution or workaround? Thank You
Ran into the exactly same problem. Luckily Google helped me out.
Now my build.gradle:
// ...
android {
// ...
buildTypes {
debug {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.txt',
'proguard-rules.debug.txt'
debuggable true
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.txt'
}
}
}
proguard-rules.debug.txt:
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-dontobfuscate
-dontoptimize
-dontpreverify
Worked for me. Hope it helps. ;-)
Related
When Proguard enabled in Android release build, Line numbers will change. This will not happen in Proguard enabled debug build, If exception occurred it is possible to find root cause easily retracing logs on debug application. but in release build line numbers are wrong.
How do I fix this issue?
TargerSDKVersion = 33 | GrdleVersion = 7.1.2
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
proguard-rules.pro
-keepattributes SourceFile,LineNumberTable
I want to obfuscate my android code, I have set minifienable true and setup proguard file, but after generating apk and decompile, the code is not obfuscated. This is my proguard :
my proguard file:
-dontwarn com.huawei.**
-dontwarn org.conscrypt.*
-dontwarn org.openjsse.javax.net.ssl.*
-dontwarn org.openjsse.net.ssl.OpenJSSE
my build.gradle file
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug{
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
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 proguard minifyEnabled true and useProguard true
enable shrinkResources true to reduce the APK size by shrinking resources.
proguardFiles getDefaultProguardFile('proguard-android.txt') to enable the default one. If you want to use your own proguard file then use the below rules.
release
{
debuggable false
useProguard true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
delete build file
invalidate cache and restart android studio
How to disable proguard for espresso test.
I enabled proguard for debug build type. But i want to disable proguard for espresso debug tests.
debug {
minifyEnabled true
shrinkResources true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testProguardFile 'test-proguard-project.pro'
}
and my test-proguard-project.pro looks like
-dontoptimize
-dontwarn
-dontobfuscate
Still proguard is optimizing the test app. Please help me how to disable proguard for test app.
The way to do it is to turn on minifyEnabled but turn off Proguard:
minifyEnabled true
useProguard false
I tried to proguard my app. It successfully obfuscated the apk. However, when i try to view the java code of my apk using Apk_oneclick, I am able to. I have created a release version of my apk. Still the problem persist. Any help would be much appreciated.
Thanks in advance.
build.gradle:
Proguard Rules:
Java code from the release-apk:
For enabling ProGuard configurations for your application you need to enable it in your module level gradle file. you need to set the value of minifyEnabled true.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
You can also enable shrinkResources true which will remove resources that ProGuard flaggs as unused.
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
You need to set following property
and add some rules in proguard-android
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Got it working. Cleaned the project and ran the same with some changes in the Proguard rules.
I need to make different flavors for test libraries. Why? Well, I want project to be fully secured so I wanna minifying to be enabled all the time(even for debug build type).
While making tests I'm using different classes from project,
so I decided to change proguard files using flavor. It looks like something this :
android {
...
buildTypes {
release {
minifyEnabled true
testProguardFile 'test-proguard-rules.pro'
}
debug {
minifyEnabled true
testProguardFile 'test-proguard-rules.pro'
}
}
...
productFlavors{
forTest{
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules1.pro', 'debug-rules.pro'
}
forRelease{
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'debug-rules.pro'
}
}
}
And proguard-rules* files
proguard-rules:
-dontwarn blablabla.**
-dontwarn blabla.**
-keep class bla.** { *; }
proguard-rules1:
-dontshrink
-dontobfuscate
-dontwarn
But this wasn't helpful for me. I want to run tests without obfuscation. Flavors doesn't have such param as minifyEnabled so I try to find any solution. So any suggestions about resolving an issue? May be someone had the same problem and find another solution (not using flavors) ?
After a whole day messing with this I found the following works:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
flavorA {
applicationIdSuffix ".a"
proguardFile 'flavorA_rules.pro'
}
flavorB {
applicationIdSuffix ".b"
}
}
More info: Include additional configurations