Skip to content

Instantly share code, notes, and snippets.

@krgn
Created May 14, 2011 13:18
Show Gist options
  • Save krgn/972202 to your computer and use it in GitHub Desktop.
Save krgn/972202 to your computer and use it in GitHub Desktop.
ant and android - macro to kill, uninstall, install and then launch an app. requires a simple setting of "main-activity" in projects build.xml
<macrodef name="install-helper">
<sequential>
<echo>Killing the running app...</echo>
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}" />
<arg value="shell" />
<arg value="killall" />
<arg value="${manifest.package}" />
</exec>
<echo>Uninstalling previous version for clean slate...</echo>
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}" />
<arg value="uninstall" />
<arg value="${manifest.package}" />
</exec>
<echo>Installing ${out.debug.file} onto default emulator or device...</echo>
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}" />
<arg value="install" />
<arg value="-r" />
<arg path="${out.debug.file}" />
</exec>
<if>
<condition>
<isset property="main-activity" />
</condition>
<then>
<echo>Starting TicketScanner on default emulator or device...</echo>
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}" />
<arg value="shell" />
<arg value="am" />
<arg value="start" />
<arg value="-a" />
<arg value="android.intent.action.MAIN" />
<arg value="-n" />
<arg value="${manifest.package}/${manifest.package}.${main-activity}" />
</exec>
</then>
<else>
<echo>no main activity specified, not starting...</echo>
</else>
</if>
</sequential>
</macrodef>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment