Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have to protect my app by enabling Proguard obfuscation in Android Studio. I have searched for the process of how to apply it but i did not get any clear solution. When i try it, i always get an error. So can anyone tell me the clear steps to apply it in my app?

I am doing this by the following steps:

  1. In Android Studio, open up an Android project.

  2. Change to Project View.

  3. Change the following line:

    minifyEnable false to minifyEnable true

  4. Set ProGuard Rules(optional)

    4.1 In Project View, select the proguard-rules.pro file.

    4.2 Add in the following lines to tell ProGuard not to obfuscate certain classes.

    -keepclassmembers class com.dom925.xxxx 
    {
      public *
    }
    

Error that I am getting by following the steps are

Error:Execution failed for task ':app:packageRelease'. Unable to compute hash of D:AndroidPojectnameappuildintermediatesclasses-proguard eleaseclasses.jar

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
334 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 minifyEnabled true
  3. enable shrinkResources true to reduce the APK size
  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
            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:

For more detail go through this link


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...