开发者问题收集

无法解析 Jetpack Compose 编译器

2021-06-22
783

我尝试将 jetpack compose 添加到现有项目中。 我将 jetpack compose 添加到我的 gradle 文件中:

buildFeatures {
     compose = true
}
compileOptions {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions { jvmTarget = "1.8" }

composeOptions {
    kotlinCompilerExtensionVersion composeVersion
}

//to the dependencies
implementation "androidx.compose.compiler:compiler:$composeVersion"
    // Tooling support (Previews, etc.)
    implementation "androidx.compose.ui:ui-tooling:$composeVersion"
    // Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
    implementation "androidx.compose.foundation:foundation:$composeVersion"
    // Material Design
    implementation "androidx.compose.material:material:$composeVersion"
    implementation "androidx.activity:activity-compose:1.3.0-beta02"
    implementation "androidx.compose.runtime:runtime-livedata:$composeVersion"

当我尝试构建项目时,出现错误:

Execution failed for task ':app:prepareAcceptanceDebugKotlinCompileTask'.
> Could not resolve all files for configuration ':app:kotlin-extension'.
   > Could not resolve androidx.compose:compose-compiler:1.0.0-beta09.
     Required by:
         project :app
      > No cached version of androidx.compose:compose-compiler:1.0.0-beta09 available for offline mode.
      > No cached version of androidx.compose:compose-compiler:1.0.0-beta09 available for offline mode.
      > No cached version of androidx.compose:compose-compiler:1.0.0-beta09 available for offline mode.
      > No cached version of androidx.compose:compose-compiler:1.0.0-beta09 available for offline mode.
      > No cached version of androidx.compose:compose-compiler:1.0.0-beta09 available for offline mode.
      > No cached version of androidx.compose:compose-compiler:1.0.0-beta09 available for offline mode.
      > No cached version of androidx.compose:compose-compiler:1.0.0-beta09 available for offline mode.
      > No cached version of androidx.compose:compose-compiler:1.0.0-beta09 available for offline mode.
      > No cached version of androidx.compose:compose-compiler:1.0.0-beta09 available for offline mode.
      > No cached version of androidx.compose:compose-compiler:1.0.0-beta09 available for offline mode.
      > No cached version of androidx.compose:compose-compiler:1.0.0-beta09 available for offline mode.
      > No cached version of androidx.compose:compose-compiler:1.0.0-beta09 available for offline mode.

Possible solution:
 - Disable offline mode and rerun the build

我检查了一下,没有 androidx.compose:compose-compiler:1.0.0-beta09 这样的东西,只有 此处 提供此版本的 1.0.0-alpha03

打印 gradle 依赖项时,我得到以下信息:

kotlin-extension - Configuration for Compose related kotlin compiler extension
\--- androidx.compose:compose-compiler:1.0.0-beta09 FAILED

我该怎么做才能解决这个问题,它来自哪里?

2个回答

在您的主 bu​​ild.gradle 中设置

dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0-beta04'
        ...
}

并将您的 gradle-wrapper.properties 设置为:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
Hans
2021-06-22

第一步,禁用离线模式。然后你应该删除文件夹 .gradle

例如 C:\Users\youruser(.gradle)

Fahime Zivdar
2021-06-22