Reputation: 5586
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?
Upvotes: 19
Views: 7164
Reputation: 131
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>
Upvotes: 13
Reputation: 117675
<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>
I just want to say that {package.name}
should be equal to <manifest>
's package
and {activity}
should be the full qualified name of the main activity (i.e. with its package name, e.g. com.example.activty.MainActivty).
Upvotes: 0
Reputation: 5586
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
Upvotes: 32
Reputation: 1271
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...
Upvotes: 10