Cordova 在 gradle-wrapper.properties 文件中构建更改 distributionUrl [英] Cordova build changes distributionUrl in gradle-wrapper.properties file

查看:42
本文介绍了Cordova 在 gradle-wrapper.properties 文件中构建更改 distributionUrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行时不断收到以下构建异常

 科尔多瓦运行 android --verbose

  • 出了什么问题:评估根项目android"时出现问题.<块引用>

    无法应用插件 [id 'android']需要 Gradle 版本 2.10.当前版本是 2.2.1.如果使用 gradle 包装器,请尝试将 C:UsersProjectgradlewrappergradle-wrapper.properties 中的 distributionUrl 编辑为 gradle-2.10-all.zip

原因是当我运行cordova build 命令时该行被更改;

distributionUrl=http://services.gradle.org/distributions/gradle-2.1.0-all.zip

distributionUrl=http://services.gradle.org/distributions/gradle-2.2.1-all.zip

有什么办法防止这种情况发生?

解决方案

可以猜到,当您发出Cordova build android"命令时,有一个脚本正在后台运行.需要找到此脚本才能查看为 Gradle 版本指定的配置.

你必须去检查以下js文件:

$PROJECT_ROOT/platforms/android/cordova/lib/builders/GradleBuilder.js

然后在文件中找到包含以下变量的行:

GradleBuilder.prototype.prepEnv

并检查distributionUrl变量:

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

这就是您要查找的内容以及需要更改为 gradle-2.10-all.zip 的 URL;

现在您可以运行构建命令了!

灵感来自以下 SO;安装gradle以便在cordova build android中使用

I keep getting the following build exception when I run

 cordova run android --verbose

  • What went wrong: A problem occurred evaluating root project 'android'.

    Failed to apply plugin [id 'android'] Gradle version 2.10 is required. Current version is 2.2.1. If using the gradle wrapper, try editing the distributionUrl in C:UsersProjectgradlewrappergradle-wrapper.properties to gradle-2.10-all.zip

The reason for this is the line being changed when I run the cordova build command from;

distributionUrl=http://services.gradle.org/distributions/gradle-2.1.0-all.zip

to

distributionUrl=http://services.gradle.org/distributions/gradle-2.2.1-all.zip

Any way to prevent this ?

解决方案

As could be guessed, there is a script that is being run behind the scene when you issue the "Cordova build android" command. This script needs to be found in order to see the config specified for Gradle version.

You must go and check the following js file:

$PROJECT_ROOT/platforms/android/cordova/lib/builders/GradleBuilder.js

Then find the line including the following variable in the file:

GradleBuilder.prototype.prepEnv

And check the distributionUrl variable:

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

That's what you are looking for and what you need to change to gradle-2.10-all.zip URL;

Now you can run the build command, and there you go!

inspired from the following SO; install gradle for using in cordova build android

这篇关于Cordova 在 gradle-wrapper.properties 文件中构建更改 distributionUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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