就像我一直在用的

classpath 'com.android.tools.build:gradle:+'

在构建中。gradle文件,我得到了以下错误,因为gradle版本2.10已经发布。 错误是:

警告:需要Gradle 2.10版本。当前版本是2.8。如果 使用gradle包装器,尝试编辑distributionUrl C:\Users\blahblah\myproject\gradle\wrapper\ gradle-wrapper.properties gradle - 2.10 all.zip

起初,它看起来很容易解决的指导,但当我做了改变,我又得到了错误。

我使用Android Studio 2.0,最新的Android SDK Tools 24.4.1和Android SDK Build Tools 23.0.2

我甚至尝试下载Gradle 2.10,并手动将其放在android-studio\ Gradle \文件夹中,但运气不佳。

任何帮助都将不胜感激。


当前回答

对于使用Ionic/Cordova框架的人,我们需要将GradleBuilder.js文件中的distributionUrl更改为var distributionUrl = process。env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'http\\://services.gradle.org/distributions/gradle-2.10-all.zip';

GradleBuilder.js位于project/platforms/android/cordova/lib/builders/GradleBuilder.js

其他回答

在我的案例中,问题确实在gradle-wrapper中的distributionURL中。属性文件和Android Studio自动修复插入

distributionUrl = https://services.gradle.org/distributions/gradle - 4.0 - 20170417000025 + 0000 - all.zip

但这是一个错误的URL。正确的答案是

distributionUrl = https://services.gradle.org/distributions - snapshots/gradle - 4.0 - 20170417000025 + 0000 - all.zip

显然,url在gradle的API中发生了变化,但在Android Studio中没有,所以手动修复它为我解决了问题。

For those who uses ionic, go to [project name]/platforms/android/cordova/lib/builders/GradleBuilder.js on line 164 you will see the following: var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'http\\://services.gradle.org/distributions/gradle-2.13-all.zip';This line is used to create your gradle-wrapper.properties, so any changes to the gradle-wrapper.properties wont matter. All you need to do is change the url to the latest version, sync the gradle and the problem is solved.

只是想在Android studio中更改gradle版本,去文件>设置>项目并更改gradle版本。应用后,它将同步项目,您就可以开始构建了。

您需要更改首选项>构建,执行,部署>构建工具>Gradle >Gradle主路径

或者设置使用默认gradle包装器,编辑项目\gradle\包装器\gradle-wrapper。properties文件字段distributionUrl像这样

- 2.10 - all.zip distributionUrl = https://services.gradle.org/distributions/gradle

如果问题仍然存在,请在构建中添加以下代码。顶层项目的Gradle。

buildscript {
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'

...
}

下载最新的gradle-3.0-all.zip

http://gradle.org/gradle-download/

从完整分发链接下载

打开在android studio文件>设置>gradle

打开该路径,并将下载的zip文件夹gradle-3.0粘贴到该文件夹中

在文件->设置->gradle中将gradle 2.8更改为gradle 3.0

或者您可以在项目中更改gradle包装器

编辑志愿者项目\ \ gradle-wrapper gradle \包装器。将distributionUrl字段编辑到

- 3.0 - all.zip distributionUrl = https://services.gradle.org/distributions/gradle