You can add the ProGuard plugin to your project by including the following in your root level build.gradle(.kts) file:
dependencies {
classpath 'com.android.tools.build:gradle:x.y.z' // The Android Gradle plugin.
classpath 'com.guardsquare:proguard-gradle:7.1.0' // The ProGuard Gradle plugin.
}
To actually apply the plugin to your project, just add the line to your module level build.gradle(.kts) file after applying the Android Gradle plugin as shown below.
ProGuard can be executed automatically whenever you build any of the configured variants. You can configure a variant using the proguard block in your module level build.gradle(.kts) files. This is a top-level block and should be placed outside the android block.
For example, in the snippet below, ProGuard is configured to only process the release variant of the application, using a configuration provided by the user (proguard-project.txt) and a default configuration (proguard-android-optimize.txt).
Android 升级到 30+以后, proguard 混淆以后打包运行报错。 报错 1. 空对象 报错 2. 未实现对应接口
根据官网说明,升级使用方法如下: AGP version 4.x - AGP 7.x 需要使用 ProGuard Gradle Plugin
ProGuard can be executed automatically whenever you build any of the configured variants. You can configure a variant using the proguard block in your module level build.gradle(.kts) files. This is a top-level block and should be placed outside the android block.
For example, in the snippet below, ProGuard is configured to only process the release variant of the application, using a configuration provided by the user (proguard-project.txt) and a default configuration (proguard-android-optimize.txt).
There are three default configurations available: