简体   繁体   English

Cordova / Ionic build android Gradle 错误:支持的最低 Gradle 版本为 2.14.1。 当前版本是 2.13

[英]Cordova / Ionic build android Gradle error: Minimum supported Gradle version is 2.14.1. Current version is 2.13

This is a solution to the above error that I want to document.这是我要记录的上述错误的解决方案。 I found other similar posts, but none described how this error can be associated with Cordova or Ionic.我发现了其他类似的帖子,但没有人描述此错误如何与 Cordova 或 Ionic 相关联。

If you are not careful, there can be a mismatch between the version of Gradle that Android Studio uses and the version of Gradle that Cordova / cordova-android specifies in its auto-generated application code.如果您不小心,Android Studio 使用的 Gradle 版本可能与 Cordova / cordova-android 在其自动生成的应用程序代码中指定的 Gradle 版本不匹配。 As you know, running众所周知,跑步

$ cordova platform add android

(or $ ionic platform add android , if you are building an Ionic app) creates the native application code at the-project/platforms/android. (或$ ionic platform add android ,如果您正在构建 Ionic 应用程序)在-project/platforms/android 中创建本机应用程序代码。

Inside that folder, the file: /the-project/platforms/android/cordova/lib/builders/GradleBuilder.js exports a variable as shown below:在该文件夹中,文件:/the-project/platforms/android/cordova/lib/builders/GradleBuilder.js 导出一个变量,如下所示:

var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'http\\://services.gradle.org/distributions/gradle-x.y-all.zip';

Where x and y depened on which version of Cordova / cordova-android are being used to build the native application code.其中 x 和 y 取决于使用哪个版本的 Cordova / cordova-android 来构建本机应用程序代码。

When you run当你跑

$ cordova build android

The version of Gradle specified in the distributionUrl var is the version used for the build.distributionUrl var 中指定的 Gradle 版本是用于构建的版本。

Now here comes the tricky part.现在,棘手的部分来了。 When you import the project into Android Studio, you will most likely get a message strongly recommending that you upgrade Gradle to a newer version, as shown below:当您将项目导入 Android Studio 时,您很可能会收到一条强烈建议您将 Gradle 升级到更新版本的消息,如下所示:

在此处输入图像描述 If you do this, Android Studio will download a new version of Gradle and store it locally and configure the project to use the newly download local Gradle distribution, which is the radio option below the selected “Use default grade wrapper”, which I ended up deselecting because this will cause errors.如果这样做,Android Studio 将下载一个新版本的 Gradle 并将其存储在本地,并将项目配置为使用新下载的本地 Gradle 发行版,这是选中的“使用默认等级包装器”下方的单选选项,我结束了取消选择,因为这会导致错误。

在此处输入图像描述

This will cause problems because Android Studio and Cordova will now be attempting to build the application with different versions of Gradle and you will get build errors within Android Studio and also with这将导致问题,因为 Android Studio 和 Cordova 现在将尝试使用不同版本的 Gradle 构建应用程序,您将在 Android Studio 中以及使用

$ cordova build android

in the command line.在命令行中。 The solution with Cordova apps is to always keep the Android Studio project set to "Use default gradle wrapper" and ignore the tempting messages to upgrade. Cordova 应用程序的解决方案是始终将 Android Studio 项目设置为“使用默认 gradle 包装器”,并忽略升级的诱人消息。 If you do want to use a newer version of Gradle, you can always change the distributionUrl var in the file mentioned above (however Cordova strongly discourages modifying code within the platforms folder since it is easily overwritten).如果您确实想使用更新版本的 Gradle,您可以随时更改上述文件中的 distributionUrl var(但是 Cordova 强烈反对修改平台文件夹中的代码,因为它很容易被覆盖)。 At the time of writing this, I cannot tell is there is a way to set the Gradle version at the在撰写本文时,我无法确定是否有办法将 Gradle 版本设置为

$ cordova platform add android

