在Android Studio Giraffe 2022.3.1 Patch 2中构建Android项目时发生Gradle版本冲突

nnsrf1az  于 2023-11-18  发布在  Android
关注(0)|答案(1)|浏览(337)

我正在使用Android Studio Giraffe 2022.3.1 Patch 2使用空Activity创建新的Android项目。在Android Studio中构建项目时,一切正常。但是,当我尝试从命令行运行./gradlew wrapper时,我遇到以下错误:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring the root project 'Addfree QR Scanner'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:8.1.2.
     Required by:
         project : > com.android.application:com.android.application.gradle.plugin:8.1.2
      > No matching variant of com.android.tools.build:gradle:8.1.2 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.0'.

   > Could not resolve com.google.gms:google-services:4.4.0.
     Required by:
         project : > com.google.gms.google-services:com.google.gms.google-services.gradle.plugin:4.4.0
      > No matching variant of com.google.gms:google-services:4.4.0 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.0'.

字符串
我的gradle-wrapper-properties文件包含以下内容:

#Mon Nov 06 13:22:09 CET 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists


在我的项目中,我配置了Java 17。
下面是我的build.gradle.kts文件:

plugins {
    id("com.android.application") version "8.1.2" apply false
    id("org.jetbrains.kotlin.android") version "1.9.0" apply false
    id("com.google.gms.google-services") version "4.4.0" apply false
}


我试图了解这个版本8.2.1是从哪里来的,因为它似乎与我的配置冲突。任何关于解决这个问题的见解或指导将不胜感激。
我不明白为什么构建成功,应用在我的手机上运行,但命令“./gradlew wrapper”失败。我需要它工作,因为我试图设置“fastlane”并遇到相同的错误消息。请注意,此问题发生在Android Studio中创建的全新项目中。
谢谢你,谢谢

fiei3ece

fiei3ece1#

我已成功解决此问题。事实证明,仅当在Android Studio中处理构建时,为Gradle配置Java版本才有效。
证据如下:


的数据
但是,当我尝试在命令行中执行./gradlew wrapper命令时,我遇到了原始问题中描述的错误。
为了解决这个问题,我采取了以下步骤:

  1. Java 17安装在Windows机器上
    1.我确保环境变量指向新安装的Java 17,如下所示:



综上所述,这意味着在Android Studio中配置Gradle JDK只会影响通过Android Studio执行的构建。如果您计划在终端中手动运行Gradle命令,则必须在Windows计算机上安装Java 17,并设置正确的环境变量。请注意,可能需要重新启动Windows才能使环境变量中的更改生效。

相关问题