我创建ionic 2项目,并添加诊断cordova插件,如下所示:

ionic plugin add cordova.plugins.diagnostic

npm install --save @ionic-native/diagnostic

并像这样添加android平台:

ionic platform add android@latest

但当构建与ionic构建android控制台给我这个错误:

Error: 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

我尝试下载手动gradle.3.3-all.zip,并在platform/android/cordova/lib/builders/GradleBuilder.js中更改这个distributionUrl变量

 var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-3.3-all.zip'

to:

var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'file:///E:/gradles/gradle-3.3-all.zip';

但不工作和控制台给我最后一个错误。

我不知道如何为android@latest版本添加gradle


当前回答

在Ubuntu 18.04上,我安装了gradle:

sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle

和准备好了。

其他回答

brew install gradle

简而言之,这将节省时间:)Ionic团队请解决这个问题

cordova 6.4.0版本和android 6.2.1版本有问题,请尝试以下兼容版本

Cordova版本必须为6.4.0

Sudo NPM install -g cordova@6.4.0

在你的项目中安装android

Sudo cordova平台加android@6.1.2

 or

Sudo离子平台加android@6.1.2

Windows用户:

Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
scoop install gradle

只需安装android studio并选择您的SDK文件夹作为android studio的SDK默认文件夹,然后android studio修复所有损坏区域并下载所需的文件。

我解决了这个问题

从这个网站https://gradle.org/install下载gradle.zip。并按照网站上的说明进行操作。

然后打开另一个终端cmd并执行命令:

Cordova build android --prod --release
End