step, which is when you would want to do it so you are never directly modifiying code inside of the-project/platforms步骤,这是您想要这样做的时候,因此您永远不会直接修改项目/平台内的代码

For me, the following commands solved the problem:对我来说,以下命令解决了这个问题:

cordova platform remove android

cordova platform add android

ionic build android

I'd love to just leave this as a comment, but I'm apparently not reputable enough...我很想把它作为评论留下,但我显然不够有名气......

After reading your documentation, I wasn't able to resolve my issue with your suggestion of keeping the Android Studio to "Use default gradle wrapper".阅读您的文档后,我无法通过您建议将 Android Studio 保持为“使用默认 gradle 包装器”来解决我的问题。 What I did find is that setting the session variable CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL before building got me a bit further:我确实发现在构建之前设置会话变量 CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL 让我更进一步:

root@dev:$ export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL="https\://services.gradle.org/distributions/gradle-2.14.1-all.zip"
root@dev:$ cordova build android

The next thing I had to do was edit <project>/platforms/android/build.gradle and <project>/platforms/android/CordovaLib/build.gradle and make sure they both pointed to a valid gradle plugin version.接下来我要做的是编辑<project>/platforms/android/build.gradle<project>/platforms/android/CordovaLib/build.gradle并确保它们都指向一个有效的 gradle 插件版本。

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0'
}

...and in <project>/platforms/android/CordovaLib/build.gradle I added jcenter in the repositories (because maven.org did not seem to have 2.2.0) ...在<project>/platforms/android/CordovaLib/build.gradle我在存储库中添加了 jcenter (因为 maven.org 似乎没有 2.2.0)

repositories {
    mavenCentral();
    jcenter()
}

I was able to build then.那时我能够建造。

Switching back to "Use default gradle wrapper" didn't work for me on my ionic 1 project, but running在我的 ionic 1 项目中切换回“使用默认 gradle 包装器”对我不起作用,但正在运行

ionic platform remove android
ionic platform add android

Worked for me为我工作

you can change the value in platform/android/cordova/lib/builders/GradleBuilder.js您可以更改平台/android/cordova/lib/builders/GradleBuilder.js 中的值

the value you changed, it will be replaced by the lastest gradle zip when you reinstall android platform, so you don't need to worry about change it你改变的值,当你重新安装android平台时它会被最新的gradle zip替换,所以你不用担心改变它

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

or like the others ans或像其他人一样

export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL="https\://services.gradle.org/distributions/gradle-2.14.1-all.zip"

解决问题的另一种方法,也适用于 Windows:

cordova build android --release --CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

I want to extend @bungler answer.我想扩展@bungler 的答案。

I got confused with version of gradle & compatible version of android plugin for gradle.我对 gradle 的版本和 gradle 的 android 插件的兼容版本感到困惑。 Following link has the list of compatibale versions mapping:以下链接包含兼容版本映射列表:

Gradle vs Android plugin for gradle - Compatible version list Gradle vs Android plugin for gradle - 兼容版本列表

For current version of gradle 3.3+ , compatible version of android plugin is 2.3.3对于当前版本的 gradle 3.3+ ,兼容的 android 插件版本是2.3.3

So final settings will look like following:所以最终设置将如下所示:

For Mac对于 Mac

STEP 1: Add following in env variables:第 1 步:在环境变量中添加以下内容:

option a) update env variable:选项 a) 更新环境变量:

export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL="https\://services.gradle.org/distributions/gradle-3.3-all.zip"

or或者

option b ) you can download the gradle file and place it in <project>/platforms/android/gradle/ and update env variable:选项 b )您可以下载 gradle文件并将其放在<project>/platforms/android/gradle/并更新 env 变量:

export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL="../gradle-3.3-all.zip"

STEP 2: Update following in <project>/platforms/android/CordovaLib/build.gradle第 2 步:在<project>/platforms/android/CordovaLib/build.gradle中更新以下内容

buildscript {
  ...
  dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
  }
}

This worked for me.这对我有用。

