Gradle和proguard:找不到參數的方法runProguard()[true]

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


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

我按照Proguard Gradle手冊的建議配置了build.gradle

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

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都是null?

3 个解决方案

#1


13  

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-ProGuard at your build.gradle:

由於錯誤的DSL屬性名稱,這種錯誤很常見。確保在build.gradle中指定正確的值:http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Running-ProGuard:

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 -> minifyEnabled check 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

#2


57  

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

runProguard已棄用(並將很快停止工作);改為“minifyEnabled”而不是

...

buildTypes {
    release {
        minifyEnabled true
        ....

#3


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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/11/21/72a26be767e04e9e2379ced9f8dbd5ca.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com