我正在尝试使用离子框架为Android构建apk,但无法构建apk。 我已经安装了Android Studio 3.1.3,并在ionic项目中添加了平台。
ionic cordova add platform android
ionic cordova build android --release
离子信息:
cli packages: (/usr/local/lib/node_modules)
@ionic/cli-utils : 1.19.2
ionic (Ionic CLI) : 3.20.0
global packages:
cordova (Cordova CLI) : 8.0.0
local packages:
@ionic/app-scripts : 3.1.9
Cordova Platforms : android 7.0.0
Ionic Framework : ionic-angular 3.9.2
System:
Android SDK Tools : 26.1.1
Node : v8.11.1
npm : 5.6.0
OS : macOS High Sierra
Xcode : Xcode 7.2.1 Build version 7C1002
Environment Variables:
ANDROID_HOME : /Users/prakash/Documents/adt-bundle-mac-x86_64-20140321/sdk
Misc:
backend : pro
错误消息:
ANDROID_HOME=/Users/prakash/Documents/adt-bundle-mac-x86_64-20140321/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home
studio
(node:1272) 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/prakash/IONIC/NABH/platforms/android/cordova/lib/check_reqs.js:150:18)
at StudioBuilder.prepEnv (/Users/prakash/IONIC/NABH/platforms/android/cordova/lib/builders/StudioBuilder.js:216:23)
at Api.module.exports.run (/Users/prakash/IONIC/NABH/platforms/android/cordova/lib/build.js:154:20)
at /Users/prakash/IONIC/NABH/platforms/android/cordova/Api.js:342:43
at _fulfilled (/Users/prakash/IONIC/NABH/platforms/android/cordova/node_modules/q/q.js:854:54)
at self.promiseDispatch.done (/Users/prakash/IONIC/NABH/platforms/android/cordova/node_modules/q/q.js:883:30)
at Promise.promise.promiseDispatch (/Users/prakash/IONIC/NABH/platforms/android/cordova/node_modules/q/q.js:816:13)
at /Users/prakash/IONIC/NABH/platforms/android/cordova/node_modules/q/q.js:624:44
at runSingle (/Users/prakash/IONIC/NABH/platforms/android/cordova/node_modules/q/q.js:137:13)
at flush (/Users/prakash/IONIC/NABH/platforms/android/cordova/node_modules/q/q.js:125:13)
(node:1272) 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:1272) [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.
最终安装了gradle-4.1文件,并将其解压缩到以下路径,
/Users/prakash/gradle-4.1
但仍然收到上述消息。请帮助我摆脱这种困扰。 谢谢。
答案 0 :(得分:3)
最终我得到了自己的问题的解决方案。
如果您已经安装了Android Studio,并将环境变量设置为类似
,ANDROID_HOME : /Users/prakash/Documents/adt-bundle-mac-x86_64-20140321/sdk
然后,您需要下载gradle并将其包含在您的路径中。点击下面的链接获取手册。 https://gradle.org/install
下载完成后,请执行以下步骤:
步骤1:转到您的SDK路径。这是我的路径/ Users / prakash / Documents / adt-bundle-mac-x86_64-20140321 / sdk / tools
第2步:创建一个名为“ gradle”的新文件夹并将其打开。
步骤3:在此处将gradle文件夹解压缩,该文件夹先前已下载。
步骤4:现在打开终端并运行您的离子项目。
答案 1 :(得分:1)
对我有用的是将gradle文件夹内的bin文件夹设置为PATH环境变量。因此,除了上面@ pb123列出的所有步骤之外,我还必须设置PATH环境变量以包含gradle bin路径。使用他帖子中的示例:
export PATH = $ {PATH}:$ ANDROID_HOME / tools / gradle / bin
您可以在〜/ .bash_profile中进行设置,这样它就可以跨会话使用。
答案 2 :(得分:0)
对于Linux: 包括下载的Gradle路径
获取您的android sdk路径...在底部的.bashrc中找到它:ANDROID_HOME = $ HOME / Android / Sdk
$ mkdir $ HOME / Android / Sdk / gradle
在此处解压缩gradle文件夹(之前已下载)。
如果Gradle由SDKMAN下载,它将保存在$ HOME / .sdkman / archives
$解压缩$ HOME / .sdkman / archives / *。zip -d $ HOME / Android / Sdk / gradle
在.bashrc中设置路径: 对我而言,SDK路径为:
$ ANDROID_HOME == $ HOME / Android / Sdk
所以你需要做...
export PATH = $ {PATH}:$ ANDROID_HOME / gradle / gradle-5.1.1 / bin
$ source1
$ cordova build
答案 3 :(得分:0)
如何在Mac中安装gradle
- 在Mac中打开终端
- 检查是否安装了brew,如果已安装,则写出brew,然后写入
brew install gradle
- 如果未安装,请安装它,并将其写在终端下面的行中
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 现在将安装gradle
- 现在可能会报错
/Users/Desktop/project-name/platforms/android/gradlew: Command failed with exit code EACCES
- 下一步将是
sudo chmod 777 /Applications/Android\ Studio.app/Contents/gradle/gradle-4.10.1/bin/
sudo chmod 777 /Users/xyz/Desktop/project-name/platforms/android/gradlew
快乐的环境!!你好!!这将起作用。
答案 4 :(得分:0)
我正在使用Linux Fedora 30,而我的解决方案是这样。
下载后,我将文件解压缩到sdk / tools路径中的文件是/ home / JCODE07 / Android / sdk / tools / gradle
最后一步打开.bashrc,并将Gradle的路径添加到我的PATH VARIABLE中。
export PATH = $ PATH:“ / home / JCODE07 / Android / sdk / platform-tools”:“ / home / JCODE07 / Android / sdk / tools”:“ / home / JCODE07 / Android / sdk / tools / gradle / bin“
我希望这对您有用:)