按提示add后会import net.jcip.annotations.Immutable 这时@Immutable不报错了 但是import androidx.compose.runtime.Immutable依然报错
文档显示Compose Runtime是Compose 编程模型和状态管理的基本组件,以及 Compose 编译器插件的目标核心运行时。
Compose 由 androidx 中的 7 个 Maven 组 ID 构成。每个组都包含一套特定用途的功能,并各有专属的版本说明。
下表介绍了各个组及指向其版本说明的链接。
组 |
说明 |
compose.animation |
在 Jetpack Compose 应用中构建动画,丰富用户的体验。 |
compose.compiler |
借助 Kotlin 编译器插件,转换 @Composable functions(可组合函数)并启用优化功能。 |
compose.foundation |
使用现成可用的构建块编写 Jetpack Compose 应用,还可扩展 Foundation 以构建您自己的设计系统元素。 |
compose.material |
使用现成可用的 Material Design 组件构建 Jetpack Compose UI。这是更高层级的 Compose 入口点,旨在提供与 www.material.io 上描述的组件一致的组件。 |
compose.material3 |
使用 Material Design 3(下一代 Material Design)组件构建 Jetpack Compose 界面。Material 3 包括更新后的主题和组件,以及动态配色等 Material You 个性化功能,旨在与新的 Android 12 视觉风格和系统界面相得益彰。 |
compose.runtime |
Compose 的编程模型和状态管理的基本构建块,以及 Compose 编译器插件针对的核心运行时。 |
compose.ui |
与设备互动所需的 Compose UI 的基本组件,包括布局、绘图和输入。 |
声明依赖项:如需添加Compose的依赖项,要在应用或模块的build.gradle文件中添加所需工件的依赖项(build.gradle有Project和Module)
dependencies {
implementation("androidx.compose.runtime:runtime:1.1.0-rc01")
implementation("androidx.compose.runtime:runtime-livedata:1.1.0-rc01")
implementation("androidx.compose.runtime:runtime-rxjava2:1.1.0-rc01")
}
android {
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.1.0-rc01"
}
kotlinOptions {
jvmTarget = "1.8"
}
}
e: This version (1.1.0-rc01) of the Compose Compiler requires Kotlin version 1.6.0 but you appear to be using Kotlin version 1.6.10 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
e:这个Compose Compiler的版本(1.1.0-rc01)需要Kotlin版本1.6.0,但你似乎使用的是Kotlin版本1.6.10,这是不知道是兼容的。请修复您的配置(或“suppressKotlinVersionCompatibilityCheck”,但不要说我没有警告你!)
失败:构建失败并出现异常。
*哪里出了问题:
task ':app:compileDebugKotlin'执行失败
>编译错误。详细信息请参见日志
1.1.0-rc02兼容Kotlin1.6.10 而1.1.0-rc01兼容Kotlin1.6.0 https://developer.android.com/jetpack/androidx/releases/compose-kotlin?hl=zh-cn
仍然报错 Failed to resolve: androidx.compose.runtime:runtime-livedata:1.1.0-rc02
Add Google Maven repository and sync project
Show in Project Structure dialog
Affected Modules: app
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find androidx.compose.runtime:runtime:1.1.0-rc02.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/androidx/compose/runtime/runtime/1.1.0-rc02/runtime-1.1.0-rc02.pom
- https://repo.maven.apache.org/maven2/androidx/compose/runtime/runtime/1.1.0-rc02/runtime-1.1.0-rc02.pom
- https://jcenter.bintray.com/androidx/compose/runtime/runtime/1.1.0-rc02/runtime-1.1.0-rc02.pom
Required by:
project :app
> Could not find androidx.compose.runtime:runtime-livedata:1.1.0-rc02.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/androidx/compose/runtime/runtime-livedata/1.1.0-rc02/runtime-livedata-1.1.0-rc02.pom
- https://repo.maven.apache.org/maven2/androidx/compose/runtime/runtime-livedata/1.1.0-rc02/runtime-livedata-1.1.0-rc02.pom
- https://jcenter.bintray.com/androidx/compose/runtime/runtime-livedata/1.1.0-rc02/runtime-livedata-1.1.0-rc02.pom
Required by:
project :app
> Could not find androidx.compose.runtime:runtime-rxjava2:1.1.0-rc02.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/androidx/compose/runtime/runtime-rxjava2/1.1.0-rc02/runtime-rxjava2-1.1.0-rc02.pom
- https://repo.maven.apache.org/maven2/androidx/compose/runtime/runtime-rxjava2/1.1.0-rc02/runtime-rxjava2-1.1.0-rc02.pom
- https://jcenter.bintray.com/androidx/compose/runtime/runtime-rxjava2/1.1.0-rc02/runtime-rxjava2-1.1.0-rc02.pom
Required by:
project :app
* 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.
==============================================================================
将build.gradle的dependencies{目录下对应的改成这个 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0
至此 问题解决
遇到一大堆报错打印英文不要怕:找到关键词然后去了解语义即可,怎么说咱也是曾是英语课代表,也过了CET6的(PS:晚上下班后 计算机专业英语词汇 要继续背起来了啊)
注意⚠️:比如好奇官方Demo里的 import com.example.owl.buildsrc.Libs的Libs的用法,搜索Libs看不到啥内容,可以搜索buildsrc找到package com.example.owl.buildsrc对应文件Dependencies.kt(依赖的库都写在这个文件里)在Project的目录buildSrc下而不在Android子目录下