jvoegele / gradle-android-plugin

Android plugin for the Gradle build system.
Apache License 2.0
406 stars 95 forks source link

Unifying androidPackageDebug and androidPackageRelease #13

Closed fdasoghe closed 13 years ago

fdasoghe commented 13 years ago

What about unifying these two tasks into one more generale task, androidPackage? And let the user configure its behaviour, in order to acquire more customization capabilities.

For example, in the current form of gradle-android-plugin, it's not imediate how to get a signed debug package.

On the unified task you can set (with the standard Gradle ways) several properties in order to customize its behavior: if to sign or not to sign, how to sign (password/etc.), if to zipalign or not, and so on.

Furthermore, I would use same artifact for both input and output for all the tasks after jar, that is:

This way, we get issues #6 (input and output for tasks) and #10 (release package) resolved.

So a user can write build.gradle files like this:

androidPackage {
    // Signing configuration
    keyStore = "my.key.store"
    keyAlias = "my.key.alias"
    keyStorePassword = "1234"
    keyAliasPassword = "5678"
}

task myDebugBuild (dependsOn: androidPackage) {
    // Nothing to do...
}

task myReleaseBuild (dependsOn: proguard, androidPackage) {
    // ... nothing to do, too! :o)
}

I'm going to implement this in the next days. If anybody has any hints/suggestions/critics, he/she's welcome :-)

fdasoghe commented 13 years ago

I've committed some work on my fork.

It's not all I wanted to do (it still misses inputs and outputs management), but the unified task is done, together with optional proguard task.

With this form of the plugin, one can easily get debug and release build, configured as one wishes.

For example, in the build.gradle, one can declare:

// Base configuration, valid for all builds
version = "0.0.5"
androidPackage {
    // Signing configuration
    keyStore = "tools/prova1_keystore"
    keyAlias = "prova1"
    keyStorePassword = "prova1"
    keyAliasPassword = "prova1"
}

for the global configuration. Of course, you can take the signing configuration from everywhere you wish, using all the tools Gradle offers you.

After this, to get the default build (which creates the final apk, signed with the configuration above, in the distributions folder of the project), just call:

gradle assemble

Other builds:

task configureDebug << {
    // To get a customized debug build, call assemble after this task (from command line!)
    jar.classifier = "debug"
}

task configureRelease << {
    // To get a release build, call assemble after this task (from command line!)
    proguard.enabled = true
}

My debug build: gradle configureDebug assemble

My release build: gradle configureRelease assemble

From Gradle's user guide, it seems you can do even better, using the Gradle DAG configuration, exploring which tasks are scheduled for execution and put the right dependency on the configuration tasks... but I'm not so uber-Gradle.

What do you think about this way to create the build process of an Android project?

fdasoghe commented 13 years ago

Fixed in 0.9.5. See the README.txt for instructions.