Alex Rivera | Logout

How to run an android app on the device with ant

Asked 2012-01-26T22:09:26.727
19

I would like to be able to launch my app after installation with ant just as happens when pressing the run button in eclipse.

Is there an existing ant task after creating a project on the command line or is there a command I could execute with ant?

Edit
Report

2 Answers

13

Generally, copy following target to your build.xml or custom_rules.xml. Note that in custom_rules.xml (if it doesn't yet exist) you need to wrap this in a element.

<target name="start">
    <xpath input="AndroidManifest.xml"
           expression="/manifest/@package"
           output="manifest.package" />
    <xpath input="AndroidManifest.xml"
           expression="/manifest/application/activity[intent-filter/action/@android:name='android.intent.action.MAIN']/@android:name"
           output="manifest.main" />
    <echo level="info">Restart main activity ${manifest.package}/.${manifest.main}</echo>
    <exec executable="${android.platform.tools.dir}/adb">
        <arg value="shell"/>
        <arg value="am"/>
        <arg value="start"/>
        <arg value="-S"/>
        <arg value="-a"/>
        <arg value="android.intent.action.MAIN"/>
        <arg value="-n"/>
        <arg value="${manifest.package}/.${manifest.main}"/>
    </exec>
</target>
answered 2013-04-10T17:29:57.810
10

executing adb shell am start -a android.intent.action.MAIN -n <Package_name>/.<Activity> from ant should launch your app.ofcourse you need to build and install the app trying to start the app...you can use android build xml to build and use "adb install " to install the app...

answered 2012-01-26T22:33:23.163

Your Answer