首页 > 解决方案 > Gradle 找不到 Android Compose 编译器

问题描述

我对这个问题感到非常困惑。我的 gradle 文件中有以下几行:

implementation "androidx.compose.runtime:runtime:1.0.0-alpha04"
implementation "androidx.compose.compiler:compiler:1.0.0-alpha04"
implementation "androidx.compose.runtime:runtime-rxjava2:1.0.0-alpha04"

但是,当我构建时,我收到以下错误:

Could not determine the dependencies of task ':app-name-omitted:prepareDebugKotlinCompileTask'.
> Could not resolve all task dependencies for configuration ':app-name-omitted:kotlin-extension'.
   > Could not find androidx.compose:compose-compiler:1.0.0-alpha04.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/androidx/compose/compose-compiler/1.0.0-alpha04/compose-compiler-1.0.0-alpha04.pom
       - https://repo.maven.apache.org/maven2/androidx/compose/compose-compiler/1.0.0-alpha04/compose-compiler-1.0.0-alpha04.pom
       - https://jcenter.bintray.com/androidx/compose/compose-compiler/1.0.0-alpha04/compose-compiler-1.0.0-alpha04.pom
     Required by:
         project :app-name-omitted

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

我对此感到困惑,因为编译器确实存在于 Google 的仓库中:https ://maven.google.com/web/index.html#androidx.compose.compiler:compiler

如有必要,我可以发布更多信息,但我想保持简单。即使compose设置完全错误,为什么它找不到POM文件?

标签: androidandroid-gradle-pluginandroid-jetpack-compose

解决方案


更新 gradle 版本后遇到同样的问题并解决

classpath "com.android.tools.build:gradle:4.2.0-alpha14"

而不是kotlinCompilerExtensionVersion在 composeoptions 中声明编译器版本,而是作为依赖项

implementation "androidx.ui:ui-tooling:$compose_version"
implementation "androidx.compose.runtime:runtime:$compose_version"
implementation "androidx.compose.compiler:compiler:$compose_version"

推荐阅读