我创建了一个基于2021.2.1修补程序1的向导空组合活动的项目,它可以编译,而且运行良好。
在将compose_version从compose_version = '1.1.0-beta01'升级到1.2.1后,我会得到以下运行错误。
Could not resolve all files for configuration ':app:kotlin-extension'.
> Could not find androidx.compose.compiler:compiler:1.2.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/androidx/compose/compiler/compiler/1.2.1/compiler-1.2.1.pom
- https://repo.maven.apache.org/maven2/androidx/compose/compiler/compiler/1.2.1/compiler-1.2.1.pom但是,当我删除kotlinCompilerExtensionVersion compose_version中的build.gradle (模块)时,这个应用程序可以运行良好,为什么?
build.gradle (项目)
buildscript {
ext {
compose_version = '1.1.0-beta01' //I will upgrade it to 1.2.1
}
}
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
}build.gradle (模块)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.myapplication"
minSdk 25
targetSdk 32
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'
}
}
composeOptions {
kotlinCompilerExtensionVersion compose_version //OK after I removed it
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}发布于 2022-09-11 13:44:15
问题是没有Compose Compiler 1.2.1版本。目前,Compose Compiler遵循与其他Compose libraries不同的发布计划。
这里是与Kotlin一起使用的兼容性映射和可用的Compose Compiler版本。
如果您想知道在Compose Compiler和其他Compose libraries之间使用不同的版本,那么这样做是完全没有问题的,而这正是您应该做的才能访问它们的最新版本。
您可以按照以下方式配置您的gradle:
项目模块
buildscript {
ext {
kotlinVer = '1.7.10'
composeCompilerVer = '1.3.1' // should be compatible with kotlin version
composeVer = '1.2.1'
}
}
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version "$kotlinVer" apply false
// ...
}App模块
// ...
android {
// ...
composeOptions {
kotlinCompilerExtensionVersion composeCompilerVer
}
// ...
}
dependencies {
implementation "androidx.compose.ui:ui:$composeVer"
implementation "androidx.compose.ui:ui-tooling-preview:$composeVer"
// ...
}发布于 2022-09-11 16:03:13
版本androidx.compose.compiler:compiler:1.2.1不存在。
您可以在google回购中检查它。
在任何情况下,您都可以在1.2.1中使用模块编译器1.3.0的稳定版本和所有其他组合依赖关系:
buildscript {
ext {
compose_compiler = '1.3.0'
compose_version = '1.2.1'
}
//...
}然后:
composeOptions {
kotlinCompilerExtensionVersion compose_compiler
}
dependencies {
// stable 1.2.1 releases
implementation "androidx.compose.material:material:$compose_version"
//...
}正如在文档中所描述的,编译器1.3.0需要Kotlin1.7.10:
https://stackoverflow.com/questions/73679572
复制相似问题