首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >错误:(26,0)找不到Gradle DSL方法:'runProguard()‘

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

Stack Overflow用户
提问于 2014-11-19 20:04:44
回答 8查看 72.5K关注 0票数 136

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

应用插件:'com.android.application‘

代码语言:javascript
复制
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.+'
}

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

如何解决这个问题?

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2014-11-19 20:06:49

据我所知,minifyEnabled取代了runProguard。我仍然不确定如何定义proguard的配置,但谷歌搜索应该会帮助你找到答案。

编辑:

对于outFile,请阅读此处:https://groups.google.com/forum/#!topic/adt-dev/4_-5NvxuFB0如何做到这一点。

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

代码语言:javascript
复制
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 + "]");
    }
}
票数 97
EN

Stack Overflow用户

发布于 2014-11-21 09:44:50

尝试使用minifyEnabled,而不是在gradle文件中使用runProguard。这应该可以解决这个问题。runProguard已被弃用,很快就会停止工作。

编辑

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

票数 131
EN

Stack Overflow用户

发布于 2014-12-05 13:20:56

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

旧的:

代码语言:javascript
复制
buildTypes {
    release {

        runProguard false // this line has to be changed

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

新的:

代码语言:javascript
复制
buildTypes {
    release {

        minifyEnabled false // new version

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
票数 112
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27016385

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档