Gradle 和 proguard:找不到参数的方法 runProguard() [true]
Posted
技术标签:
【中文标题】Gradle 和 proguard:找不到参数的方法 runProguard() [true]【英文标题】:Gradle and proguard: could not find method runProguard() for arguments [true] 【发布时间】:2013-12-05 14:15:02 【问题描述】:我已经按照Proguard Gradle manual 的建议配置了 build.gradle
这是根 build.gradle
buildscript
repositories
flatDir dirs: '/home/username/android-sdks/tools/proguard/lib'
mavenCentral()
dependencies
classpath 'com.android.tools.build:gradle:0.5.+'
classpath ':proguard'
现在这是我项目的 build.gradle
apply plugin: 'android'
dependencies
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':SomeLibraryProject')
android
compileSdkVersion 19
buildToolsVersion "19.0.0"
sourceSets
...
task runProguardTask(type: proguard.gradle.ProGuardTask)
signingConfigs
debug
storeFile file("./keystore/keystore")
storePassword "******"
keyAlias "******"
keyPassword "*******"
release
runProguard true
proguardFile 'proguard-android.txt'
storeFile file("./releasekey/keystore")
storePassword "******"
keyAlias "********"
keyPassword "*******"
buildTypes
release
signingConfig signingConfigs.release
这是输出
$ ./gradlew build
FAILURE: Build failed with an exception.
* Where:
Build file '/home/username/Documents/eclipse/workspace/repo/ProjectName/build.gradle' line: 49
* What went wrong:
A problem occurred evaluating project ':ProjectName'.
> Could not find method runProguard() for arguments [true] on SigningConfigDsl_Decoratedname=release, storeFile=null, storePassword=null, keyAlias=null, keyPassword=null, storeType=null.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 9.14 secs
我也想知道为什么storeFile、storePassword、keyAlias和keyPassword都是空的?
【问题讨论】:
【参考方案1】:runProguard 已弃用(并将很快停止工作);改为“minifyEnabled”
...
buildTypes
release
minifyEnabled true
....
【讨论】:
感谢修复了我在 Android Studio 1.0 RC 1 上的 gradle 错误【参考方案2】:由于错误的 DSL 属性名称,此类错误很常见。确保您指定正确的值:http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Running-ProGuard build.gradle
:
android
buildTypes
release
minifyEnabled true
proguardFile getDefaultProguardFile('proguard-android.txt')
您可以在此处找到包含所有属性的 javadoc(单击下载 DSL 参考 btn): http://developer.android.com/tools/building/plugin-for-gradle.html
2014 年 11 月 24 日更新:
在 0.14.0 gradle 插件中重命名了一些属性。 runProguard -> minifyEnabled
检查 Alécio 的答案并在此处关注最近的更改列表:http://tools.android.com/tech-docs/new-build-system
【讨论】:
runProguard 现已被弃用。看下面正确答案,需要改成minifyEnabled。【参考方案3】:runProguard is deprecated after gradle build tools version 1.0.0-rc1
Running ProGuard
ProGuard is supported through the Gradle plugin for ProGuard version 4.10. The ProGuard plugin is applied automatically, and the tasks are created automatically if the Build Type is configured to run ProGuard through the minifyEnabled property.
android
buildTypes
release
minifyEnabled true
proguardFile getDefaultProguardFile('proguard-android.txt')
productFlavors
flavor1
flavor2
proguardFile 'some-other-rules.txt'
【讨论】:
以上部分对你的android代码真的很安全吗?以上是关于Gradle 和 proguard:找不到参数的方法 runProguard() [true]的主要内容,如果未能解决你的问题,请参考以下文章
Gradle 在使用 Proguard 编译发布版本时无法找到一些引用和库类
Notification.setSound() 不适用于 proguard