I'm new to Proguard configuration, so please correct me if I'm doing something wrong.
After playing with Gradle and Proguard configuration, I got two main options: either setting useProguard false or deleting that line.
First option:
buildTypes {
release {
minifyEnabled true
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Second option:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
The thing is that in the first case my APK-file size is 8 mb but it is not obfuscated and in the second case it becomes obfuscated but gets more than twice the size: 18 mb.
Proguard rule is the same in both cases:
-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-dontwarn org.codehaus.mojo.animal_sniffer.*
-dontwarn okhttp3.internal.platform.ConscryptPlatform
So how do I make my APK both small and obfuscated?
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
I'm using Android Hilt ViewModel. It's working fine for debug mode below:
debug {
debuggable true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
but when I change to release mode, Android Hilt not working. Especially when I change shrinkResources to true or debuggable to false, It's will not working. Below is my release mode:
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
Below is my proguard:
-dontwarn com.google.errorprone.annotations.**
-keepnames #dagger.hilt.android.lifecycle.HiltViewModel class * extends androidx.lifecycle.ViewModel
Please help me!
I am trying to take singed apk build but generating the build getting too much of time (nearly 30 min)
build.gradle:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Set to false these line if you are not using proguard rule file
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
My android app was crashing when i build a signed apk. The crash was not seen when i did a debug build. The build.gradle file is like this:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
debuggable true
}
}
setting minifyEnabled to false is not the correct solution, that would disable proguard while building the release version
The reason why setting minifyEnabled is working is because proguard might be obfuscating jsoup.
So, you should keep minifyEnabled as true and include these rules for jsoup in your proguard-rules.txt file to prevent the app from crashing :
-keep public class org.jsoup.** {
public *;
}
What i did to prevent the app from crashing is that i have made minifyEnabled to false from true in the build.gradle file. In that file i have made the following change.
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
debuggable true
}
}
If anybody have any other answers please post it here.