Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Maven not starting emulator

When i right-click my Android Project and Select Run->Android Application. The emulator gets launched and the changes do reflect.

But when i do the following below commands, it does not reflect.

mvn clean install
mvn android:deploy
mvn android:emulator-start

More-Over, The deploy and emulator-start command fails if there is no emulator opened up. Found 0 devices connected with the Android Debug Bridge.

[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:andr
oid-maven-plugin:3.3.0:deploy (default-cli) on project SampleProject: No online de
vices attached. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal c
om.jayway.maven.plugins.android.generation2:android-maven-plugin:3.3.0:deploy (d
efault-cli) on project SampleProject: No online devices attached.
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:217)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBu
ild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
eStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
352)
Caused by: org.apache.maven.plugin.MojoExecutionException: No online devices att
ached.
        at com.jayway.maven.plugins.android.AbstractAndroidMojo.doWithDevices(Ab
stractAndroidMojo.java:625)
        at com.jayway.maven.plugins.android.AbstractAndroidMojo.deployApk(Abstra
ctAndroidMojo.java:527)
        at com.jayway.maven.plugins.android.AbstractAndroidMojo.deployBuiltApk(A
bstractAndroidMojo.java:570)
        at com.jayway.maven.plugins.android.standalonemojos.DeployMojo.execute(D
eployMojo.java:48)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
BuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:209)
        ... 19 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
xception

Here is my android-maven-plugin-emulator-start.vbs file.

Dim oShell
Set oShell = WScript.CreateObject("WScript.shell")
oShell.run "C:\Windows\system32\cmd.exe /X /C START /SEPARATE ""AndroidMavenPlugin-AVDDefault""  D:\SDK\tools\emulator.exe -avd Default"

Here is MY POM.XML

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.sample</groupId>
    <artifactId>SampleProject</artifactId>
    <version>1.0</version>
    <packaging>apk</packaging>
    <name>SampleProject</name>
    <properties>
        <platform.version>2.3.3</platform.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>${platform.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.googlecode.androidannotations</groupId>
            <artifactId>androidannotations</artifactId>
            <version>2.5.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.googlecode.androidannotations</groupId>
            <artifactId>androidannotations</artifactId>
            <classifier>api</classifier>
            <version>2.5.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.3.2</version>
                <configuration>
                    <sdk>
                  <!-- platform or api level (api level 4 = platform 1.6) -->
                  <platform>16</platform>
                  <path>${env.ANDROID_HOME}/</path>
                 </sdk>
                 <emulator>
                    <avd>21</avd>
                    <options>-no-skin</options>
                </emulator>
                    <undeployBeforeDeploy>false</undeployBeforeDeploy>
                </configuration>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
like image 773
theJava Avatar asked Oct 13 '12 15:10

theJava


2 Answers

Run mvn android:emulator-start before mvn android:deploy. The maven plugin cannot deploy to an emulator that does not exist. You must also wait for the emulator to boot up before deploying.

Use adb devices to check the active android devices that are connected to your computer.

like image 120
Deepak Bala Avatar answered Sep 17 '22 13:09

Deepak Bala


You can either launch the emulator manually (like Deepak mentioned in his answer) before running mvn android:deploy, or using the following configuration and run mvn android:deploy directly, it will automatically start emulator and wait for it before doing the deploy:

<plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <version>3.3.2</version>
    <configuration>
        ... ...
        <emulator>
            <avd>21</avd>
            <!-- Wait for emulator starting (3 minutes) -->
            <wait>180000</wait>
            <options>-no-skin</options>
        </emulator>
        ... ...
    </configuration>
    <extensions>true</extensions>
</plugin>
like image 21
yorkw Avatar answered Sep 21 '22 13:09

yorkw