Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pro-guard Obfuscation not working in android studio

Using Latest Android Studio and having updated all platform ( OsX) :

Build.gradle :

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.xxxxxxlxxxxxx.apps.firebase"
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Proguard-rules.pro :

-keep public class OpenSource

As you can see proguard is enabled and rules also given for just keeping OpenSource class. Still when i build its apk / signed apk. And uses following commands on apk file :

  1. Unzip apk
  2. sh Dex2jar.sh classes.dex
  3. And by opening output jar file with Jd-GUI
  4. I get all all my classes right from MainActivity and rest all, as it is. There is no Obfuscation seen working

It would be very nice to have your suggestions on it. Thanks.

like image 961
sandhya sasane Avatar asked Oct 15 '25 20:10

sandhya sasane


1 Answers

To enable ProGuard in Android Studio. Below is the sample how to enable default ProGuard in Android Studio.

1) Go to the build.gradle file of app

2) enable the proguard minifyEnabled true and useProguard true

3) enable shrinkResources true to reduce the APK size by shrinking resources.

4) 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
        useProguard true
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    debug {
        debuggable true
        useProguard true
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
like image 107
Aditya Avatar answered Oct 17 '25 11:10

Aditya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!