Gradle Proguard and Sign Tasks

101 views
Skip to first unread message

Alex Avance

unread,
Apr 15, 2014, 5:42:04 PM4/15/14
to adt...@googlegroups.com
I'm working with a gradle build for an internal app where the proguard and keystore files are hosted on our internal maven server and used across multiple apps.

I'm trying to fetch the keystore and proguard files using gradle then reference them in the setup, but I'm having issues. See the build.gradle below

If I run 'gradle getKeystore getProguard build' everything works, but I can't seem to hook them up directly.

I tried using 'proguardRelease.dependsOn getProguard', but it complains that it can't find proguardRelease or packageRelease properties on project :myproject.

How can I hook up those task dependencies correctly so that it fetches the keystore or proguard config before running the related tasks? Are there android plugin tasks I can hook up to?

configurations {
  signing
  proguard
}

dependencies {
  ...

  signing 'com.internal:keystore:1.0'
  proguard 'com.internal:proguard:1.0'
}

task getKeystore(type: Copy) {
  from configurations.signing
  into "$buildDir/keystore"
  rename '.*\\.keystore', 'android.keystore'
}

task getProguard(type: Copy) {
  from configurations.proguard
  into "$buildDir/proguard"
  rename '.*\\.proguard', 'global.proguard'
}

android {
  ...

  signingConfigs {
    release {
      storeFile file("$buildDir/keystore/android.keystore")
      // keystore password
    }
  }

  buildTypes {
    release {
      signingConfig signingConfigs.release
      runProguard true
      proguardFiles 'proguard-project.cfg', "$buildDir/proguard/global.proguard"
    }
  }

  ...
}

Xavier Ducrohet

unread,
Apr 15, 2014, 6:49:01 PM4/15/14
to adt...@googlegroups.com
Those tasks are created after the project evaluation so you can setup your tasks dependencies in 

afterEvaluate {
}

but it's probably better to do it for each variants:

android.applicationVariants.all { variant -> 
   variant.proguard.dependsOn ...
}


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Alex Avance

unread,
Apr 16, 2014, 6:40:07 PM4/16/14
to adt...@googlegroups.com
Thanks for the input. applicationVariants.all works great for the proguard task (with a null check ofc). I'm using afterEvaluate to bind fetchFooKeystore to validateFooSigning. I have some logic in a signing plugin to bind the tasks, fetch the keystores, and set up the signing config so I can reuse it across our apps. I assume that's a decent way to do it.

Thanks again for your help.


--
You received this message because you are subscribed to a topic in the Google Groups "adt-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adt-dev/-QpPPu3bsWk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adt-dev+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alex Avance
Reply all
Reply to author
Forward
0 new messages