Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run an android app on the device with ant

Tags:

android

ant

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?

like image 451
rogermushroom Avatar asked Jan 26 '12 22:01

rogermushroom


People also ask

What is ANT Android?

The Android ANT SDK enables developers to connect Android apps to ANT devices. It is provided to allow you to connect to proprietary devices and build complex topologies utilising advance ANT features such as background scanning and phone-phone applications.

What is a universal ant test?

The ANT is a task designed to test three attentional networks in children and adults: alerting, orienting, and executive control. Efficiency of the alerting network is examined by changes in reaction time resulting from a warning signal.


2 Answers

Using the command provided by Navin I was able to create this ant target:

<target name="run">
    <exec executable="adb">
        <arg value="shell"/>
        <arg value="am"/>
        <arg value="start"/>
        <arg value="-a"/>
        <arg value="android.intent.action.MAIN"/>
        <arg value="-n"/>
        <arg value="{package.name}/{activity}"/>
    </exec>
</target>

On the command line I execute:

ant debug install run

And it all works swimmingly.

EDIT

As WarrenFaith helpfully pointed out in the comments {activity} should be the class name of main activity with a . prefix.

So a complete example of the value of the last arg would be

org.package.name/.MyCustomActivity
like image 183
rogermushroom Avatar answered Sep 20 '22 18:09

rogermushroom


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>
like image 24
user2266915 Avatar answered Sep 17 '22 18:09

user2266915