更新分发Gradle版本到7.6.1时出现错误。

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

While updating distribution gradle version to 7.6.1 getting error

问题

尝试将Gradle分发网址更新为https://services.gradle.org/distributions/gradle-7.6.1-bin.zip时出现以下错误:

FAILURE: 任务执行失败。
* 发生了什么:
任务“:buildSrc:generateExternalPluginSpecBuilders”的执行失败。
> 无法解析配置“:buildSrc:compileClasspath”的所有文件。
   > 无法解析com.android.tools.build:gradle:7.4.2。
     所需的是:
         项目:buildSrc
      > 未找到com.android.tools.build:gradle:7.4.2的匹配变体。配置为查找与Java 8兼容的库的API,最好不打包为jar,最好优化为标准JVM,其依赖项声明为外部声明,并具有值为“7.6.1”的属性“org.gradle.plugin.api-version”,以及值为“jvm”的属性“org.jetbrains.kotlin.platform.type”,但:
          - 变体“apiElements”的能力com.android.tools.build:gradle:7.4.2声明了一个库的API,打包为jar,最好优化为标准JVM,并将其依赖项声明为外部声明,以及具有值“jvm”的属性“org.jetbrains.kotlin.platform.type”:
              - 不兼容,因为此组件声明了与Java 11兼容的组件,而消费者需要与Java 8兼容的组件
              - 其他兼容属性:
                  - 不包含org.gradle.plugin.api-version的信息(需要“7.6.1”)
          - 变体“javadocElements”的能力com.android.tools.build:gradle:7.4.2声明了一个组件的运行时,以及将其依赖项声明为外部声明:
              - 不兼容,因为此组件声明了文档,而消费者需要一个库
              - 其他兼容属性:
                  - 不包含其目标Java环境的信息(最好优化为标准JVM)
                  - 不包含其目标Java版本的信息(需要与Java 8兼容)
                  - 不包含其元素的信息(最好不打包为jar)
                  - 不包含org.gradle.plugin.api-version的信息(需要“7.6.1”)
                  - 不包含org.jetbrains.kotlin.platform.type的信息(需要“jvm”)
          - 变体“runtimeElements”的能力com.android.tools.build:gradle:7.4.2声明了一个库的运行时,打包为jar,最好优化为标准JVM,并将其依赖项声明为外部声明,以及具有值“jvm”的属性“org.jetbrains.kotlin.platform.type”:
              - 不兼容,因为此组件声明了与Java 11兼容的组件,而消费者需要与Java 8兼容的组件
              - 其他兼容属性:
                  - 不包含org.gradle.plugin.api-version的信息(需要“7.6.1”)
          - 变体“sourcesElements”的能力com.android.tools.build:gradle:7.4.2声明了一个组件的运行时,以及将其依赖项声明为外部声明:
              - 不兼容,因为此组件声明了文档,而消费者需要一个库
              - 其他兼容属性:
                  - 不包含其目标Java环境的信息(最好优化为标准JVM)
                  - 不包含其目标Java版本的信息(需要与Java 8兼容)
                  - 不包含其元素的信息(最好不打包为jar)
                  - 不包含org.gradle.plugin.api-version的信息(需要“7.6.1”)
                  - 不包含org.jetbrains.kotlin.platform.type的信息(需要“jvm”)
* 尝试:
> 使用--stacktrace选项运行以获取堆栈跟踪。
> 使用--info或--debug选项运行以获取更多日志输出。
> 使用--scan运行以获取全面的洞察。
* 获取更多帮助:https://help.gradle.org
2s内构建失败
> 任务:buildSrc:generateExternalPluginSpecBuilders 失败
1个可执行任务:1个已执行
*********************************************
            静态分析失败           
请在提交之前修复上述问题
*********************************************

我迄今为止检查的解决方法:

  • 清除Gradle缓存
  • 检查JDK支持的版本(是11)

版本信息:

  • Android Studio版本(Electric Eel | 2022.1.1 Patch 2)
  • Gradle版本(7.4.2)
  • macOS版本(13.1)
  • Git版本(2.37.1)
英文:

When try to update distribution gradle url to

https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip

getting below error

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildSrc:generateExternalPluginSpecBuilders'.
> Could not resolve all files for configuration ':buildSrc:compileClasspath'.
   > Could not resolve com.android.tools.build:gradle:7.4.2.
     Required by:
         project :buildSrc
      > No matching variant of com.android.tools.build:gradle:7.4.2 was found. The consumer was configured to find an API of a library compatible with Java 8, preferably not packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.6.1', attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
          - Variant 'apiElements' capability com.android.tools.build:gradle:7.4.2 declares an API of a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
          - Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them preferably not packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm')
          - Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
          - Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them preferably not packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm')
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
> Task :buildSrc:generateExternalPluginSpecBuilders FAILED
1 actionable task: 1 executed
*********************************************
            Static Analysis Failed           
Please fix the above issues before committing
*********************************************

Things I checked so far to resolve it

  • Cleared the gradle caches
  • Checked JDK supported version (It's 11)

Versions

  • Android studio version (Electric Eel | 2022.1.1 Patch 2)
  • gradle version (7.4.2)
  • Mac version (13.1)
  • git version (2.37.1)

答案1

得分: 8

I had the same error!

Do it:

In the android/build.gradle file, change the dependencies line to "gradle:7.4.2":

dependencies {
        classpath("com.android.tools.build:gradle:7.4.2")
    }

In the android/gradle/wrapper/gradle-wrapper.properties, change the version of gradle:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip

Go to the android directory and run the command:

./gradlew wrapper --gradle-version=7.6.1

Hope this fixes it and helps you.

英文:

I had the same error!

Do it:

In the android/build.gradle file, change the dependencies line to "gradle:7.4.2":

dependencies {
        classpath("com.android.tools.build:gradle:7.4.2")
    }

In the android/gradle/wrapper/gradle-wrapper.properties, change the version of gradle:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip

Go to the android directory and run the command:

./gradlew wrapper --gradle-version=7.6.1

Hope this fixes it and helps you.

答案2

得分: 0

我们都已经在Android Studio中看到了这些基本的配置问题很长时间了。很希望能看到一些改进。

英文:

We've all seen these basic configuraiton issues in Android Studio for a long time. Would be nice to see some improvements there.

答案3

得分: 0

buildscript {
    ext.kotlin_version = '1.6.0'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.0.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

对我来说,解决方案是让AndroidStudio自行确定Gradle类路径,因此在冒号后按Ctrl+Space(自动完成),它将提供可用的有效选项。


<details>
<summary>英文:</summary>

buildscript {
ext.kotlin_version = '1.6.0'
repositories {
google()
jcenter()
}

dependencies {
    classpath &#39;com.android.tools.build:gradle:8.0.2&#39;
                                              ^
    classpath &quot;org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version&quot;
}

}

for me the solution was to let AndroidStudio figure out the gradle class path, so going to the colon: and ctrl+space (autocomplete, and it gives available valid options)

</details>



huangapple
  • 本文由 发表于 2023年3月9日 21:46:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75685456.html
匿名

发表评论

匿名网友

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

确定