提问人:Amirhussein 提问时间:11/17/2023 更新时间:11/18/2023 访问量:26
尝试启动新的 jetpack compose 项目时缺少依赖项或依赖项冲突
Missing or conflicting dependencies when try to start a new jetpack compose project
问:
我想使用 jet pack compose 开始一个新项目。在制作项目时,我收到此错误,并且导入的库中的“compose”一词为红色。似乎android studio无法访问库。MainActivity
这是文件:build.gradle(Moudle:app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.example.myapplication'
compileSdk 33
defaultConfig {
applicationId "com.example.myapplication"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.4.3'
}
packaging {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation 'androidx.activity:activity-compose:1.8.1'
implementation platform('androidx.compose:compose-bom:2023.03.00')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
implementation platform('androidx.compose:compose-bom:2023.03.00')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation platform('androidx.compose:compose-bom:2023.03.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
androidTestImplementation platform('androidx.compose:compose-bom:2023.03.00')
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
}
我注意到某些依赖项中没有版本,所以我添加了android的建议,但仍然有问题。我搜索了很多,但什么也没找到。
我不知道该怎么办。我该如何解决这个问题?
答:
0赞
Code Poet
11/18/2023
#1
你的依赖项中有一行重复的行:它在依赖项中也是重复的。implementation platform('androidx.compose:compose-bom:2023.03.00')
androidTestImplementation
您可以删除它们并尝试更新的 BOM,即 .implementation platform('androidx.compose:compose-bom:2023.10.01')
评论
0赞
Amirhussein
11/20/2023
我做到了,它有效。所有的错误都消失了。但我仍然有这个错误:“无法访问类'androidx.compose.ui.unit.Dp',检查模块类路径中是否缺少或冲突的依赖项”在“表面”和“文本”上
1赞
Code Poet
11/20/2023
kotlinCompilerExtensionVersion '1.4.3'
也过时了。需要更改为 1.5.4。不过,应该与您的错误无关。你清理过项目吗?
0赞
Amirhussein
11/21/2023
非常感谢您抽出时间接受采访。我将android studio更新到最新版本,问题自行解决。
评论