Proguard - also use proguard files from modules

6.9k views Asked by At

My projects build.gradle looks like following:

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 does have it's own proguard file. How can I make my main project use this file as well?

Is there some way to auto merge all proguard files of all modules, if I compile a project? Is there another way a module can specify it's proguard rules and a project can inherit it?

2

There are 2 answers

0
prom85 On BEST ANSWER

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

So my androKnife library looks like following:

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 {

    ...
}
0
Jenus Dong On

So, main module proguard code, likes this:

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

Who does know the principle of the inner relationship of proguardFiles? Auto merged or Overrided when has the same proguard code?