Updated the hooks directory to have execute permissions
running cordova build android
Running command: "C:\Program Files\nodejs\node.exe" F:\ionic\myApp\hooks\after_prepare
Updated the hooks directory to have execute permissions
running cordova build android
Running command: "C:\Program Files\nodejs\node.exe" F:\ionic\myApp\hooks\after_prepare\010_add_platform_class.js F:\ionic\myApp
add to body class: platform-android
Running command: F:\ionic\myApp\platforms\android\cordova\build.bat
ERROR building one of the platforms: Error: F:\ionic\myApp\platforms\android\cordova\build.bat: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: F:\ionic\myApp\platforms\android\cordova\build.bat: Command failed with exit code 2
at ChildProcess.whenDone (C:\Users\svkaushik17\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:766:16)
at Process.ChildProcess._handle.onexit (child_process.js:833:5)
Please let me know if there is any dependencies I've to install to build the application.
如果我要安装任何依赖项来构建应用程序,请告诉我。
I've the Ionic website to build the app.
我有Ionic网站来构建应用程序。
$ ionic platform add android
$ ionic build android
I also have installed the AVD Manager.
我也安装了AVD Manager。
2 个解决方案
#1
You have missed this part of dependencies during the setup (Java Ant & Android on Windows).
您在安装过程中错过了这部分依赖项(Windows上的Java Ant和Android)。
It is available here: https://ionicframework.com/docs/guide/installation.html
它可以在这里找到:https://ionicframework.com/docs/guide/installation.html
Windows users developing for Android: You'll want to make sure you have the following installed and set up.
为Android开发的Windows用户:您需要确保安装并设置了以下内容。
NOTE: Whenever you make changes to the PATH, or any other environment variable, you'll need to restart or open a new tab in your shell program for the PATH change to take effect.
注意:每当您对PATH或任何其他环境变量进行更改时,您都需要重新启动或打开shell程序中的新选项卡,以使PATH更改生效。
Java JDK
Install the most recent Java JDK (NOT just the JRE).
安装最新的Java JDK(不仅仅是JRE)。
Next, create an environment variable for JAVA_HOME pointing to the root folder where the Java JDK was installed. So, if you installed the JDK into C:\Program Files\Java\jdk7, set JAVA_HOME to be this path. After that, add the JDK's bin directory to the PATH variable as well. Following the previous assumption, this should be either %JAVA_HOME%\bin or the full path C:\Program Files\Java\jdk7\bin
接下来,为JAVA_HOME创建一个环境变量,指向安装Java JDK的根文件夹。因此,如果将JDK安装到C:\ Program Files \ Java \ jdk7中,请将JAVA_HOME设置为此路径。之后,将JDK的bin目录添加到PATH变量中。按照前面的假设,这应该是%JAVA_HOME%\ bin或完整路径C:\ Program Files \ Java \ jdk7 \ bin
Apache Ant
To install Ant, download a zip from here, extract it, move the first folder in the zip to a safe place, and update your PATH to include the bin folder in that folder. For example, if you moved the Ant folder to c:/, you'd want to add this to your PATH: C:\apache-ant-1.9.2\bin.
要安装Ant,请从此处下载zip文件,将其解压缩,将zip中的第一个文件夹移动到安全位置,然后更新PATH以将bin文件夹包含在该文件夹中。例如,如果将Ant文件夹移动到c:/,则需要将其添加到PATH:C:\ apache-ant-1.9.2 \ bin。
Android SDK
Installing the Android SDK is also necessary. The Android SDK provides you the API libraries and developer tools necessary to build, test, and debug apps for Android.
安装Android SDK也是必要的。 Android SDK为您提供构建,测试和调试Android应用程序所需的API库和开发人员工具。
Cordova requires the ANDROID_HOME environment variable to be set. This should point to the [ANDROID_SDK_DIR]\android-sdk directory (for example c:\android\android-sdk).
Cordova需要设置ANDROID_HOME环境变量。这应该指向[ANDROID_SDK_DIR] \ android-sdk目录(例如c:\ android \ android-sdk)。
Next, update your PATH to include the tools/ and platform-tools/ folder in that folder. So, using ANDROID_HOME, you would add both %ANDROID_HOME%\tools and %ANDROID_HOME%\platform-tools.
接下来,更新PATH以包含该文件夹中的tools /和platform-tools /文件夹。因此,使用ANDROID_HOME,您将添加%ANDROID_HOME%\ tools和%ANDROID_HOME%\ platform-tools。
#2
Make sure there isn't 2 versions of JDK installed. If you have 2 versions installed, try pointing your JAVA_HOME to the C:\Program Files\ version that seemed to resolve the issue. Also, cordova is checking for javac not just java -version, so try javac from command line and check if it works.
确保没有安装2个JDK版本。如果您安装了2个版本,请尝试将JAVA_HOME指向可能解决该问题的C:\ Program Files \版本。此外,cordova正在检查javac而不仅仅是java -version,所以从命令行尝试javac并检查它是否有效。
0_add_platform_class.js F:\ionic\myApp
add to body class: platform-android
Running command: F:\ionic\myApp\platforms\android\cordova\build.bat
ERROR building one of the platforms: Error: F:\ionic\myApp\platforms\android\cordova\build.bat: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: F:\ionic\myApp\platforms\android\cordova\build.bat: Command failed with exit code 2
at ChildProcess.whenDone (C:\Users\svkaushik17\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:766:16)
at Process.ChildProcess._handle.onexit (child_process.js:833:5)
Updated the hooks directory to have execute per