Ionic Cordova构建android无法正常工作

时间:2017-12-26 08:01:07

标签: android cordova ionic-framework

我安装了离子和cordova。

当我检查我的构建并模拟IOS工作正常但Android无法运行时。

我得到的信息是:

> cordova build android
Android Studio project detected

Running command: /Users/hongzhiyuan/Desktop/nihao_app/app/niHAO/hooks/after_prepare/010_add_platform_class.js /Users/hongzhiyuan/Desktop/nihao_app/app/niHAO

ANDROID_HOME=/Users/hongzhiyuan/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
studio
(node:28943) UnhandledPromiseRejectionWarning: CordovaError: Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle 
in your path, or install Android Studio
    at Object.module.exports.check_gradle (/Users/hongzhiyuan/Desktop/nihao_app/app/niHAO/platforms/android/cordova/lib/check_reqs.js:150:18)
    at StudioBuilder.prepEnv (/Users/hongzhiyuan/Desktop/nihao_app/app/niHAO/platforms/android/cordova/lib/builders/StudioBuilder.js:216:23)
    at Api.module.exports.run (/Users/hongzhiyuan/Desktop/nihao_app/app/niHAO/platforms/android/cordova/lib/build.js:154:20)
    at /Users/hongzhiyuan/Desktop/nihao_app/app/niHAO/platforms/android/cordova/Api.js:342:43
    at _fulfilled (/Users/hongzhiyuan/Desktop/nihao_app/app/niHAO/platforms/android/cordova/node_modules/q/q.js:854:54)
    at self.promiseDispatch.done (/Users/hongzhiyuan/Desktop/nihao_app/app/niHAO/platforms/android/cordova/node_modules/q/q.js:883:30)
    at Promise.promise.promiseDispatch (/Users/hongzhiyuan/Desktop/nihao_app/app/niHAO/platforms/android/cordova/node_modules/q/q.js:816:13)
    at /Users/hongzhiyuan/Desktop/nihao_app/app/niHAO/platforms/android/cordova/node_modules/q/q.js:624:44
    at runSingle (/Users/hongzhiyuan/Desktop/nihao_app/app/niHAO/platforms/android/cordova/node_modules/q/q.js:137:13)
    at flush (/Users/hongzhiyuan/Desktop/nihao_app/app/niHAO/platforms/android/cordova/node_modules/q/q.js:125:13)
(node:28943) 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:28943) [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.

rm android平台并重新安装它但仍然遇到了同样的问题。知道如何使其有效吗?

2 个答案:

答案 0 :(得分:1)

you can follow this steps:--

Open Terminal.app.
Create a new directory sudo mkdir /usr/local/gradle.
Extract the downloaded Gradle distribution archive by executing sudo unzip gradle-4.0.2-all.zip -d /usr/local/gradle.
Edit .bash_profile in your home directory to add GRADLE_HOME variable with the following line export GRADLE_HOME=/usr/local/gradle/gradle-4.0.2
Also update the PATH variable to include $GRADLE_HOME/bin. If you don’t already have the PATH variable add the following line export PATH=$GRADLE_HOME/bin:$PATH
Run source ~/.bash_profile to executes the update version of .bash_profile. Or you can open a new Terminal.app to make this changes active.

或点击此链接https://kodejava.org/how-do-i-install-gradle-in-os-x/

答案 1 :(得分:0)

我发现了问题。我又做了brew install gradle,但这次我打开了我的vpn。由于我位于中国,一些代码无法在没有vpn的情况下下载现在它正在运行