java – Android Maven没有启动模拟器

前端之家收集整理的这篇文章主要介绍了java – Android Maven没有启动模拟器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我右键单击我的 Android项目并选择运行 – > Android应用程序.仿真器被启动并且变化确实反映出来.

但是当我执行以下命令时,它不反映.

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

更多,如果没有打开仿真器,则deploy和emulator-start命令将失败.
找到与Android调试桥连接的0个设备.

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

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

解决方法

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

使用adb设备检查连接到您的计算机的活动Android设备.

原文链接:https://www.f2er.com/java/122578.html

猜你在找的Java相关文章