Created
April 23, 2013 12:58
-
-
Save fredgrott/5443348 to your computer and use it in GitHub Desktop.
gant andoird app buildfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//author: Fred Grott(http://about.me/fredgrott) | |
//license: Apache 2.0 License | |
// | |
// Watch things: | |
// project.properties props are nonGroovy naming syntax | |
// | |
// | |
// loadProperties{} To load all the properties from | |
// properties files.We also load the | |
// keyStore.properties file. | |
includeTool << gant.tools.Ivy | |
loadProperties { | |
property(file: 'local.properties') | |
property(file: 'gant.properties') | |
property(file: 'project.properties') | |
property(file: "${ant.project.properties.keystoreDir}/keystore.properties") | |
ant.project.properties | |
} | |
// simple closure to print out the individual | |
// properties of the properties files that were loaded | |
// notice what its filtering out | |
printProperties = {props -> | |
def sysProps = System.properties.keySet() | |
def names = props.keySet().grep { !(it =~ /^environment/) && !sysProps.contains(it) } as TreeSet | |
names.each {name -> println "${name} : ${props[name]}" } | |
} | |
inittoolsLocation { | |
def androidtoolsDir = "${androidsdkDir}/tools" | |
def androidplatformtoolsDir = "${androidsdkDir}/platform-tools" | |
def ourExe = Ant.condition(property: 'exe', value: 'exe', else: '.'){ | |
Ant.os(family:'windows') | |
} | |
def ourBat = Ant.condition(property: 'bat', value: 'bat', else: ''){ | |
Ant.os(family: 'windows') | |
} | |
def adbExec = "${androidplatformtoolsDir}/adb${ourExe}" | |
def zipaignExec = "${androidtoolsDir}/zipalign${ourExe}" | |
def aidlExec = "${androidplatformtoolsDir}/aidl${ourExe}" | |
def aaptExec = "${androidplatformtoolsDir|/aapt${ourExe}" | |
def dxExec = "${androidplatformtoolsDir}/dx${outBat}" | |
def rsExec = "${androidplatformtoolsDir}/llvm-rs-cc${ourExe}" | |
def lintExec = "${androidtoolsDir}/lint${ourBat}" | |
} | |
// Careful ${exe} is not windows exe | |
// but the exectuable..in windows | |
// this closure has to have the | |
// executable extensions | |
initAndroid = {skdhome, target -> | |
def chk = {dir, exe -> | |
def cmd = "${skdhome}/${dir}/${exe}" | |
expectFile cmd | |
cmd | |
} | |
aapt = chk 'platform-tools', 'aapt${ourExec}' | |
dex = chk 'platform-tools', 'dx${ourBat}' | |
adb = chk 'platform-tools', 'adb${ourExe}' | |
aidl = chk 'platform-tool' , 'aidl${ourExe}' | |
lint = chk 'tools' , 'lint${ourBat}' | |
apk = chk 'tools', 'apkbuilder' | |
zipalign = chk 'tools', 'zipalign${ourExe}' | |
renderscript = chk 'platform-tools' , 'llvm-rs-cc${ourExe}' | |
androidJar = chk "platforms/${version}", 'android.jar' | |
proguardJar = chk "tools/proguard/lib", 'proguard.jar' | |
emmaJar = chk "tools/lib" , 'emma.jar' | |
emmaAntJar = chk "tools/lib" , 'emma.ant.jar' | |
} | |
// check the properties set by loading the properties files | |
//if they are not set do log of error and system exit | |
checkFileSetProperties{ | |
carryOn = true | |
['androidSdkDir', 'buildDir', 'srcDir' , 'keystoreDir' | |
].each { name -> | |
try { binding.getVariable ( name ) } | |
catch ( MissingPropertyException mpe ) { | |
ant.project.log ( "${name} is not defined in a property file." ) | |
carryOn = false | |
} | |
} | |
if ( ! carryOn ) { | |
ant.project.log ( 'A required property is not set, so terminating.' ) | |
System.exit ( 1 ) | |
} | |
} | |
// Setup Ivy managed Lib deps of project | |
initIvyLibDeps{ | |
def projectlibDir = "lib" | |
def classpathRef= 'docletpathRef' | |
def antclasspathRef = 'anttaskpathRef' | |
ivy.retrieve() | |
ivy.cachepath(conf:'doclet', pathid : classpathRef ) | |
//ivy.cachepath(conf:'anttask',pathid: antclasspathRef) | |
} | |
// Setup ant task defs for the project | |
initAntTaskDefs { | |
// we need path setup for emma for its taskdef as its from the | |
// android sdk install | |
def toolslibDir = "${androidsdkDir}/tools/lib" | |
def emmaJars = Ant.path(id: 'emmaJars'){ | |
fileset(dir: toolslibDir) { | |
include(name: 'emma.jar') | |
include(name: 'emma.ant.jar') | |
} | |
} | |
//<taskdef resource="emma_ant.properties" classpathref="emma.lib" /> | |
Ant.taskdef(resource:'emma_ant.properties', classpathref: emmaJars) | |
//android antlibs | |
def androidantlibJar = Ant.path(id: 'androidlibJar'){ | |
fileset(dir: toolslibDir){ | |
include(name: 'anttasks.jar') | |
} | |
} | |
Ant.taskdef(resource: 'anttasks.properties', classpathref: androidantlibJar) | |
// other taskdefs for any codeqa,etc go below | |
} | |
// android project preferred properties setup | |
initAndroidPrefProperties { | |
// project.properties: | |
// target | |
// local.properties: | |
// keystoreDir | |
// androidsdkDir | |
// gant.properties | |
// | |
// | |
//other properties | |
def sourceDir = "src" | |
def genDir = "gen" | |
def resDir = "res" | |
def assetsDir = "assets" | |
def jarlibsDir = "libs" | |
def nativelibsDir = "libs" | |
def manifestFile = "AndroidManifest.xml" | |
// buildDir is already defined | |
def classersDir = "${buildDir}/classes" | |
def buildresDir = "${buildDir}/res" | |
def buildaidlDir = "${buildDir}/aidl" | |
def builddexedDir = "${buildDir}/dexedLibs" | |
def buildmanifestFile = "${buildDir}/AndroidManifest.xml" | |
//def androidtoolsDir = "${androidsdkDir}/tools" | |
//def androidplatformtoolsDir ="${androidsdkDir}/platform-tools" | |
} | |
// more modulization of init than a typical ant | |
// build setup, makes build easy to read and debug | |
target(init : 'Setups the build') { | |
proj = loadProperties() | |
printProperties proj | |
checkFileSetProperties | |
inittoolsLocation | |
initAndroid proj.androidsdkDir, proj.target | |
initIvyLibDep | |
initAntTaskDefs | |
initAndroidPrefProperties | |
destDir = createDirs proj.buildDir genDir | |
} | |
// I think we need to clean both proj.buildDir and proj.genDir | |
target(clean : 'Deletes the build dir') { | |
proj = loadProperties() | |
deleteDir "${proj.buildDir}", "{proj.genDir}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment