Android Gradle 和 proguard:找不到参数的方法 runProguard() [true]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20115391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:19:35  来源:igfitidea点击:

Gradle and proguard: could not find method runProguard() for arguments [true]

androidgradleproguard

提问by Yaroslav Mytkalyk

I've configured the build.gradle as suggested by Proguard Gradle manual

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

This is root 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'
    }
}

Now this is the build.gradle for my project

现在这是我项目的 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
        }
    }  
}

And this is the output

这是输出

$ ./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

I also wonder why the storeFile, storePassword, keyAlias and keyPassword are null?

我也想知道为什么 storeFile、storePassword、keyAlias 和 keyPassword 为空?

采纳答案by Sergii Pechenizkyi

Errors like that are common due to wrong DSL property names. Make sure you specify correct values: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Running-ProGuardat your build.gradle:

由于错误的 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')
        }
    }
}

You can find javadoc with all properties here (click download DSL reference btn): http://developer.android.com/tools/building/plugin-for-gradle.html

您可以在此处找到具有所有属性的 javadoc(单击下载 DSL 参考 btn):http: //developer.android.com/tools/building/plugin-for-gradle.html



Update from 2014-11-24:

2014-11-24 更新:

A few properties was renamed at 0.14.0 gradle plugin. runProguard -> minifyEnabledcheck answer from Alécio and follow recent changes list here: http://tools.android.com/tech-docs/new-build-system

一些属性在 0.14.0 gradle 插件中重命名。runProguard -> minifyEnabled检查 Alécio 的答案并在此处关注最近的更改列表:http://tools.android.com/tech-docs/new-build-system

回答by Alécio Carvalho

runProguardis deprecated (and will soon stop working); change to "minifyEnabled" instead

runProguard已弃用(并将很快停止工作);改为“ minifyEnabled

...

buildTypes {
    release {
        minifyEnabled true
        ....

回答by LenaYan

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