在 studio 中使用 succ 时无法在命令行中构建 Android 应用程序

问题描述 投票:0回答:1

我有最新的 Android Studio Hedgehog | 2023.1.1 此日期的补丁 2。创建空的活动项目。尝试了 kotlin dsl 和 groovy dsl。 然后就可以用build studio的命令来构建它了。但无法运行任何 gradlew 任务。只有

./gradlew --version
可以工作并打印以下内容:

------------------------------------------------- ----------- 摇篮 8.2

构建时间:2023-06-30 18:02:30 UTC 修订版本:
5f4a070a62a31a17438ac998c2b849f4f6892877

Kotlin:1.8.20 Groovy:3.0.17 Ant:Apache Ant(TM) 2023年1月4日编译的版本1.10.13 JVM:1.8.0_382 (Amazon.com Inc. 25.382-b05)操作系统:Mac OS X 14.3.1 aarch64

gradle-wrapper.properties 我有

distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
。 在 Android studio 设置/构建/构建工具/Gradle 中,我将 Gradle JDK 设置设置为 GRADLE_LOCAL_JAVA_HOME (jbr 17.0.7)。 我读了一些相关的 SO 帖子,但不知道发生了什么。每个 gradlew 调用都会以这个结束:

FAILURE: Build failed with an exception.

* What went wrong:
>A problem occurred configuring root project 'GradleTest2'.

> Could not resolve all files for configuration ':classpath'.

> Could not resolve com.android.tools.build:gradle:8.2.2.

> Required by: project :
> com.android.application:com.android.application.gradle.plugin:8.2.2

> No matching variant of com.android.tools.build:gradle:8.2.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.2' but:
          - Variant 'apiElements' capability com.android.tools.build:gradle:8.2.2 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.2')
          - Variant 'javadocElements' capability com.android.tools.build:gradle:8.2.2 declares a component for use during runtime, 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 version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.2')
          - Variant 'runtimeElements' capability com.android.tools.build:gradle:8.2.2 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
              - 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 '8.2')
          - Variant 'sourcesElements' capability com.android.tools.build:gradle:8.2.2 declares a component for use during runtime, 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 version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.2')

* 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 391ms
mjollneer@IBMPC GradleTest % ./gradlew      

FAILURE: Build failed with an exception.

更新1. 系统 JAVA_HOME 当前设置为

/Users/mjollneer/Library/Java/JavaVirtualMachines/corretto-1.8.0_382/Contents/Home

因为当我。像这样将其设置为 jbr-17

/Applications/Android\ Studio.app/Contents/jbr/Contents/Home

gradlew 调用最终会这样

ERROR: JAVA_HOME is set to an invalid directory

更新2. 最初使用此版本创建的项目:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = '1.8'
}

但是当我将所有 3 个常量更改为 11 或 17 时 - 一切都保持不变(在工作室中正常,在命令行中失败)。

android android-gradle-plugin
1个回答
0
投票

我的问题是 JAVA_HOME 变量。 Mac 的默认设置和 Android Studio 内部设置的一项似乎都不够。 我刚刚从 Oracle 下载了最新版本,检查 JAVA_HOME 是否已更新(在我的情况下为

/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
),仅此而已 =/

© www.soinside.com 2019 - 2024. All rights reserved.