一尘不染

Android Maven无法启动模拟器

java

当我右键单击我的Android项目并选择时Run->Android Application。模拟器启动,所做的更改确实反映出来。

但是当我执行以下以下命令时,它不会反映出来。

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

而且,如果没有打开模拟器,则deploy and emulator-start命令将失败。 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

这是我的android-maven-plugin-emulator-start.vbs文件。

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"

这是我的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>

阅读 154

收藏
2020-12-03

共1个答案

一尘不染

mvn android:emulator-start之前mvn android:deploy。Maven插件无法部署到不存在的仿真器。在部署之前,您还必须等待模拟器启动。

使用adb devices检查连接到您的电脑的Android活跃设备。

2020-12-03