【问题标题】:Minimum supported Gradle version is 4.1. Current version is 3.3支持的最低 Gradle 版本为 4.1。当前版本是 3.3
【发布时间】:2018-08-25 12:51:48
【问题描述】:

我正在尝试使用命令构建 android 离子科尔多瓦构建android 但我面临像

这样的错误

支持的最低 Gradle 版本为 4.1。当前版本是 3.3。如果使用吨 他 gradle 包装器,尝试在 D:\BAXA_POS\Development\tr 中编辑 distributionUrl unk\Mobile\baxa_pos\gradle\wrapper\gradle-wrapper.properties 到 gradle-4.1-all.zip

build.gradle 中的代码是

    /*
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
*/

apply plugin: 'com.android.application'

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }

    // Switch the Android Gradle plugin version requirement depending on the
    // installed version of Gradle. This dependency is documented at
    // http://tools.android.com/tech-docs/new-build-system/version-compatibility
    // and https://issues.apache.org/jira/browse/CB-8143
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

    }
}

// Allow plugins to declare Maven dependencies via build-extras.gradle.
allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

//task wrapper(type: Wrapper) {
 //   gradleVersion = '2.14.1'
//}

// Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties.
// Refer to: http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html
ext {
    apply from: 'CordovaLib/cordova.gradle'
    // The value for android.compileSdkVersion.
    if (!project.hasProperty('cdvCompileSdkVersion')) {
        cdvCompileSdkVersion = null;
    }
    // The value for android.buildToolsVersion.
    if (!project.hasProperty('cdvBuildToolsVersion')) {
        cdvBuildToolsVersion = null;
    }
    // Sets the versionCode to the given value.
    if (!project.hasProperty('cdvVersionCode')) {
        cdvVersionCode = null
    }
    // Sets the minSdkVersion to the given value.
    if (!project.hasProperty('cdvMinSdkVersion')) {
        cdvMinSdkVersion = null
    }
    // Whether to build architecture-specific APKs.
    if (!project.hasProperty('cdvBuildMultipleApks')) {
        cdvBuildMultipleApks = null
    }
    // .properties files to use for release signing.
    if (!project.hasProperty('cdvReleaseSigningPropertiesFile')) {
        cdvReleaseSigningPropertiesFile = null
    }
    // .properties files to use for debug signing.
    if (!project.hasProperty('cdvDebugSigningPropertiesFile')) {
        cdvDebugSigningPropertiesFile = null
    }
    // Set by build.js script.
    if (!project.hasProperty('cdvBuildArch')) {
        cdvBuildArch = null
    }

    // Plugin gradle extensions can append to this to have code run at the end.
    cdvPluginPostBuildExtras = []
}

// PLUGIN GRADLE EXTENSIONS START
// PLUGIN GRADLE EXTENSIONS END

def hasBuildExtras = file('build-extras.gradle').exists()
if (hasBuildExtras) {
    apply from: 'build-extras.gradle'
}

// Set property defaults after extension .gradle files.
if (ext.cdvCompileSdkVersion == null) {
    ext.cdvCompileSdkVersion = privateHelpers.getProjectTarget()
}
if (ext.cdvBuildToolsVersion == null) {
    ext.cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
}
if (ext.cdvDebugSigningPropertiesFile == null && file('debug-signing.properties').exists()) {
    ext.cdvDebugSigningPropertiesFile = 'debug-signing.properties'
}
if (ext.cdvReleaseSigningPropertiesFile == null && file('release-signing.properties').exists()) {
    ext.cdvReleaseSigningPropertiesFile = 'release-signing.properties'
}

// Cast to appropriate types.
ext.cdvBuildMultipleApks = cdvBuildMultipleApks == null ? false : cdvBuildMultipleApks.toBoolean();
ext.cdvMinSdkVersion = cdvMinSdkVersion == null ? null : Integer.parseInt('' + cdvMinSdkVersion)
ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)

def computeBuildTargetName(debugBuild) {
    def ret = 'assemble'
    if (cdvBuildMultipleApks && cdvBuildArch) {
        def arch = cdvBuildArch == 'arm' ? 'armv7' : cdvBuildArch
        ret += '' + arch.toUpperCase().charAt(0) + arch.substring(1);
    }
    return ret + (debugBuild ? 'Debug' : 'Release')
}

// Make cdvBuild a task that depends on the debug/arch-sepecific task.
task cdvBuildDebug
cdvBuildDebug.dependsOn {
    return computeBuildTargetName(true)
}

task cdvBuildRelease
cdvBuildRelease.dependsOn {
    return computeBuildTargetName(false)
}

task cdvPrintProps << {
    println('cdvCompileSdkVersion=' + cdvCompileSdkVersion)
    println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
    println('cdvVersionCode=' + cdvVersionCode)
    println('cdvMinSdkVersion=' + cdvMinSdkVersion)
    println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
    println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
    println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
    println('cdvBuildArch=' + cdvBuildArch)
    println('computedVersionCode=' + android.defaultConfig.versionCode)
    android.productFlavors.each { flavor ->
        println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
    }
}

android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }
    }

    defaultConfig {
        versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
        applicationId privateHelpers.extractStringFromManifest("package")

        if (cdvMinSdkVersion != null) {
            minSdkVersion cdvMinSdkVersion
        }
    }

    lintOptions {
      abortOnError false;
    }

    compileSdkVersion cdvCompileSdkVersion
    buildToolsVersion cdvBuildToolsVersion

    if (Boolean.valueOf(cdvBuildMultipleApks)) {
        productFlavors {
            armv7 {
                versionCode defaultConfig.versionCode*10 + 2
                ndk {
                    abiFilters "armeabi-v7a", ""
                }
            }
            x86 {
                versionCode defaultConfig.versionCode*10 + 4
                ndk {
                    abiFilters "x86", ""
                }
            }
            all {
                ndk {
                    abiFilters "all", ""
                }
            }
        }
    }
    /*

    ELSE NOTHING! DON'T MESS WITH THE VERSION CODE IF YOU DON'T HAVE TO!

    else if (!cdvVersionCode) {
      def minSdkVersion = cdvMinSdkVersion ?: privateHelpers.extractIntFromManifest("minSdkVersion")
      // Vary versionCode by the two most common API levels:
      // 14 is ICS, which is the lowest API level for many apps.
      // 20 is Lollipop, which is the lowest API level for the updatable system webview.
      if (minSdkVersion >= 20) {
        defaultConfig.versionCode += 9
      } else if (minSdkVersion >= 14) {
        defaultConfig.versionCode += 8
      }
    }
    */

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }

    if (cdvReleaseSigningPropertiesFile) {
        signingConfigs {
            release {
                // These must be set or Gradle will complain (even if they are overridden).
                keyAlias = ""
                keyPassword = "__unset" // And these must be set to non-empty in order to have the signing step added to the task graph.
                storeFile = null
                storePassword = "__unset"
            }
        }
        buildTypes {
            release {
                signingConfig signingConfigs.release
            }
        }
        addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release)
    }
    if (cdvDebugSigningPropertiesFile) {
        addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    debugCompile(project(path: "CordovaLib", configuration: "debug"))
    releaseCompile(project(path: "CordovaLib", configuration: "release"))
    // SUB-PROJECT DEPENDENCIES END
}

def promptForReleaseKeyPassword() {
    if (!cdvReleaseSigningPropertiesFile) {
        return;
    }
    if ('__unset'.equals(android.signingConfigs.release.storePassword)) {
        android.signingConfigs.release.storePassword = privateHelpers.promptForPassword('Enter key store password: ')
    }
    if ('__unset'.equals(android.signingConfigs.release.keyPassword)) {
        android.signingConfigs.release.keyPassword = privateHelpers.promptForPassword('Enter key password: ');
    }
}

gradle.taskGraph.whenReady { taskGraph ->
    taskGraph.getAllTasks().each() { task ->
        if (task.name == 'validateReleaseSigning' || task.name == 'validateSigningRelease') {
            promptForReleaseKeyPassword()
        }
    }
}

