在Android模拟器上运行的Cordova错误:"android:命令失败,退出代码2" [英] Cordova error running on android emulator: "android: Command failed with exit code 2"
问题描述
我正在尝试在Android模拟器中运行Cordova项目:
I'm trying to run my cordova project in an android emulator:
cordova emulate android
构建成功,但仿真器未启动,并且出现错误:
The build is successful but the emulator is not starting and I get an error:
Error: android: Command failed with exit code 2
运行cordova requirements
时我得到的是相同的东西:
I get the same thing when running cordova requirements
:
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: not installed
android: Command failed with exit code 2
Gradle: installed /opt/android-studio/gradle/gradle-3.2/bin/gradle
Error: Some of requirements check failed
我已经将Android SDK工具升级到26.0.1,并且android
命令不再对我有用.因此,我按照发布页面的说明安装了cordova-android@6.2.1
并在我的项目中使用它:
I've upgraded Android SDK Tools to 26.0.1 and android
command doesn't work for me anymore. So I installed cordova-android@6.2.1
as the release page says and use it in my project:
$ cordova platform ls
Installed platforms:
android 6.2.1
Available platforms:
amazon-fireos ~3.6.3 (deprecated)
blackberry10 ~3.8.0
browser ~4.1.0
firefoxos ~3.6.3
ubuntu ~4.3.4
webos ~3.7.0
但是错误仍然发生.有谁知道为什么会这样?
But the error still happens. Does anyone has any ideas why this happens?
推荐答案
我认为Android SDK的新版本与cordova仿真不兼容,因此我对此进行了更改:
I think that a new version of Android SDK is not compatible with cordova emulation, so I change this:
return superspawn.spawn('android', ['list', 'avds'])
对此:
return superspawn.spawn('android', ['list', 'avd'])
内部
platforms/android/cordova/lib/emulator.js
,您的错误已修复.发生这种情况是因为在新的SDK中,命令"android list avds"已更改为"android list avd".感谢 Douglas Neves
and your error was fixed. That happens 'cause the command "android list avds" was changed to "android list avd" inside a new SDK. Thanx to Douglas Neves
如果在那之后您将遇到另一个错误:
If after that you'll catch another error like this:
Failed to install ... Failure [INSTALL_FAILED_VERSION_DOWNGRADE]
您需要对此进行更改:
var command = 'adb -s ' + target + ' install -r "' + apk + '"';
对此:
var command = 'adb uninstall "' + pkgName + '"; adb -s ' + target + ' install -r "' + apk + '"';
在同一文件中.此代码将在安装前卸载应用程序,因此版本问题将消失.
in the same file. This code will uninstall app before install it, so version problem will be disappeared.
这篇关于在Android模拟器上运行的Cordova错误:"android:命令失败,退出代码2"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!