505

I get an error after updating from my last project. Not a problem in my code but I'm having trouble with build.gradle. How can I fix it?

build.gradle code here:

apply plugin: 'android'

android {
    compileSdkVersion 21
    buildToolsVersion '20.0.0'

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }

    defaultConfig {
        applicationId 'com.xxx.axxx'
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 6
        versionName '1.0'
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.+'
    compile files('libs/commons-codec-1.8.jar')
    compile files('libs/asmack-android-8-4.0.4.jar')
    compile 'com.android.support:support-v4:21.0.0'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.jakewharton:butterknife:5.1.1'
}

Gradle Sync message output:

Error:(27, 0) Gradle DSL method not found: 'runProguard()'
**Possible causes:
The project 'Atomic4Mobile' may be using a version of Gradle that does not contain the method.
**Gradle settings**
The build file may be missing a Gradle plugin.
**Apply Gradle plugin**
Mahozad
  • 18,032
  • 13
  • 118
  • 133
abaci
  • 5,226
  • 2
  • 12
  • 13

6 Answers6

821

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

runProguard was renamed to minifyEnabled in version 0.14.0. For more info, See Android Build System

Naveed Ahmad
  • 6,627
  • 2
  • 58
  • 83
Babatunde Adeyemi
  • 14,360
  • 4
  • 34
  • 26
  • 4
    The source for this is [here](http://tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0). – Chris Cirefice Dec 23 '14 at 03:43
  • 3
    there are two build.gradle files, the inner one , the one in the app subdirectory, is the one. – barlop Jan 16 '15 at 05:26
  • Error:(26, 0) Gradle DSL method not found: 'classpath()' Possible causes: The project 'Sample' may be using a version of Gradle that does not contain the method. – Prasad Feb 15 '16 at 12:17
281

Using 'minifyEnabled' instead of 'runProguard' works properly.

Previous code:

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

Current code:

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
Halo
  • 1,730
  • 1
  • 8
  • 31
Amitabha Biswas
  • 3,281
  • 1
  • 11
  • 23
72

If you are migrating to 1.0.0 you need to change the following properties.

In the Project's build.gradle file you need to replace minifyEnabled.

Hence your new build type should be

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

Also make sure that gradle version is 1.0.0 like

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

in the build.gradle file.

This should solve the problem.

Source: http://tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
Bhargav Jhaveri
  • 2,123
  • 1
  • 18
  • 23
17

By changing runProguard to minifyEnabled, part of the issue gets fixed.

But the fix can cause "Library Projects cannot set application Id" (you can find the fix for this here Android Studio 1.0 and error "Library projects cannot set applicationId").

By removing application Id in the build.gradle file, you should be good to go.

Community
  • 1
  • 1
Sandeep Kumar
  • 489
  • 5
  • 8
  • Try to trace the answer here and then give the link to it. – codebot Feb 09 '15 at 06:30
  • Somebody should have told that already. Great! After doing **minifyEnabled**, need to do this as well in buld.gradle of all the external library projects as well. – sud007 Mar 17 '15 at 08:28
0

runProguard has been renamed to minifyEnabled in version 0.14.0 (2014/10/31) or more in 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
0

This is for Kotlin DSL (build.gradle.kts):

buildTypes {
    getByName("release") { // or simply  release {  in newer versions of Android Gradle Plugin (AGP)
      isMinifyEnabled = true
      isShrinkResources = true
      proguardFiles(
        // "proguard-android-optimize.txt" reduces size more than "proguard-android.txt"
        getDefaultProguardFile("proguard-android-optimize.txt"),
        "proguard-rules.pro"
      )
      signingConfig = signingConfigs.getByName("mySigningConfig")
    }
}

I'm using Android Gradle Plugin (AGP) version 7 in my top-level build file:

buildscript {
  // ...
  dependencies {
      classpath("com.android.tools.build:gradle:7.0.4")
      // ...
  }
}
Mahozad
  • 18,032
  • 13
  • 118
  • 133