将发行版 gradle 版本更新到 7.6.1 时出现错误

Nik*_*iki 3 gradle android-studio build.gradle

当尝试将发行版 gradle url 更新为

https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
Run Code Online (Sandbox Code Playgroud)

低于错误

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
*********************************************
Run Code Online (Sandbox Code Playgroud)

到目前为止我检查过的事情来解决它

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

版本

  • Android studio版(电鳗|2022.1.1补丁2)
  • 渐变版本(7.4.2)
  • Mac 版本 (13.1)
  • git 版本(2.37.1)

Din*_*ira 12

我有同样的错误!

这样做:

在android/build.gradle文件中,将依赖项行更改为“gradle:7.4.2”:

dependencies {
        classpath("com.android.tools.build:gradle:7.4.2")
    }
Run Code Online (Sandbox Code Playgroud)

在android/gradle/wrapper/gradle-wrapper.properties中,更改 gradle 的版本:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
Run Code Online (Sandbox Code Playgroud)

进入android目录并运行命令:

./gradlew wrapper --gradle-version=7.6.1
Run Code Online (Sandbox Code Playgroud)

希望这可以解决它并对您有所帮助。