The Gradle script below will let you build an Android Library while still being able to develop your code in Eclipse. Unfortunately, you can only use this script for the final command line build process, but this it's an alternative to using Ant/Maven for the release process at least. I'll annotate the script in blue with my comments on how it works.
buildscript {
repositories {
mavenCentral()
}
dependencies {
the Android Gradle plugin changes frequently, so change this version# as needed
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
this is the reference to the Android Library plugin (apps use just the 'android' plugin)
apply plugin: 'android-library'
android {
this references the latest Android SDK installed on your system
compileSdkVersion 18
buildToolsVersion "18.0.0"
defaultConfig {
these versions match what's in your AndroidManifest.xml file
targetSdkVersion 18
minSdkVersion 10
versionCode 10
}
this remaps the standard Gradle layout (root at src/main) to the Eclipse Android project directory layout
sourceSets {
main {
manifest {
srcFile 'AndroidManifest.xml'
}
java {
srcDir 'src'
}
res {
srcDir 'res'
}
assets {
srcDir 'assets'
}
resources {
srcDir 'src'
}
}
}
}
/// add dependencies
repositories {
mavenCentral()
}
dependencies {
this pulls the support library artifact from your local ADK install's repos
compile group: 'com.android.support', name: 'support-v4', version: '13.0.+'
}
the jar() and javaDoc() functions are in the 'java' plugin and for some reason Android's plugin checks that the 'java' plugin is *not* installed before it'll work, so you have to rewrite any functionality for those using the executables
//jar method lives inside java plugin which we can't include
// because it conflict w/ Android plugin :-P
//jar {
// manifest {
// attributes 'Implementation-Title': 'Android DDP Client Library',
// 'Implementation-Version': version
// }
//}
this is my version of the javaDoc function
task makeJavadoc(type:Exec) {
commandLine 'javadoc', '-d', 'build/docs/javadoc', '-sourcepath', './src', '-subpackages', 'com'
standardOutput = new ByteArrayOutputStream()
errorOutput = new ByteArrayOutputStream()
//extension method makeJavadoc.output() can be used to obtain the output:
ext.output = {
return standardOutput.toString()
}
ext.error = {
return errorOutput.toString()
}
}
// can't ", dependsOn: javadoc" because that is in the java plugin which isn't compatible w/ Android plugin :-P
task javadocJar(type: Jar, dependsOn: makeJavadoc) {
classifier = 'javadoc'
from 'build/docs/javadoc'
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.allSource
}
=======================
As mentioned above, the Android Gradle plugin uses Maven artifacts from the local ADK Manager repos (install these in the Extras section of the list of toolkits to install). It's important that you get the artifact names right or Gradle will try pulling them from Maven Central:
com.android.support:support-v4:13.0.0
com.android.support:support-v13:13.0.0
com.android.support:gridlayout-v7:13.0.0
com.google.android.gms:play-services:3.1.36
Su | Mo | Tu | We | Th | Fr | Sa |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | ||||