Android project not obfuscating - android

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

Related

Unable to Obfuscate the Android library .aar file using Ionic 6/Cordova

I have created the .aar(Android library) for ionic 6/cordova project. But unable to obfuscate the java class files, i.e, able to see the content of the file. Below is the configuration used in app level build.gradle.
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
debuggable false
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
It would be great if some one help on this?

How to disable proguard for androidTest

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

Why does Proguard make APK files bigger even when minifier is enabled?

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?

Android proguarded apk still readable

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.

App crashed when i build a signed APK with jsoup

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.

Categories

Resources