Cordova/Ionic构建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

查看:601
本文介绍了Cordova/Ionic构建android Gradle错误:支持的最低Gradle版本为2.14.1.当前版本是2.13的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要记录的上述错误的解决方案.我发现了其他类似的帖子,但是都没有描述如何将此错误与Cordova或Ionic相关联.

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.

如果您不小心,Android Studio使用的Gradle版本与Cordova/cordova-android在其自动生成的应用程序代码中指定的Gradle版本之间可能会不一致.如您所知,运行

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. As you know, running

$ cordova platform add android

(如果正在构建Ionic应用程序,则为$ ionic platform add android)在-project/platforms/android中创建本机应用程序代码.

(or $ ionic platform add android, if you are building an Ionic app) creates the native application code at the-project/platforms/android.

在该文件夹中,文件:/the-project/platforms/android/cordova/lib/builders/GradleBuilder.js导出变量,如下所示:

Inside that folder, the file: /the-project/platforms/android/cordova/lib/builders/GradleBuilder.js exports a variable as shown below:

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

x和y取决于使用哪个版本的Cordova/cordova-android构建本机应用程序代码.

Where x and y depened on which version of Cordova / cordova-android are being used to build the native application code.

跑步时

$ cordova build android

distributionUrl变量中指定的Gradle版本是用于构建的版本.

The version of Gradle specified in the distributionUrl var is the version used for the build.

现在这是棘手的部分.将项目导入Android Studio时,很可能会收到一条强烈建议您将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并将其存储在本地,并将项目配置为使用新下载的本地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和Cordova现在将尝试使用不同版本的Gradle构建应用程序,并且您将在Android Studio和

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

$ cordova build android

在命令行中输入

. Cordova应用程序的解决方案是始终将Android Studio项目设置为使用默认gradle包装器",而忽略吸引用户升级的消息.如果确实要使用较新版本的Gradle,则可以随时更改上述文件中的distributionUrl var(但是Cordova强烈建议不要在platform文件夹中修改代码,因为它很容易被覆盖).在撰写本文时,我无法确定是否有一种方法可以在

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. 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). At the time of writing this, I cannot tell is there is a way to set the Gradle version at the

$ cordova platform add android

步骤,这是您要执行的操作,因此您永远不会直接在project/platforms内修改代码

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

这篇关于Cordova/Ionic构建android Gradle错误:支持的最低Gradle版本为2.14.1.当前版本是2.13的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