尝试使用离子添加android平台时出现错误

时间:2019-06-08 22:37:20

标签: android cordova ionic-framework ionic4

运行命令ionic cordova add platform android时出现以下错误。

我已经完全卸载了Node.js,并从头开始在全球范围内重新安装了Ionic和Cordova,但我不知道为什么会发生此错误。

当我执行命令cordova -v

时也会发生错误
cordova.cmd platform add android --save
C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\node_modules\execa\index.js:347
                throw err;
                ^

Error: Command failed: wmic os get Caption
Description = O servi�o n�o pode ser iniciado porque est� desativado ou n�o tem dispositivos ativados associados.

    at makeError (C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\node_modules\execa\index.js:174:9)
    at Function.module.exports.sync (C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\node_modules\execa\index.js:338:15)
    at windowsRelease (C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\node_modules\windows-release\index.js:34:24)
    at osName (C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\node_modules\os-name\index.js:39:18)
    at new Insight (C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\node_modules\insight\lib\index.js:37:13)
    at Object.<anonymous> (C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\src\telemetry.js:26:15)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
[ERROR] An error occurred while running subprocess cordova.

        cordova.cmd platform add android --save exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

每次运行命令都会发生此错误,我无法添加Android平台。我需要运行ionic cordova run android才能在我在Android Studio中创建的模拟器中打开。

 npm list -g --depth=0
C:\Users\LUIZ\AppData\Roaming\npm
+-- @angular/cli@8.0.2
+-- cordova@9.0.0
`-- ionic@5.0.1

1 个答案:

答案 0 :(得分:0)

我尝试了很多事情,但是我不得不:

Windows-Key (Keyboard)
System Environment Variable 
Environmentsvariables.. 
Select Path Variable and edit
Add the path to your wbem
example: c:\Windows\System32\wbem
Restart cmd
Enjoy