16
votes

I've configured the build.gradle as suggested by Proguard Gradle manual

This is root build.gradle

buildscript {
    repositories {
        flatDir dirs: '/home/username/android-sdks/tools/proguard/lib'
        mavenCentral()
    }
    dependencies {                     
        classpath 'com.android.tools.build:gradle:0.5.+'
        classpath ':proguard'
    }
}

Now this is the build.gradle for my project

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':SomeLibraryProject')
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    sourceSets {
        ...
    }

    task runProguardTask(type: proguard.gradle.ProGuardTask) {
    }

    signingConfigs {
        debug {
            storeFile file("./keystore/keystore")
            storePassword "******"
            keyAlias "******"
            keyPassword "*******"
        }

        release {
            runProguard true
            proguardFile 'proguard-android.txt'
            storeFile file("./releasekey/keystore")
            storePassword "******"
            keyAlias "********"
            keyPassword "*******"
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }  
}

And this is the output

$ ./gradlew build

FAILURE: Build failed with an exception.

* Where:
Build file '/home/username/Documents/eclipse/workspace/repo/ProjectName/build.gradle' line: 49

* What went wrong:
A problem occurred evaluating project ':ProjectName'.
> Could not find method runProguard() for arguments [true] on SigningConfigDsl_Decorated{name=release, storeFile=null, storePassword=null, keyAlias=null, keyPassword=null, storeType=null}.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 9.14 secs

I also wonder why the storeFile, storePassword, keyAlias and keyPassword are null?

3

3 Answers

13
votes

Errors like that are common due to wrong DSL property names. Make sure you specify correct values: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Running-ProGuard at your build.gradle:

android {
    buildTypes {
        release {
            minifyEnabled true
            proguardFile getDefaultProguardFile('proguard-android.txt')
        }
    }
}

You can find javadoc with all properties here (click download DSL reference btn): http://developer.android.com/tools/building/plugin-for-gradle.html


Update from 2014-11-24:

A few properties was renamed at 0.14.0 gradle plugin. runProguard -> minifyEnabled check answer from Alécio and follow recent changes list here: http://tools.android.com/tech-docs/new-build-system

57
votes

runProguard is deprecated (and will soon stop working); change to "minifyEnabled" instead

...

buildTypes {
    release {
        minifyEnabled true
        ....
3
votes
runProguard is deprecated after gradle build tools version 1.0.0-rc1
Running ProGuard



ProGuard is supported through the Gradle plugin for ProGuard version 4.10. The ProGuard plugin is applied automatically, and the tasks are created automatically if the Build Type is configured to run ProGuard through the minifyEnabled property.

android {
    buildTypes {
        release {
            minifyEnabled true
            proguardFile getDefaultProguardFile('proguard-android.txt')
        }
    }

    productFlavors {
        flavor1 {
        }
        flavor2 {
            proguardFile 'some-other-rules.txt'
        }
    }
}