这是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为空?
答案 0 :(得分:57)
runProguard (很快就会停止工作);改为“ minifyEnabled ”而不是
...
buildTypes {
release {
minifyEnabled true
....
答案 1 :(得分:13)
由于错误的DSL属性名称,这种错误很常见。请务必在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
答案 2 :(得分: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'
}
}
}