【问题标题】:Error:(26, 0) Gradle DSL method not found: 'runProguard()'错误:(26, 0) 找不到 Gradle DSL 方法:'runProguard()'
【发布时间】:2015-01-16 22:39:31
【问题描述】:

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

应用插件:'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.+'
}

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

如何解决?

【问题讨论】:

标签: android android-gradle-plugin


【解决方案1】:

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

编辑

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

【讨论】:

  • 错误现在改为--> "Gradle DSL method not found: 'minifyEnable()'"
  • 您是否安装了最新的 gradle build system (2.2)?
  • 我遇到了同样的错误。未找到 minifyEnable。你找到解决办法了吗?
  • @Varundroid 哦,它依赖于 2.2 吗?我有 2.1
  • 应该是minifyEnabled(不是minifyEnable)
【解决方案2】:

更改应用程序 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'
    }
}

【讨论】:

  • 按照你的建议做了仍然得到同样的错误。
【解决方案3】:

据我所知,runProguard 已替换为 minifyEnabled。我仍然不确定如何定义 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 + "]");
    }
}

【讨论】:

  • 现在它有问题 Error:(32, 0) Could not find property 'outputFile' on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@1615795。
  • 没错,阅读0.14.0下的改动就知道具体改动了tools.android.com/tech-docs/new-build-system
  • 我编辑以反映有关 outputFile 的错误(编辑当前等待同行评审)
  • 我已经删除了重复的applicationVariants.all { variant -> 行,但接受了其余的行,谢谢
  • 我用不同的方法有同样的问题:找不到 Gradle DSL 方法 compileSdkVersion()
【解决方案4】:

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

只需添加这个。

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

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

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

【讨论】:

  • @GeorgiAngelov 很高兴收到您的 cmets 。快乐编码
【解决方案5】:

从 Gradle 0.14.4 开始,这些错误被报告为编译时错误。

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

更改列在Android Developers Blog 上。

【讨论】:

    【解决方案6】:

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

    【讨论】:

    • 我很欣赏 android 文档以及您突出显示它们的内容,但是您在哪里可以找到 zipAlign 的其他所有内容?忽略了将在哪些文件中找到它。我在我的根 gradle 配置文件中没有看到它们。
    【解决方案7】:

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

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

    作者:

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

    直到他们修复它……

    【讨论】:

      【解决方案8】:

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

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

      【讨论】:

        猜你喜欢
        • 2015-01-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-28
        相关资源
        最近更新 更多