当前位置: 首页 > 知识库问答 >
问题:

Gradle与ProGuard:找不到参数[true]得runProguard()方法

彭涵衍
2023-03-14

我已经按照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'
    }
}
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

共有1个答案

谷奕
2023-03-14

由于错误的DSL属性名称,这样的错误很常见。确保指定了正确的值:http://tools.android.com/tech-docs/new-build-system/user-guide#toc-running-proguard at yourbuild.gradle:

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

您可以在这里找到包含所有属性的javadoc(单击download DSL reference btn):http://developer.android.com/tools/building/plugin-for-gradle.html

2014-11-24更新:

一些属性被重命名为0.14.0级插件。runproguard->minifyenabled检查Alécio的回答并关注最近的更改列表:http://tools.android.com/tech-docs/new-build-system

 类似资料: