Android Maven plugin - How to start an app automatically after deploying it
Asked Answered
S

2

6

I wondering if there's a way to start an application which was deployed using mvn install android:deploy automatically. If this is somehow possible it would speedup development.

Stockyard answered 6/10, 2011 at 10:47 Comment(1)
This post might be relevant, https://mcmap.net/q/1632053/-android-maven-automation/…, and note that as of version 3.0.0-alpha, you can use android:run.Platus
C
3

Here the post: http://www.hrupin.com/2011/06/21/how-to-run-android-application-then-you-use-maven-in-your-project

First you need to add plugin in your POM

<plugin>
    <artifactId>exec-maven-plugin</artifactId>
    <groupId>org.codehaus.mojo</groupId>
    <configuration>
            <executable>${basedir}/scripts/run_app.sh</executable>
    </configuration>
</plugin>

add script in ${basedir}/scripts/ dir with next content:

adb shell am start -a android.intent.action.MAIN -n your.app.package/.YourMainActivity

Command to build and run app

mvn clean install android:deploy; mvn exec:exec

Con answered 6/10, 2011 at 10:51 Comment(2)
fyi - on sonatype.com/books/mvnref-book/reference/… the target android:run is mentioned, I'd assume it does the same as your script. However, it doesn't work for me with a real device connected.Platus
just curious: why do you call mvn twice instead of just appending exec:exec at the end of the first mvn call? does it make a difference?Platus
P
15

Since maven-android-plugin version 3.0.0, you can use:

mvn install android:deploy android:run

and works perfectly.

Plugin's changelog here.

Parve answered 3/10, 2012 at 18:5 Comment(0)
C
3

Here the post: http://www.hrupin.com/2011/06/21/how-to-run-android-application-then-you-use-maven-in-your-project

First you need to add plugin in your POM

<plugin>
    <artifactId>exec-maven-plugin</artifactId>
    <groupId>org.codehaus.mojo</groupId>
    <configuration>
            <executable>${basedir}/scripts/run_app.sh</executable>
    </configuration>
</plugin>

add script in ${basedir}/scripts/ dir with next content:

adb shell am start -a android.intent.action.MAIN -n your.app.package/.YourMainActivity

Command to build and run app

mvn clean install android:deploy; mvn exec:exec

Con answered 6/10, 2011 at 10:51 Comment(2)
fyi - on sonatype.com/books/mvnref-book/reference/… the target android:run is mentioned, I'd assume it does the same as your script. However, it doesn't work for me with a real device connected.Platus
just curious: why do you call mvn twice instead of just appending exec:exec at the end of the first mvn call? does it make a difference?Platus

© 2022 - 2024 — McMap. All rights reserved.