简体   繁体   English

Cordova android模拟器停止工作

[英]Cordova android emulator stopped working

I'm building an app for Android using Cordova. 我正在使用Cordova构建Android应用程序。 The android emulator was working fine but I wasn't using it because I installed the Ripple emulator. Android模拟器工作正常,但我没有使用它,因为我安装了Ripple模拟器。 I continued on building my app, but somewhere the emulator got corrupted. 我继续构建我的应用程序,但某处模拟器已损坏。

When I execute the following: 当我执行以下操作时:

cordova create test
cordova platform add android
cordova build
cordova emulate

Results in the following error: 导致以下错误:

    Error: An error occurred while emulating/deploying the android project.
    events.js:72
            throw er; // Unhandled 'error' event
          ^
    Error: spawn ENOENT
        at errnoException (child_process.js:980:11)
        at Process.ChildProcess._handle.onexit (child_process.js:771:34)
    ]

I have Cordova 3.2 installed and the Android 4.3 API aswell as 4.4. 我安装了Cordova 3.2和Android 4.3 API以及4.4。 I tried to reinstall Cordova with 我试着重新安装Cordova

npm uninstall cordova

And reinstall it again, but it is still producing the same error. 并重新安装它,但它仍然产生相同的错误。 I also reinstalled the Android SDK. 我还重新安装了Android SDK。 This is the log when I run run.bat --emulator: 这是我运行run.bat时的日志--emulator:

[ 'adb devices', null, 'List of devices attached \\r\\n\\r\\n', '' ] exec: android list avds [ 'android list avds', null, 'Available Android Virtual Devices:\\n Name: AVD_for_Nexus_S\\n Path: C:\\\\ Users\\\\Evers\\\\.android\\\\avd\\\\AVD_for_Nexus_S.avd\\n Target: Android 4.4 (API lev el 19)\\n ABI: armeabi-v7a\\n Skin: 480x800\\n', '' ] exec: android list avds [ 'android list avds', null, 'Available Android Virtual Devices:\\n Name: AVD_for_Nexus_S\\n Path: C:\\\\ Users\\\\Evers\\\\.android\\\\avd\\\\AVD_for_Nexus_S.avd\\n Target: Android 4.4 (API lev el 19)\\n ABI: armeabi-v7a\\n Skin: 480x800\\n', '' ] WARNING : no emulator specified, defaulting to AVD_for_Nexus_S Waiting for emulator... exec: adb devices events.js:72 throw er; ['adb devices',null,'附加设备列表\\ r \\ n \\ r \\ n',''] exec:android list avds ['android list avds',null,'可用的Android虚拟设备:\\ n名称: AVD_for_Nexus_S \\ n路径:C:\\\\用户\\\\ Evers \\\\。android \\\\ avd \\\\ AVD_for_Nexus_S.avd \\ n目标:Android 4.4(API lev el 19)\\ n ABI:armeabi-v7a \\ n皮肤:480x800 \\ n',''] exec:android list avds ['android list avds',null,'可用的Android虚拟设备:\\ n名称:AVD_for_Nexus_S \\ n路径:C:\\\\ Users \\\\ Evers \\\\。android \\\\ avd \\\\ AVD_for_Nexus_S.avd \\ n目标:Android 4.4(API级别19)\\ n ABI:armeabi-v7a \\ n外观:480x800 \\ n','']警告:未指定模拟器,默认为AVD_for_Nexus_S等待模拟器.. .exec:adb devices events.js:72 throw er; // Unhandled 'error' event //未处理的'错误'事件

Any clues? 有线索吗?

Just re run after starting emulator manually. 只需在手动启动模拟器后重新运行。

Create Emulator 创建模拟器

  1. type android in cmd and hit enter, a GUI will come. 在cmd中键入android并按Enter键,GUI将会出现。
  2. Under tools section click “manage AVDs” and follow the further instruction to create a new AVD. 在工具部分下,单击“管理AVD”并按照进一步说明创建新的AVD。

Start Emulator 启动模拟器

  1. emulator.exe -avd *avdname* in cmd (wait for few minutes for full start up) cmd中的emulator.exe -avd *avdname* (等待几分钟才能完全启动)
  2. now re run cordova. 现在重新运行cordova。 it will work. 它会工作。

I Have recieved the same error myself, there may be 3 issues : 我自己收到了同样的错误,可能有3个问题:

the emulator uses the apk file generated in the platforms/android/bin folder. 模拟器使用在platforms / android / bin文件夹中生成的apk文件。 sometimes this is missing so make sure to: 有时这是遗漏的,所以一定要:

  1. cd platforms/android cd平台/ android
  2. ant clean 蚂蚁干净
  3. ant debug 蚂蚁调试

Which will create the missing apk file if missing. 如果丢失,将创建丢失的apk文件。

The second issue may have come with adding it to the emulator, which must be run prior: 第二个问题可能是将它添加到模拟器,必须先运行:

How to install an apk on the emulator in Android Studio? 如何在Android Studio中的模拟器上安装apk?

There is also the option to delete and create the android virtual machine using: 还可以选择使用以下命令删除和创建Android虚拟机:

AVD at http://developer.android.com/tools/devices/index.html AVD在http://developer.android.com/tools/devices/index.html

hope this helps, let me know. 希望这有帮助,让我知道。 There is very little documentation about this error. 关于此错误的文档很少。

@Tech Pro @Tech Pro

