【问题标题】:Jetpack compose compiler cannot be resolvedJetpack compose 编译器无法解析
【发布时间】:2021-06-22 08:41:29
【问题描述】:

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

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 版本的可用here

打印 gradle 依赖项我得到了这个:

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

我可以做些什么来解决这个问题,它来自哪里?

【问题讨论】:

    标签: android kotlin gradle android-jetpack-compose


    【解决方案1】:

    在您的主要 build.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
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-30
        • 1970-01-01
        • 2020-12-16
        • 2022-01-22
        • 2021-03-18
        相关资源
        最近更新 更多