Proguard - also use proguard files from modules

My build.gradle projects are as follows:

android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "..." minSdkVersion 15 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile project(':androKnife') } 

And my androKnife module has its own proguard file. How can I make my main project also use this file?

Is there a way to automatically merge all the proguard files of all modules if I compile the project? Is there any other way that a module can define its proguard rules and a project can inherit it?

+5
source share
2 answers

The solution is to add the following line to the build.gradle libraries: consumerProguardFiles 'proguard-rules.pro'

So my library androKnife looks like this:

 apply plugin: 'com.android.library' android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { minSdkVersion 15 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' consumerProguardFiles 'proguard-rules.pro' } } } dependencies { ... } 
+11
source

So, the main proguard module, I like this:

 buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'main_proguard-rules.pro' } } 

Who knows the proguardFiles internal relationship proguardFiles ? Auto merge or override if you have the same proguard code?

0
source

All Articles