def addSigningProps(propsFilePath, signingConfig) {
    def propsFile = file(propsFilePath)
    def props = new Properties()
    propsFile.withReader { reader ->
        props.load(reader)
    }

    def storeFile = new File(props.get('key.store') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'storeFile'))
    if (!storeFile.isAbsolute()) {
        storeFile = RelativePath.parse(true, storeFile.toString()).getFile(propsFile.getParentFile())
    }
    if (!storeFile.exists()) {
        throw new FileNotFoundException('Keystore file does not exist: ' + storeFile.getAbsolutePath())
    }
    signingConfig.keyAlias = props.get('key.alias') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'keyAlias')
    signingConfig.keyPassword = props.get('keyPassword', props.get('key.alias.password', signingConfig.keyPassword))
    signingConfig.storeFile = storeFile
    signingConfig.storePassword = props.get('storePassword', props.get('key.store.password', signingConfig.storePassword))
    def storeType = props.get('storeType', props.get('key.store.type', ''))
    if (!storeType) {
        def filename = storeFile.getName().toLowerCase();
        if (filename.endsWith('.p12') || filename.endsWith('.pfx')) {
            storeType = 'pkcs12'
        } else {
            storeType = signingConfig.storeType // "jks"
        }
    }
    signingConfig.storeType = storeType
}

for (def func : cdvPluginPostBuildExtras) {
    func()
}

// This can be defined within build-extras.gradle as:
//     ext.postBuildExtras = { ... code here ... }
if (hasProperty('postBuildExtras')) {
    postBuildExtras()
}

gradle-wrapper.properties 的代码

        #DATE
        distributionBase=GRADLE_USER_HOME
        distributionPath=wrapper/dists
        zipStoreBase=GRADLE_USER_HOME
        zipStorePath=wrapper/dists
        distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

我已经尝试了所有方法,例如更改 distributionUrl 和更改默认 gradle 版本,但每次我运行 android build 命令时,distributionUrl 都会将自身更改为旧版本。谁能为此建议我一些东西,这对我来说可以工作。

【问题讨论】:

标签: android maven


【解决方案1】:

在尝试了这么多替代方案后,我得到了解决问题的方法,即

使用ionic的请前往

[project name]/platforms/android/cordova/lib/builders/GradleBuilder.js 

在第 164 行,您将看到以下内容:

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

此行用于创建您的 gradle-wrapper.properties,因此对 gradle-wrapper.properties 的任何更改都无关紧要。只需要把url改成最新版本,同步gradle,问题就解决了。

如果你只是想在Android studio中更改gradle版本,去File&gt;settings&gt;project更改gradle版本。申请后,它会同步项目,您就可以开始构建了。

【讨论】:

  • 最佳解决方案基于您的回复。将环境变量 CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL 设置为所需的 URL,它将起作用。
  • @Andrew - 这对我来说非常适合 Gradle 4.6 和 Ionic。
  • 我同意,设置CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL 应该是公认的答案。
  • @Andrew:我从 CLI 尝试了上述解决方案,但是在构建 android 之后,所有更改都被替换了,你能告诉我问题是什么吗?
【解决方案2】:

我对科尔多瓦也有同样的问题。

您需要在这些文件中将 gradle 版本编辑为最新版本。

platforms/android/app/build.gradle
platforms/android/cordova/lib/builders/GradleBuilder.js
platforms/android/cordova/lib/builders/StudioBuilder.js
platforms/android/build.gradle

在我写这篇文章时,最新版本是 4.10.2。当前版本可以在here找到。

/android/app/build.gradle中找到这部分代码。

task wrapper(type: Wrapper) {
    gradleVersion = '4.10.2'
}

GradleBuilder.js中找到这部分代码。

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

StudioBuilder.js中找到这部分代码。

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

在最后一个文件 /android/build.gradle 中,我们将以下行更改为实际版本。您可以在this side 上找到 Android Gradle 插件的实际版本。

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

感谢哈立德·奥斯曼

【讨论】:

  • 这解决了我的 gradle 链接不断恢复到旧的问题
  • 同时存在 ProjectBuilder.js 文件而不是 GradleBuilder.js 和 StudioBuilder.js。
  • @Juraj Kršák:我尝试了上面的代码,但是在从 cli 构建 android 后,所有更改都被重置了你能告诉我先生是什么问题吗?
