Generating a Pro Guard configuration file with Android Studio

十年热恋 提交于 2019-11-30 02:42:05
Ricardo Belchior

I was also not able to do it through Android Studio. However, this worked for me.

Add the following sections to the "android" section of your build.gradle file, filling in your own implementation details where appropriate.

android {

...

    signingConfigs {
        releaseConfig {
            storeFile file("/dir/to/your.keystore")
            storePassword "xxx"
            keyAlias "yyy"
            keyPassword "xxx"
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), '../your_proguard_file.txt'
            signingConfig signingConfigs.releaseConfig
        }
    }
}

In your project folder, run ./gradlew clean and ./gradlew assembleRelease

You can copy the default Proguard configuration file to your project.

sdk-location/tools/proguard/examples/android.pro — copy and paste it as proguard.cfg in your project. Then choose it when AS asks for the config file path.

The complete ProGuard configuration that is generated by your rules (.pro) file can be saved by appending the -printconfiguration command to your existing rules. i.e.

-printconfiguration 'C:\Example\File\Path\proguard-configuration.txt'

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!