Proguard - 也使用模块中的 proguard 文件 [英] Proguard - also use proguard files from modules

查看:42
本文介绍了Proguard - 也使用模块中的 proguard 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目 build.gradle 如下所示:

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')
}

而且我的 androKnife 模块确实有它自己的 proguard 文件.我怎样才能让我的主项目也使用这个文件?

And my androKnife module does have it's own proguard file. How can I make my main project use this file as well?

如果我编译一个项目,是否有某种方法可以自动合并所有模块的所有 proguard 文件?是否有另一种方式模块可以指定它的 proguard 规则并且项目可以继承它?

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?

推荐答案

解决方案是在库 build.gradle 中添加以下行: consumerProguardFiles 'proguard-rules.pro'

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

所以我的 androKnife 库如下所示:

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 {

    ...
}

这篇关于Proguard - 也使用模块中的 proguard 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