【解决方案3】:

在 Linux 中运行以下命令:

gedit ~/.bashrc

将导出放在文件末尾。

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

运行这些命令来加载新变量。

source ~/.bashrc

检查导出 url 中的 gradle 版本是否符合您的要求。

【讨论】:

  • 你拯救了我的一天!
【解决方案4】:

如果您使用的是cordova/phonegap,请转到

platforms/android/app/build.gradle
platforms/android/cordova/lib/builders/GradleBuilder.js
platforms/android/cordova/lib/builders/StudioBuilder.js

并根据错误查找旧的gradle版本,然后用新版本替换。

【讨论】:

    【解决方案5】:

    对于 Ionic 用户:

    在各处(在 js、gradle 文件等中)更改 URL 后,它仍然无法正常工作。

    为了让它发挥作用,我必须这样做:

    ionic cordova rm android
    ionic cordova add android@latest
    

    删除android平台然后重新添加。

    【讨论】:

    • 这应该是:ionic cordova platform rm androidionic cordova platform add android@latest
    【解决方案6】:

    转到项目->android->Wrapper->Gradle->Wrapper->打开 gradle-wrapper.properties 更改您的版本:

    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
    

    改变这一行:

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

    重建您的应用程序

    【讨论】:

    • 先生,我在构建过程中尝试构建 android 更改被删除
    【解决方案7】:

    这是因为下面的代码:

    task wrapper(type: Wrapper) {
        gradleVersion = '2.14.1'
    }
    

    尝试评论它。然后将您的gradle-wrapper.properties 更改为:

    #Tue Jan 30 17:55:46 WIB 2018
    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
    

    【讨论】:

    • 我试过评论这个但同样的问题发生了。
    • 尝试删除项目中的.gradle 目录。
    • 已删除 .gradle ,仍然无法正常工作 .. 每次我尝试使用命令 'ionic cordova build android' 进行构建时,build.gradle 和 gradle-wrapper.properties 文件都会重新加载并更改为较早的属性。
    【解决方案8】:

    如果你是 mac 用户,那么只需按照以下步骤操作

    $ brew install gradle
    

    以上命令安装letest gradle

    然后检查版本

    $ gradle -v
    

    然后更改build.gradle文件的gradle版本。

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

    它对我有用。

    【讨论】:

      【解决方案9】:

      对于 Ionic 4 用户:

      Shilpi 的答案是正确的,只是现在可以在以下位置找到构建 gradle 的路径:

      [project name]/platforms/android/cordova/lib/builders/ProjectBuilder.js 
      

      搜索distributionUrl

      【讨论】:

        【解决方案10】:

        到 Android 工作室,我刚刚清理了 /app/.gradle 中的子文件夹

        之后,gradle 能够构建包装器的正确版本

        【讨论】:

          【解决方案11】:

          使用最新的 gradle 链接更改 gradle-wrapper.properties distributionUrl

          distributionBase=GRADLE_USER_HOME
          distributionPath=wrapper/dists
          zipStoreBase=GRADLE_USER_HOME
          zipStorePath=wrapper/dists
          distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
          

          【讨论】:

            【解决方案12】:

            我在 cordova cli 更新 910 并将 Android Studio 4.0.0 升级到 4.0 之后遇到了这个问题.1.

            我对 Cordova Android 应用没有太多修改,并且使用过

            cordova 平台 rm android

            之后

            cordova 平台添加 android

            这个命令也更新了我的 cordova android 版本。

            较旧 “科尔多瓦机器人”:“^8.1.0” 最新 “cordova-android”:“^9.0.0”

            【讨论】:

              【解决方案13】:

              请检查您的 path 变量是哪个 gradle 版本。

              【讨论】:

                猜你喜欢
                • 2018-05-26
                • 2017-08-21
                • 1970-01-01
                • 2020-09-20
                • 1970-01-01
                • 2020-09-15
                • 1970-01-01
                相关资源
                最近更新 更多