How to configure Proguard using Gradle?

做~自己de王妃 提交于 2019-12-03 02:37:14
Scott Barta

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.

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