无法在Android上构建和运行基于离子和Cordova的应用程序

时间:2018-09-20 21:24:21

标签: android cordova ionic-framework ionic3 ionic4

我有一个非常基本的Ionic应用程序,我正在尝试在Win 10机器上构建并运行它。但是运行此命令时出现以下错误。由于我对NodeJSAndroid技术很陌生,因此不确定是否缺少其他内容。

# ionic cordova build android
> ionic-app-scripts build --target cordova --platform android
[16:57:21]  ionic-app-scripts 3.2.0
[16:57:21]  build dev started ...
[16:57:21]  clean started ...
[16:57:21]  clean finished in 21 ms
[16:57:21]  copy started ...
[16:57:21]  deeplinks started ...
[16:57:21]  deeplinks finished in 26 ms
[16:57:21]  transpile started ...
[16:57:23]  transpile finished in 2.77 s
[16:57:23]  preprocess started ...
[16:57:23]  preprocess finished in 1 ms
[16:57:23]  webpack started ...
[16:57:24]  copy finished in 2.94 s
[16:57:26]  webpack finished in 2.57 s
[16:57:26]  sass started ...
[16:57:27]  sass finished in 913 ms
[16:57:27]  postprocess started ...
[16:57:27]  postprocess finished in 10 ms
[16:57:27]  lint started ...
[16:57:27]  build dev finished in 6.43 s
[16:57:29]  lint finished in 2.17 s
> cordova build android
Android Studio project detected
ANDROID_HOME=C:\Program Files\Android\Android Studio
JAVA_HOME=C:\Java\jdk
studio
Subproject Path: CordovaLib
Subproject Path: app

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\nital\Documents\Tech\RESET-CODE-SAMPLES\IONIC-CODE-SAMPLES\ionic-basics\platforms\android\CordovaLib\cordova.gradle' line: 68

* What went wrong:
A problem occurred evaluating project ':CordovaLib'.
> No installed build tools found. Install the Android build tools version 19.1.0 or higher.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
(node:15236) UnhandledPromiseRejectionWarning: Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\nital\Documents\Tech\RESET-CODE-SAMPLES\IONIC-CODE-SAMPLES\ionic-basics\platforms\android\CordovaLib\cordova.gradle' line: 68

* What went wrong:
A problem occurred evaluating project ':CordovaLib'.
> No installed build tools found. Install the Android build tools version 19.1.0 or higher.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
    at ChildProcess.whenDone (C:\Users\nital\Documents\Tech\RESET-CODE-SAMPLES\IONIC-CODE-SAMPLES\ionic-basics\platforms\android\cordova\node_modules\cordova-common\src\superspawn.js:169:23)
    at ChildProcess.emit (events.js:182:13)
    at maybeClose (internal/child_process.js:961:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:250:5)
(node:15236) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:15236) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

离子信息

# ionic info
√ Gathering environment info - done!

Ionic:

   ionic (Ionic CLI)  : 4.1.2 (C:\Users\nital\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 7.0.0
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.1.4, (and 4 other plugins)

System:

   NodeJS : v10.9.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.2.0
   OS     : Windows 10

科尔多瓦要求:

# cordova requirements
Android Studio project detected

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: not installed
cmd: Command failed with exit code 1 Error output:
'android' is not recognized as an internal or external command,
operable program or batch file.
Gradle: installed C:\Program Files\Android\Android Studio\gradle\gradle-4.4\bin\gradle
(node:10252) UnhandledPromiseRejectionWarning: CordovaError: Some of requirements check failed
    at C:\Users\nital\AppData\Roaming\npm\node_modules\cordova\src\cli.js:414:27
    at _fulfilled (C:\Users\nital\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:787:54)
    at C:\Users\nital\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:816:30
    at Promise.promise.promiseDispatch (C:\Users\nital\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:749:13)
    at C:\Users\nital\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:557:44
    at flush (C:\Users\nital\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:108:17)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:10252) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:10252) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

环境变量:

JAVA_HOME = C:\Java\jdk
GRADLE_HOME = C:\Program Files\Android\Android Studio\gradle\gradle-4.4
ANDROID_HOME = C:\Program Files\Android\Android Studio
Path =  %JAVA_HOME%\bin; %GRADLE_HOME%\bin; %ANDROID_HOME%\bin;

Java版本信息:

# javac -version
javac 1.8.0_181

# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

我还研究了此在线链接https://cordova.apache.org/docs/en/latest/guide/platforms/android/ 并且在安装Android Studio之后,安装了所有必需的工具和插件(下面的屏幕截图)

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:2)

您的路径中缺少android sdk目录。

如果您查看Cordova需求日志,它会显示'android' is not recognized as an internal or external command

因此,您需要从系统路径中安装了android sdk的任何地方添加toolsplatform-tools

答案 1 :(得分:1)

找到了解决方案。

所以这里有两个问题:

  1. 错误的ANDROID_HOME env变量值。这不应指向您安装android的位置。 AppData是Win中的一个隐藏文件夹,因此您需要找到该文件夹​​,然后指向正确的路径

    ANDROID_HOME = C:\ Users \ nital \ AppData \ Local \ Android \ SDK

  2. 没有将PATH的环境变量指向platform_tools文件夹中的toolsSdk文件夹

    PATH = C:\ Users \ nital \ AppData \ Local \ Android \ Sdk \ platform-tools

    PATH = C:\ Users \ nital \ AppData \ Local \ Android \ Sdk \ tools