How to include a proguard configuration in my Andr

2020-01-31 03:09发布

Android libraries, per the AAR file spec, includes a 'proguard.txt' file. My understanding is that this file declares how the library correctly can be obfuscated and minified. In my case I need to preserve some API-classes.

How can I declare the library's proguard.txt file in the library's build.gradle? And will this file be automatically read when creating an application (APK) that uses my library?

I didn't find this information in Android's Gradle Plugin User Guide.

2条回答
Deceive 欺骗
2楼-- · 2020-01-31 03:15

In your Gradle file's default configuration closure, specify your Proguard file with consumerProguardFiles instead of proguardFiles. For example:

defaultConfig {
    consumerProguardFiles 'proguard.txt'
}
查看更多
时光不老,我们不散
3楼-- · 2020-01-31 03:32

If you create library you can disable proguard and provide a consumerProguardFiles in you build.gradle which will be used by consumer project which resolve it

android {
    defaultConfig {
        consumerProguardFiles 'proguard-rules.pro'
    }

    buildTypes {
        release {
            minifyEnabled false
        }
    }
    //...
}

But if you should enable proguard, for example, because you want distribute your library as archive - you are able to use the next possibility:

android {

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles 'proguard-rules.pro'
        }
    }
    //...
}
查看更多
登录 后发表回答