Java – Android Maven does not start the simulator

When I right-click My Android project and select run – > Android application The simulator is started and the changes are actually reflected

But when I execute the following command, it does not reflect

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

More, if the emulator is not opened, the deploy and emulator start commands will fail Found 0 devices connected to 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

This 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"

This 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>

Solution

Before running MVN Android: emulator start, MVN Android: deploy The Maven plug - in cannot be deployed to a non - existent simulator You must also wait for the emulator to start before deployment

Use the ADB device to check for active Android devices connected to your computer

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>