我创建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


当前回答

尝试安装gradle并将其包含到您的路径中。点击下面的链接获取手册。 https://gradle.org/install

其他回答

在linux上安装gradle,即使安装了Android Studio,

Sudo apt安装gradle

尝试安装gradle并将其包含到您的路径中。点击下面的链接获取手册。 https://gradle.org/install

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

在Ubuntu中,安装最新版本的gradle为我解决了这个问题。

尝试以下步骤安装最新版本,

sudo add-apt-repository ppa:cwchien/gradle

sudo apt-get update

sudo apt-get install gradle

然后使用,

Cordova build android或ionic Cordova build android

注意:如果你从ubuntu repo安装gradle,它会安装旧版本1.4,不会有帮助,所以sudo apt-get安装gradle在大多数情况下不会有帮助,如果你之前没有添加repo ppa:cwchien/gradle

对于Windows,您可以尝试下面的解决方案

复制gradle——>bin路径并将其添加到系统环境变量路径。

在我的情况下gradle路径是

C:\Users\username\.gradle\wrapper\dists\gradle-3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9\gradle-3.3\bin

这个解决方案对我很有效。