For follow error:对于跟随错误:

Minimum supported Gradle version is 4.1.支持的最低 Gradle 版本为 4.1。 Current version is 3.3.当前版本是 3.3。 If using t he gradle wrapper, try editing the distributionUrl in E:\ionic\MyIonicProject\gr adle\wrapper\gradle-wrapper.properties to gradle-4.1-all.zip for gradle 4.1如果使用 gradle 包装器,请尝试将 E:\ionic\MyIonicProject\gr adle\wrapper\gradle-wrapper.properties 中的 distributionUrl 编辑为 gradle-4.1-all.zip 用于 gradle 4.1

This command worked for me:这个命令对我有用:

ionic cordova platform update android

In follow up to Chuck Holbrooks answer, with following solution I get an error when trying to add android platform again saying it is already added.在跟进 Chuck Holbrooks 的回答时,通过以下解决方案,我在尝试再次添加 android 平台时遇到错误,说它已经添加。

ionic cordova platform remove android
ionic cordova platform add android

My working Solution:我的工作解决方案:

ionic cordova platform remove android
ionic cordova platform check android
ionic cordova platform add android 

if you run the following it will fix the problem building APKs from the command line如果您运行以下命令,它将解决从命令行构建 APK 的问题

ionic cordova platform remove android
ionic cordova platform add android 

however, after you run/build it in android studio the version mismatch error returns...但是,在 android studio 中运行/构建它后,版本不匹配错误会返回......

instead to fix this, in android studio you should NOT update the project gradle versioning but instead go to file > project structure > SDK location > Gradle settings... and then tell it to use Gradle from a specified location which should be C:/Gradle/gradle-7.4.2 or whatever version you have.为了解决这个问题,在 android studio 中,您不应该更新项目 gradle 版本控制,而是转到文件 > 项目结构 > SDK 位置 > Gradle 设置...,然后告诉它从指定位置使用 Gradle,该位置应该是 C:/ Gradle/gradle-7.4.2 或您拥有的任何版本。

By doing this you will be able to build APKs from the command line using ionic as well as from within android studio.通过这样做,您将能够使用 ionic 从命令行以及在 android studio 中构建 APK。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 支持的最低Gradle版本为2.14.1。 当前版本是2.10 - Minimum supported Gradle version is 2.14.1. Current version is 2.10 java.lang.RuntimeException:支持的最低Gradle版本是3.3。 当前版本是2.14.1 - java.lang.RuntimeException: Minimum supported Gradle version is 3.3. Current version is 2.14.1 Ionic Android最低支持的Gradle版本是4.6。 当前版本是4.1 - Ionic Android Minimum supported Gradle version is 4.6. Current version is 4.1 Android studio-Gradle版本为2.14.1。 当前版本是2.10 - Android studio - Gradle version is 2.14.1 . Current version is 2.10 错误:支持的最低 Gradle 版本为 5.6.4。 当前版本是 5.2.1 - ERROR: Minimum supported Gradle version is 5.6.4. Current version is 5.2.1 Android Studio 错误“支持的最低 Gradle 版本是 7.0.2。当前版本是 6.8。” - Android Studio Error "Minimum supported Gradle version is 7.0.2. Current version is 6.8." 更新 android studio 后出现错误“支持的最低 Gradle 版本为 5.1.1。当前版本为 4.4.1” - Error "Minimum supported Gradle version is 5.1.1. Current version is 4.4.1" after update android studio Gradle 错误:支持的最低 Gradle 版本是 3.3。 当前版本是 3.2 - Gradle error: Minimum supported Gradle version is 3.3. Current version is 3.2 错误:android studio 3.0.1 中支持的最低 gradle 版本为 4.6 - Error : minimum supported gradle version is 4.6 in android studio 3.0.1 Gradle构建错误:org.gradle.buildexceptionreporter Gradle版本使用2.14.1 - Gradle build error: org.gradle.buildexceptionreporter Gradle version used 2.14.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM