Gradle distributionUrl 更改为较旧版本,导致 ‘ionic cordova run android’ 构建失败。

huangapple go评论161阅读模式
英文:

Gradle distributionUrl changes with 'ionic cordova run android' to older version, build failure

问题

I've updated my Gradle distributionUrl to https://services.gradle.org/distributions/gradle-6.1.1-all.zip from gradle-4.1-all.zip, but when I run ionic cordova run android it reverts itself back to the 4.1-all.zip file. This happens around the time where the terminal comes to:

我已将Gradle distributionUrl更新为https://services.gradle.org/distributions/gradle-6.1.1-all.zip,从gradle-4.1-all.zip,但当我运行ionic cordova run android时,它会自行恢复到4.1-all.zip文件。这发生在终端显示如下的时候:

ANDROID_HOME=C:\Users\me\AppData\Local\Android\SDK
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181
studio
Subproject Path: CordovaLib

Subproject Path: app

which then results in

然后导致如下结果:

FAILURE: Build failed with an exception.

*Where:
Build file 'C:\Users\me\Desktop\....\platforms\android\CordovaLib\build.gradle' line 40

* What went wrong:
A problem occurred evaluating project':CordovaLib'.
> Failed to apply plugin [id 'com.android.internal.version-check']
 > Minimum supported Gradle version is 6.1.1. Current version is 4.1...

Line 40 in this case is apply plugin: 'com.android.library'

在这种情况下,第40行是apply plugin: 'com.android.library'

The issue I'm seeing is that the Gradle version is reverting itself back to the previous version. How can I get this to stay at version 6.1.1? Is there something wrong with the com.android.library plugin that I should be fixing?

我遇到的问题是Gradle版本会自行恢复到以前的版本。我该如何使其保持在6.1.1版本?com.android.library插件是否存在问题,我需要进行修复吗?

my gradle dependencies are:

我的Gradle依赖项是:

classpath 'com.andorid.tools.build:gradle:4.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'

my ionic info:

我的 ionic info

cli packages: (C:\Users\bg21562\AppData\Roaming\npm\node_modules)
    @ionic/cli-utils  : 1.19.3
    ionic (Ionic CLI) : 3.20.1
global packages:
    cordova (Cordova CLI) : 9.0.0 (cordova-lib@9.0.1)
local packages:
    @ionic/app-scripts : 3.2.4
    Cordova Platforms  : android 7.1.4
    Ionic Framework    : ionic-angular 3.9.9
System:
    Android SDK Tools : 26.1.1
    Node              : v8.11.3
    npm               : 6.11.3
    OS                : Windows 10
Environment Variables:
    ANDROID_HOME : C:\Users\Bg21562\AppData\Local\Android\SDK
Misc:
    backend : pro
英文:

I've updated my Gradle distributionUrl to https://services.gradle.org/distributions/gradle-6.1.1-all.zip from gradle-4.1-all.zip, but when I run ionic cordova run android it reverts itself back to the 4.1-all.zip file. This happens around the time where the terminal comes to:

ANDROID_HOME=C:\Users\me\AppData\Local\Android\SDK
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181
studio
Subproject Path: CordovaLib

Subproject Path: app

which then results in

FAILURE: Build failed with an exception.

*Where:
Build file 'C:\Users\me\Desktop\....\platforms\android\CordovaLib\build.gradle' line 40

* What went wrong:
A problem occurred evaluating project':CordovaLib'.
> Failed to apply plugin [id 'com.android.internal.version-check']
 > Minimum supported Gradle version is 6.1.1. Current version is 4.1...

Line 40 in this case is apply plugin: 'com.android.library'

The issue I'm seeing is that the Gradle version is reverting itself back to the previous version. How can I get this to stay at version 6.1.1? Is there something wrong with the com.android.library plugin that I should be fixing?

my gradle dependencies are:

classpath 'com.andorid.tools.build:gradle:4.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'

my ionic info:

cli packages: (C:\Users\bg21562\AppData\Roaming\npm\node_modules)
    @ionic/cli-utils  : 1.19.3
    ionic (Ionic CLI) : 3.20.1
global packages:
    cordova (Cordova CLI) : 9.0.0 (cordova-lib@9.0.1)
local packages:
    @ionic/app-scripts : 3.2.4
    Cordova Platforms  : android 7.1.4
    Ionic Framework    : ionic-angular 3.9.9
System:
    Android SDK Tools : 26.1.1
    Node              : v8.11.3
    npm               : 6.11.3
    OS                : Windows 10
Environment Variables:
    ANDROID_HOME : C:\Users\Bg21562\AppData\Local\Android\SDK
Misc:
    backend : pro

答案1

得分: 6

Gradle版本存储在多个位置,正如事实所表明。

为了修复这个问题,我在以下位置找到了distributionUrl作为一个变量:
platforms\android\cordova\lib\builders\StudioBuilder.jsplatforms\android\cordova\lib\builders\GradleBuilder.js

这两个文件都包括以下内容:

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

当然,这需要替换为6.1.1-all.zip

确保还替换gradle-wrapper.properties文件为6.1.1的gradle版本。

我还发现一个选项可以将CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL导出为bash配置文件的变量:
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=http\\://services.gradle.org/distributions/gradle-6.1.1-all.zip

最佳答案可以在这里找到:https://stackoverflow.com/questions/37125496/cordova-build-changes-distributionurl-in-gradle-wrapper-properties-file/37242313

英文:

Gradle versions are located in several locations, as it turns out.

In order to fix this, I found the distributionUrl as a variable in the following locations:
platforms\android\cordova\lib\builders\StudioBuilder.js and platforms\android\cordova\lib\builders\GradleBuilder.js

Both of these files include

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

which of course, needed to be replaced with 6.1.1-all.zip

Make sure to also replace the gradle-wrapper.properties file with the 6.1.1 gradle version.

I also found an option to add an export variable for CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL into the bash profile:
export
CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=http\\://services.gradle.org/distributions/gradle-6.1.1-all.zip

Best answers found here: https://stackoverflow.com/questions/37125496/cordova-build-changes-distributionurl-in-gradle-wrapper-properties-file/37242313

huangapple
  • 本文由 发表于 2020年7月22日 00:56:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/63019361.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定