137

I'm using 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.+'
}

The project compiled before without any changes in that file, I'm getting: Error:(26, 0) Gradle DSL method not found: 'runProguard()'

How to fix that?

NickF
  • 5,637
  • 12
  • 44
  • 75
  • 1
    You can read this for reference: http://tools.android.com/tech-docs/new-build-system. It will illuminate such questions for you. – IgorGanapolsky Jan 08 '15 at 15:24

8 Answers8

131

Instead of using runProguard in your gradle file, try using minifyEnabled. This should fix the issue. runProguard is deprecated and soon be stop working.

EDIT

To use minifyEnabled, gradle should be updated to version 2.2 or above.

Varundroid
  • 9,135
  • 14
  • 63
  • 93
112

Change in the app build.gradle file may help:

old:

buildTypes {
    release {

        runProguard false // this line has to be changed

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

new:

buildTypes {
    release {

        minifyEnabled false // new version

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
Andrew
  • 36,676
  • 11
  • 141
  • 113
97

As far as I know runProguard was replaced with minifyEnabled. I am still not sure how to define the config for proguard but a Google search should help you to find out.

Edit:

For the outFile read here: https://groups.google.com/forum/#!topic/adt-dev/4_-5NvxuFB0 how they do it.

In short: they used a more complex version:

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 + "]");
    }
}
WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
  • 1
    now it has problem with Error:(32, 0) Could not find property 'outputFile' on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@1615795. – NickF Nov 19 '14 at 12:08
  • 1
    That is correct, read the changes under 0.14.0 to know the exact changes http://tools.android.com/tech-docs/new-build-system – Soham Nov 21 '14 at 10:02
  • I edited to reflect the error about outputFile (edit currently waiting peer review) – RoundSparrow hilltx Jan 08 '15 at 13:40
  • 1
    I have removed the duplicated `applicationVariants.all { variant ->` line but accepted the rest, thanks – WarrenFaith Jan 08 '15 at 13:59
  • i have same problem with different method: Gradle DSL method not found compileSdkVersion() – Usman Jun 11 '15 at 06:25
26

If you are using version 0.14.0 or higher of the gradle plugin, you should replace "runProguard" with "minifyEnabled" in your build.gradle files.

Just add this.

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

minifyEnabled false Means Build Type names cannot be main or androidTest (this is enforced by the plugin), and that they have to be unique to each other.

The new version of the Android Gradle plugin, can automatically remove unused resources. The big win here is that it removes unused resources not just from your own code, but more importantly from libraries you are using (e.g. where there are resources included to support features that you are not actually using from your app).

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
25

As of Gradle 0.14.4, these errors are reported as compile-time errors.

So you have to replace runProguard false/true with minifyEnabled false/true

The changes are listed on Android Developers Blog.

sandalone
  • 41,141
  • 63
  • 222
  • 338
21

Migrating Gradle Projects to version 1.0.0 needs some easy renaming work, everything is described here: http://tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0

For proguard you can simply rename 'runProguard' => 'minifyEnabled', for the others see below:

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.
madx
  • 6,723
  • 4
  • 55
  • 59
  • I appreciate both the android docs as well as you highlighting them, but where do you find everything else from zipAlign going forwards? There's neglect to mention in which files this will be found. I do not see them in my root gradle config file. – tinonetic Dec 09 '14 at 22:28
3

This is due to the update of the gradle android tools to 0.14.3. Into your file "build.gradle" replace

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

by:

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

Until they fix it…

stankocken
  • 2,201
  • 4
  • 19
  • 18
1

runProguard has been renamed to minifyEnabled in version 0.14.0 (2014/10/31) of Gradle.

To fix this, you need to change runProguard to minifyEnabled in the build.gradle file of your project.

enter image description here

Biswajit Karmakar
  • 9,799
  • 4
  • 39
  • 41