Android Jetpack Compose项目构建失败:customview-poolingcontainer依赖缺失
解决Jetpack Compose构建时找不到androidx.customview:customview-poolingcontainer:1.0.0的问题
问题原因
这个错误由以下几个因素导致:
- 使用Compose BOM管理版本的同时,手动指定了
material3的alpha版本,破坏了BOM的版本统一管理规则,引发间接依赖版本冲突 - 可能缺失Google Maven仓库配置,导致无法拉取该依赖包
- Gradle插件、Kotlin版本与Compose Compiler版本不匹配,引发依赖兼容问题
解决方案
1. 确认仓库配置正确性
在项目根目录的settings.gradle中,确保已添加Google和MavenCentral仓库:
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } }
2. 统一Compose依赖版本(移除手动指定的material3版本)
Compose BOM会自动管理所有Compose相关依赖的兼容版本,需去掉material3的手动版本号,交由BOM控制:
def composeBom = platform('androidx.compose:compose-bom:2023.01.00') implementation composeBom androidTestImplementation composeBom implementation 'androidx.core:core-ktx:1.9.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' // Compose implementation "androidx.compose.ui:ui" implementation "androidx.compose.material3:material3" // 移除手动版本号 implementation "androidx.compose.ui:ui-tooling-preview" implementation 'androidx.activity:activity-compose' implementation "androidx.constraintlayout:constraintlayout-compose:1.1.0-alpha06" // Compose Compiler and test androidTestImplementation "androidx.compose.ui:ui-test-junit4" debugImplementation "androidx.compose.ui:ui-tooling" debugImplementation "androidx.compose.ui:ui-test-manifest"
3. 匹配Gradle插件、Kotlin与Compose Compiler版本
Compose Compiler 1.3.1要求Kotlin版本为1.7.20,同时建议使用7.4.0及以上版本的Android Gradle插件来保证兼容:
修改项目根目录的build.gradle插件配置:
plugins { id 'com.android.application' version '7.4.2' apply false id 'com.android.library' version '7.4.2' apply false id 'org.jetbrains.kotlin.android' version '1.7.20' apply false }
4. 清理缓存并重新构建
执行以下操作解决缓存导致的依赖拉取异常:
- 在Android Studio中点击
Build > Clean Project - 接着点击
Build > Rebuild Project - 若问题仍存在,手动删除项目根目录下的
.gradle文件夹和app/build文件夹后重新构建
关于之前的问题说明
未使用BOM时手动指定1.3.1版本出现的material3和ComponentActivity无法解析问题,本质是Compose各模块依赖版本不兼容导致的。Compose BOM的核心作用就是统一管理所有Compose相关依赖的兼容版本,避免手动指定版本时的冲突问题。
内容的提问来源于stack exchange,提问作者yaan
相关产品推荐
相关产品推荐