Cordova 3.2 need Android KITKAT version sdk. Cordova 3.2需要Android KITKAT版本sdk。 So, the problem lies in your Android SDK version. 所以,问题在于你的Android SDK版本。 There are two solutions of this problem. 这个问题有两个解决方案。

Solution:1 : 解决方案:1

Update your Android SDK to latest version or downgrade to Cordova version 3.0 as suggested by @Evers 按照@Evers的建议,将您的Android SDK更新到最新版本或降级到Cordova 3.0版

Solution:2 : If you don't want to either upgrade the Android SDK or downgrade Cordova version then follow the steps here. 解决方案:2 :如果您不想升级Android SDK或降级Cordova版本,请按照此处的步骤操作。

  1. Find the CordovaWebView.java file ({project}\\platforms\\android\\CordovaLib\\src\\org\\apache\\cordova) 找到CordovaWebView.java文件({project} \\ platforms \\ android \\ CordovaLib \\ src \\ org \\ apache \\ cordova)
  2. Go to Line No-296 and update the code as follows "android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KIT_KAT". 转到第296行并更新代码如下“android.os.Build.VERSION.SDK_INT> = android.os.Build.VERSION_CODES.KIT_KAT”。 Change your version code according to your SDK version from this link http://developer.android.com/reference/android/os/Build.VERSION_CODES.html . 根据您的SDK版本从此链接http://developer.android.com/reference/android/os/Build.VERSION_CODES.html更改您的版本代码。 Ex: if you have Android 4.2 then chnage KITKAT into JELLY_BEAN. 例如:如果你有Android 4.2,那么将KITKAT引入JELLY_BEAN。
  3. Comment out line No-299 ie //setWebContentsDebuggingEnabled(true); 注释掉第299行,即// setWebContentsDebuggingEnabled(true);
  4. Now follow the steps given by @snake. 现在按照@snake给出的步骤进行操作。 ie ant clean and ant debug. 即蚂蚁清洁和蚂蚁调试。 I hope it will work 我希望它能奏效

@Tech Pro This error may be caused by the undocumented fact that the virtual machine needs to be launched + unlocked before the emulate command is sent. @Tech Pro此错误可能是由于在发送模拟命令之前需要启动和解锁虚拟机的未记录事实引起的。

Make sure that a virtual machine has been created by Android virtual device manager by the following command: 确保Android虚拟设备管理器通过以下命令创建了虚拟机:

android avd android avd

Make sure the versions are correct with the compatibility for your app :) I'm sorry I got the late reply! 确保版本与您的应用程序兼容性正确:)对不起,我得到了迟到的回复!

I was playing with the Cordova workshop tutorial and ran into a similar issue with the android emulator not starting. 我正在玩Cordova研讨会教程并遇到类似的问题,Android模拟器无法启动。 I checked the above answer but it still didn't work for me. 我检查了上面的答案,但它仍然不适合我。 So here is what I did (I'm using windows 7): 所以这就是我所做的(我使用的是Windows 7):

  1. I started the AVD (Android Virtual device) manager from: 我从以下位置启动了AVD (Android Virtual device)管理器:

    start->programs->Android SDK Tools->AVD Manager. start->programs->Android SDK Tools->AVD Manager。

  2. I noticed the single entry listed for Nexus_5_API_21_X86 had "?" 我注意到为Nexus_5_API_21_X86列出的单个条目有“?” next to Platform and other columns. 在Platform和其他列旁边。 This made me wonder why. 这让我想知道为什么。

  3. I click " Edit " and specify the target platform, and other missing fields. 我单击“ Edit ”并指定目标平台和其他缺少的字段。

  4. Click the "Start" to start the AVD . 单击“开始”以启动AVD After a min, you should also see the android emulator screen display. 一分钟后,你还应该看到android模拟器屏幕显示。

  5. rerun cordova (c:\\Cordova\\workshop>cordova emulate android) 重新运行cordova (c:\\Cordova\\workshop>cordova emulate android)

  6. Voila! 瞧! The command window then displays the compilation progress and finally, you should see the messages below. 然后,命令窗口显示编译进度,最后,您应该看到下面的消息。 After another min, you should be able to find your app on the android emulator. 再过一分钟,你应该能够在Android模拟器上找到你的应用程序。

     BUILD SUCCESSFUL Total time: 1 mins 10.307 secs Built the following apk(s): C:\\Cordova\\workshop\\platforms\\android\\build\\outputs\\apk\\android-debug.apk Installing app on emulator... Using apk: C:\\Cordova\\workshop\\platforms\\android\\build\\outputs\\apk\\android-debug.apk Launching application... LAUNCH SUCCESS 

Hope this helps! 希望这可以帮助!

I finally found a work around. 我终于找到了一个解决方案。 I don't know why Cordova 3.2 isn't able to start the emulator automatically on my system, because it does work on my laptop. 我不知道为什么Cordova 3.2无法在我的系统上自动启动模拟器,因为它可以在我的笔记本电脑上运行。 Downgrading to 3.0 seems to fix the problem: 降级到3.0似乎解决了这个问题:

npm uninstall cordova
npm install -g cordova@3.0.0

My problem was due to the fact that I was running the android sdk manager through a symlink (I had it at usr/local/bin ). 我的问题是由于我通过符号链接运行android sdk管理器(我在usr/local/bin )。 It started working when I put my $ANDROID_HOME/tools in my PATH and removed the symlinks. 当我将$ANDROID_HOME/tools放入PATH并删除符号链接时,它开始工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM