How to configure Proguard using Gradle?

后端 未结 1 774
深忆病人
深忆病人 2021-02-05 22:50

I recently switched to Android Studio / Gradle and I am wondering, how ProGuard can be configured in the build.gradle script. I am new to Gradle, but I thought, configuring the

相关标签:
1条回答
  • 2021-02-05 23:27

    Proguard is built into the Android-Gradle plugin and you don't need to configure it as a separate task. The docs are at:

    http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Running-ProGuard

    Are your flavors so different that you really want different ProGuard configurations for them? I'd think in most cases you could have one config that could cover them all.

    EDIT:

    If you do want to change ProGuard rules for different flavors, the Android Gradle DSL allows you to do so. The sample in the docs shows how to do it:

    android {
        buildTypes {
            release {
                // in later versions of the Gradle plugin runProguard -> minifyEnabled
                minifyEnabled true
                proguardFile getDefaultProguardFile('proguard-android.txt')
            }
        }
    
        productFlavors {
            flavor1 {
            }
            flavor2 {
                proguardFile 'some-other-rules.txt'
            }
        }
    }
    

    That should handle your use case, unless you're looking for a way to have it automatically determine the proguardFile value based on the flavor name without you having to set it manually; you could do that through some custom Groovy scripting.

    0 讨论(0)
提交回复
热议问题