首页 文章

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

提问于
浏览
136

我正在使用android studio 0.9.3 with gradle '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.+'
}

之前编译的项目没有对该文件进行任何更改,我得到: Error:(26, 0) Gradle DSL method not found: 'runProguard()'

如何解决?

8 回答

  • 3

    据我所知 runProguardminifyEnabled 取代 . 我仍然不确定如何定义proguard的配置,但Google搜索应该可以帮助您找到答案 .

    编辑:

    对于 outFile 在这里阅读:https://groups.google.com/forum/#!topic/adt-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 + "]");
        }
    }
    
  • 97

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

    EDIT

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

  • 112

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

    旧:

    buildTypes {
        release {
    
            runProguard false // this line has to be changed
    
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    

    新:

    buildTypes {
        release {
    
            minifyEnabled false // new version
    
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    
  • 21

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

    只需添加这个 .

    buildTypes {           
         release {
                        minifyEnabled false
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
                    }
                }
    

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

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

  • 26

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

    所以你必须用 minifyEnabled false/true 替换 runProguard false/true

    更改列在Android Developers Blog上 .

  • 1

    将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.
    
  • 25

    这是由于gradle android工具更新到0.14.3 . 进入你的文件“build.gradle”替换

    classpath 'com.android.tools.build:gradle:0.14.+'
    

    通过:

    classpath 'com.android.tools.build:gradle:0.14.2'
    

    直到他们解决它...

  • 131

    runProguard 已在Gradle版本0.14.0(2014/10/31)中重命名为 minifyEnabled .

    要解决此问题,您需要在项目的 build.gradle 文件中将runProguard更改为minifyEnabled .

    enter image description here

相关问题