Proguard - also use proguard files from modules

瘦欲@ 提交于 2019-12-07 01:40:30

问题


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?


回答1:


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 {

    ...
}



回答2:


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?



来源:https://stackoverflow.com/questions/30783407/proguard-also-use-proguard-files-from-modules

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