Gradle和proguard:找不到参数的方法runProguard()

我按照Proguard Gradle手册的建议配置了build.gradle

这是root 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_Decorated{name=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都是null?

Solutions Collecting From Web of "Gradle和proguard:找不到参数的方法runProguard()"

由于错误的DSL属性名称,这种错误很常见。 确保在build.gradle指定正确的值: http : build.gradle

 android { buildTypes { release { minifyEnabled true proguardFile getDefaultProguardFile('proguard-android.txt') } } } 

你可以在这里find所有属性的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 ”而不是

 ... buildTypes { release { minifyEnabled true .... 
 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' } } }