Android command-line: gradle and testing

For android projects, some engineers use Android Studio (new), some use Eclipse with ADT (old), few like me still savor command line, this blog post is about handling (building, installing and testing) android projects from command line. To create android project Sh 1 2 $ android create project --target 4 --name TestAndroidApp --path ./test_android_app --activity Main --package net.ashishb.TestAndroidApp --gradle --gradle-version 1.0.+  ... After changing to directory test_android_app (cd test_android_app), fix a bug ...

Android, Gradle and compile-time only dependencies

Android plugin for Gradle does not support Java-style compile time only dependencies. After spending a few hours on trying to build android app targeted for Amazon SDK (without using Amazon’s Android specific plugin but just their jar stubs for maps, ADM and Home widget), I finally found that the one way to support compile-time dependencies is following. For application project Groovy 1 2 3 4 5 6 7 8 9 10 11 12 13 configurations { provided } dependencies { // ... provided fileTree(dir: "${project.rootDir}/path_to_libs_dir", include: '*.jar') } // Android's version of sourceSets.main.compileClasspath android.applicationVariants.each { variant -> variant.javaCompile.classpath += configurations.provided } For the library project Groovy 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 configurations { provided } dependencies { // ... compile fileTree(dir: 'libs', include: '*.jar') provided fileTree(dir: "${project.rootDir}/patch_to_libs_dir", include: '*.jar') } android.libraryVariants.all { variant -> // Exclude the jar files from making its way into the final apk. // Irrespective of what the path_to_libs_dir is the final jar files end up in libs dir. variant.packageLibrary.exclude('libs/lib1.jar') variant.packageLibrary.exclude('libs/lib2.jar') // ... } References https://stackoverflow.com/questions/16613722/gradle-configurations-not-working-as-expected-in-new-android-build-system http://stackoverflow.com/a/24157721