错误:(26,0)未找到Gradle DSL方法:'runProguard()'

Nic*_*ckF 136 android android-gradle-plugin

我正在使用带有gradle的android studio 0.9.3 'com.android.tools.build:gradle:0.14.+'

apply plugin:'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion '20.0.0'

    defaultConfig {
        applicationId "xxx.xxx.xxx"
        minSdkVersion 16
        targetSdkVersion 19
        versionCode 1
        versionName "1.0.11"
    }

    signingConfigs{
        releaseConfig{
            storeFile file("xxxxxxx")
            storePassword = "xxxx"
            keyAlias = "xxxx"
            keyPassword = "xxxx"
        }
    }

    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.releaseConfig

            // adds version to file name
            applicationVariants.all { variant ->
                def file = variant.outputFile
                variant.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
            }
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    // You must install or update the Support Repository through the SDK manager to use this dependency.
    // You must install or update the Support Repository through the SDK manager to use this dependency.
    // You must install or update the Google Repository through the SDK manager to use this dependency.
    // You must install or update the Support Repository through the SDK manager to use this dependency.
    compile 'com.android.support:support-v4:19.+'
    compile 'com.android.support:appcompat-v7:19.+'
    compile 'com.mcxiaoke.volley:library:1.0.6'
    compile 'com.google.code.gson:gson:2.2.+'
}
Run Code Online (Sandbox Code Playgroud)

之前编译的项目没有对该文件进行任何更改,我得到: 错误:(26,0)未找到Gradle DSL方法:'runProguard()'

如何解决?

Var*_*oid 131

不要runProguard在gradle文件中使用,请尝试使用minifyEnabled.这应该解决问题.runProguard已被弃用,很快就会停止工作.

编辑

要使用minifyEnabled,gradle应更新到2.2或更高版本.

  • 应该是`minifyEnabled`(不是'minifyEnable`) (6认同)

And*_*rey 112

应用build.gradle文件中的更改可能会有所帮助:

旧:

buildTypes {
    release {

        runProguard false // this line has to be changed

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
Run Code Online (Sandbox Code Playgroud)

新:

buildTypes {
    release {

        minifyEnabled false // new version

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
Run Code Online (Sandbox Code Playgroud)


War*_*ith 97

据我所知,runProguard被替换为minifyEnabled.我仍然不确定如何定义proguard的配置,但Google搜索应该可以帮助您找到答案.

编辑:

如需outFile阅读:https://groups.google.com/forum/#!topic/sq-dev/4_- 5NvxuFB0他们是如何做到的.

简而言之:他们使用了更复杂的版本:

applicationVariants.all { variant ->

    variant.outputs.each { output ->

        def apk = output.outputFile;
        def newName;

        // newName = apk.name.replace(".apk", "-v" + defaultConfig.versionName + "-" + variant.buildType.name.toUpperCase() + ".apk");
        if (variant.buildType.name == "release") {
            newName = apk.name.replace(".apk", "-v" + defaultConfig.versionName + "-release.apk");
        } else {
            newName = apk.name.replace(".apk", "-v" + defaultConfig.versionName + "-beta.apk");
        }

        output.outputFile = new File(apk.parentFile, newName);

        if (output.zipAlign) {
            output.outputFile = new File(apk.parentFile, newName.replace("-unaligned", ""));
        }

        logger.info('INFO: Set outputFile to ' + output.outputFile + " for [" + output.name + "]");
    }
}
Run Code Online (Sandbox Code Playgroud)


Int*_*iya 26

如果您使用的是gradle插件的0.14.0或更高版本,则应在文件中将runProguard" minifyEnabled" 替换为" " build.gradle.

只需添加这个.

 buildTypes {           
     release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
                }
            }
Run Code Online (Sandbox Code Playgroud)

minifyEnabled false意味着构建类型名称不能是main或androidTest(这是由插件强制执行的),并且它们必须彼此唯一.

新版Android Gradle插件,可以自动删除未使用的资源.这里的最大胜利是它不仅从您自己的代码中删除未使用的资源,更重要的是从您正在使用的库中删除(例如,包含的资源用于支持您实际上未在应用中使用的功能).


san*_*one 25

Gradle 0.14.4开始,这些错误报告为编译时错误.

所以,你必须更换runProguard false/trueminifyEnabled false/true

这些更改列在Android开发人员博客上.


mad*_*adx 21

将Gradle项目迁移到版本1.0.0需要一些简单的重命名工作,所有内容都在这里描述:http: //tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0

对于proguard,你可以简单地重命名'runProguard'=>'minifyEnabled',其他人见下文:

Renamed Properties in BuildTypes:    
runProguard => minifyEnabled
zipAlign => zipAlignEnabled
jniDebugBuild => jniDebuggable
renderscriptDebug => renderscriptDebuggable

Renamed Properties in ProductFlavors:    
flavorGroups => flavorDimensions
packageName => applicationId
testPackageName => testApplicationId
renderscriptSupportMode => renderscriptSupportModeEnabled
ProductFlavor.renderscriptNdkMode => renderscriptNdkModeEnabled
Other Name changes

InstrumentTest was renamed to androidTest.
Run Code Online (Sandbox Code Playgroud)