Skip to content

Instantly share code, notes, and snippets.

@kimukou
Last active October 13, 2015 01:18
Show Gist options
  • Save kimukou/4117051 to your computer and use it in GitHub Desktop.
Save kimukou/4117051 to your computer and use it in GitHub Desktop.
apkinstall_builder.groovy
//println("path => " + this.class.protectionDomain.codeSource.location.path)
//println("fileName => " + new File(this.class.protectionDomain.codeSource.location.file).name)
def loc=this.getClass().getProtectionDomain().getCodeSource().getLocation()
println "===start($loc)==="
def prop1 = new Properties()
prop1.load(new FileInputStream('local.properties'))
def config = new ConfigSlurper().parse(prop1)
def adb_home="${config.sdk.dir}/platform-tools"
def apkName= "${config.release.app.name}_${config.release.app.version}.apk"
println apkName
def manifestXml = new XmlSlurper().parse(new File("AndroidManifest.xml"))
//println manifestXml.dump()
pkgName = [email protected]()
println pkgName
activity = manifestXml.application.activity[0].@'android:name'.text()
println activity
def ant = new AntBuilder()
println ant.dump()
//read build.xml
import org.apache.tools.ant.Project
import org.apache.tools.ant.ProjectHelper
def antFile = new File("./build.xml")
def project = new Project()
project.init()
ProjectHelper.configureProject(project, antFile);
project.addTarget(
ant.target(name: "apt") {
ant.mkdir(dir:'bin')
ant.mkdir(dir:'gen')
//apt 実行バージョン
ant.exec(outputproperty:"cmdOutA",
errorproperty: "cmdErrA",
resultproperty:"cmdExitA",
failonerror: "true",
dir:".",
executable: "apt") {
arg(value:"-AJsonPullParserClassPostfix=Gererated")
arg(value:"-AJsonPullParserDebug=true")
arg(line:"-cp factory/jsonpullparser-apt-1.5.1.jar")
arg(line:"-factory net.vvakame.util.jsonpullparser.factory.JsonAnnotationProcessor")
arg(line:"-d bin")
arg(line:"-s gen")
new File("src/com/twitpic/bean").eachFileMatch(~".*.java"){
arg(value:it.absolutePath)
println it.absolutePath
}
}
println "<${ant.project.properties.cmdExitA}>=${ant.project.properties.cmdOutA}"
/*
//java 1.6バージョン(動かない)
//see http://svn.codehaus.org/groovy/tags/GROOVY_1_7_6/src/test/groovy/util/AntTest.groovy
// https://gist.github.com/4428306
def cls_lib = ant.path {
fileset(dir: "${config.sdk.dir}/tools/lib") {
include(name: "*.jar")
}
fileset(dir: 'libs') {
include(name: "*.jar")
}
}
ant.javac(
includeAntRuntime: false,
classpath: cls_lib,
srcdir: "src/com/twitpic/bean",
encoding: "UTF-8"
) {
//compilerarg(line:"-AJsonPullParserClassPostfix=Gererated") //認識されない警告が出る
//compilerarg(line:"-AJsonPullParserDebug=true") //認識されない警告が出る
//compilerarg(line:"-factory net.vvakame.util.jsonpullparser.factory.JsonAnnotationProcessor")
compilerarg(line:"-processorpath factory/jsonpullparser-apt-1.5.1.jar")
//compilerarg(line:"-d bin")
compilerarg(line:"-s gen")
}
*/
}
)
//project.executeTargets(['debug'] as Vector)
project.executeTargets(['clean','apt','debug'] as Vector)
//cmd = "${adb_home}/adb devices"
//println cmd
//def proc = cmd.execute()
//proc.waitFor()
//see http://www.dzeta.jp/~junjis/code_reading/index.php?ant%2F%A5%D3%A5%EB%A5%C9%A5%D7%A5%ED%A5%BB%A5%B9%A4%F2%C6%C9%A4%E0
//=== after-copy ==
org_file = project.getProperty('out.final.file')
to_file="./${project.getProperty('out.dir')}/../${apkName}"
println "org_file=$org_file"
ant.echo "to_file=$to_file"
ant.copy(file:org_file,tofile:to_file,overwrite:true)
//=== after-copy-install ==
cmd=''
ant.exec(outputproperty:"cmdOut",
errorproperty: "cmdErr",
resultproperty:"cmdExit",
failonerror: "false",
dir:".",
executable: "${adb_home}/adb") {
arg(line:"devices")
}
println "[$cmd]<${ant.project.properties.cmdExit}>=${ant.project.properties.cmdOut}"
def deviceList = []
def txt =ant.project.properties.cmdOut
println txt
txt.split('\n').each{
if(""== it.trim() || it=~/List*/ )return;//same continure
device = it.split('\t')[0]
println device
deviceList.add device
}
println deviceList.dump()
cmd=''
deviceList.each{
cmd ="-s $it uninstall $pkgName"
ant.exec(outputproperty:"cmdOut2",
errorproperty: "cmdErr2",
resultproperty:"cmdExit2",
dir:".",
failonerror: "false",
executable: "${adb_home}/adb") {
arg(line:cmd)
}
println "[$cmd]<${ant.project.properties.cmdExit2}>=${ant.project.properties.cmdOut2}"
//println "stderr: ${ant.project.properties.cmdErr2}"
cmd = "-s $it install $apkName"
ant.exec(outputproperty:"cmdOut3",
errorproperty: "cmdErr3",
resultproperty:"cmdExit3",
dir:".",
failonerror: "false",
executable: "${adb_home}/adb") {
arg(line:cmd)
}
println "[$cmd]<${ant.project.properties.cmdExit3}>=${ant.project.properties.cmdOut3}"
//println "stderr: ${ant.project.properties.cmdErr3}"
cmd = "-s $it shell am start -a android.intent.action.MAIN -n ${pkgName}/${activity}"
ant.exec(outputproperty:"cmdOut3",
errorproperty: "cmdErr4",
resultproperty:"cmdExit4",
dir:".",
failonerror: "false",
executable: "${adb_home}/adb") {
arg(line:cmd)
}
println "[$cmd]<${ant.project.properties.cmdExit4}>=${ant.project.properties.cmdOut4}"
//println "stderr: ${ant.project.properties.cmdErr4}"
}
println "===end($loc)==="
sdk.dir=/Users/XXXXXX/android-sdk-macosx
key.store=irof.keystore
key.alias=irofworld
key.store.password=irof_friend
key.alias.password=irof_friend
release.app.name=irof-history
release.app.version=v01
@kimukou
Copy link
Author

kimukou commented Nov 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment