JJD
JJD

Reputation: 51864

How to reference system ProGuard binary in build.gradle?

I noticed that running gradle assembleRelease calls upon an outdated ProGuard version as can be seen from the shell output:

$ gradle assembleRelease
Relying on packaging to define the extension of the main artifact has been \
  deprecated and is scheduled to be removed in Gradle 2.0
:Foobar:preBuild UP-TO-DATE
:Foobar:preReleaseBuild UP-TO-DATE
:Foobar:preDebugBuild UP-TO-DATE
:Foobar:prepareComAndroidSupportAppcompatV71900Library UP-TO-DATE
:Foobar:prepareComGoogleAndroidGmsPlayServices3136Library UP-TO-DATE
:Foobar:prepareReleaseDependencies
:Foobar:compileReleaseAidl UP-TO-DATE
:Foobar:compileReleaseRenderscript UP-TO-DATE
:Foobar:generateReleaseBuildConfig UP-TO-DATE
:Foobar:mergeReleaseAssets UP-TO-DATE
:Foobar:mergeReleaseResources UP-TO-DATE
:Foobar:processReleaseManifest UP-TO-DATE
:Foobar:processReleaseResources UP-TO-DATE
:Foobar:generateReleaseSources UP-TO-DATE
:Foobar:compileRelease UP-TO-DATE
:Foobar:proguardRelease
ProGuard, version 4.9
The output seems up to date
:Foobar:dexRelease UP-TO-DATE
:Foobar:processReleaseJavaRes UP-TO-DATE
:Foobar:packageRelease UP-TO-DATE
:Foobar:assembleRelease UP-TO-DATE

BUILD SUCCESSFUL

Total time: 15.703 secs

I use the following configuration in my build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}

apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
    }

    buildTypes {
        release {
            runProguard true
            proguardFile 'proguard-project.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:19.0.0'
    compile 'com.android.support:support-v4:19.0.0'
    compile 'com.google.android.gms:play-services:3.1.36'
}

How can I point gradle to a newer version of ProGuard which might be available from the PATH, e.g. /usr/local/bin/proguard?

An alternative solution is to reference the desired version as follows:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
        classpath 'net.sf.proguard:proguard-gradle:4.10'
    }
}
...

What is your setup?

Upvotes: 1

Views: 1073

Answers (1)

Varun
Varun

Reputation: 33983

The official Proguard doc shows how you can point to proguard in the build.gradle. See here

As per the Proguard manual you can do the below to point to a proguard binary,

buildscript {
    repositories {
        flatDir dirs: '/usr/local/java/proguard/lib'
    }
    dependencies {
        classpath ':proguard'
    }
}

I think this might cause problems with the proguard version that comes shipped with the android SDK. Not tried yet!!

Upvotes: 2

Related Questions