无法在 Android 上构建和 运行 基于 ionic 和 cordova 的应用程序
Not able to build and run an ionic and cordova based app on Android
我有一个非常基本的 Ionic
应用程序,我正在尝试构建 运行 在 Win 10
机器上。但是当我 运行 此命令时出现以下错误。不确定是否缺少其他内容,因为我对 NodeJS
和 Android
技术还很陌生。
# 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)
我也在网上查了这个link https://cordova.apache.org/docs/en/latest/guide/platforms/android/
安装后 Android Studio 安装了所有必需的工具和插件(下面的屏幕截图)
您的路径中缺少 android sdk 目录。
如果您查看 Cordova 需求日志,它会显示 'android' is not recognized as an internal or external command
因此,您需要在系统路径中安装 android SDK 的任何地方添加 tools
和 platform-tools
。
找到解决方案。
所以这里有两个问题:
不正确的 ANDROID_HOME
环境变量值。这不应指向您的安装位置 android。 AppData 是 Win 中的隐藏文件夹,因此您需要找到它,然后指向正确的路径
ANDROID_HOME = C:\Users\nital\AppData\Local\Android\Sdk
未将 PATH
环境变量指向位于 Sdk
文件夹
中的 platform_tools
和 tools
文件夹
PATH = C:\Users\nital\AppData\Local\Android\Sdk\platform-tools
路径=C:\Users\nital\AppData\Local\Android\Sdk\tools
我有一个非常基本的 Ionic
应用程序,我正在尝试构建 运行 在 Win 10
机器上。但是当我 运行 此命令时出现以下错误。不确定是否缺少其他内容,因为我对 NodeJS
和 Android
技术还很陌生。
# 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)
我也在网上查了这个link https://cordova.apache.org/docs/en/latest/guide/platforms/android/ 安装后 Android Studio 安装了所有必需的工具和插件(下面的屏幕截图)
您的路径中缺少 android sdk 目录。
如果您查看 Cordova 需求日志,它会显示 'android' is not recognized as an internal or external command
因此,您需要在系统路径中安装 android SDK 的任何地方添加 tools
和 platform-tools
。
找到解决方案。
所以这里有两个问题:
不正确的
ANDROID_HOME
环境变量值。这不应指向您的安装位置 android。 AppData 是 Win 中的隐藏文件夹,因此您需要找到它,然后指向正确的路径ANDROID_HOME = C:\Users\nital\AppData\Local\Android\Sdk
未将
中的PATH
环境变量指向位于Sdk
文件夹platform_tools
和tools
文件夹PATH = C:\Users\nital\AppData\Local\Android\Sdk\platform-tools
路径=C:\Users\nital\AppData\Local\Android\Sdk\tools