因此,在我的项目中,Gradle不断地将我的Android作曲库(具体地说:‘androidx.active:active-compose’)推广到最新的1.8.0-alpha05版本.然而,这个版本需要compileSdk 34才能运行,而Gradle版本8.0.2似乎不支持它.

我的应用程序是build.gradle:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id("com.google.dagger.hilt.android")
    id("com.google.devtools.ksp")
    id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.20'
    id 'com.google.gms.google-services'
}

android {
    namespace 'com.my_app'
    compileSdk 33

    defaultConfig {
        applicationId "com.my_app"
        minSdk 21
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.debug
        }
    }

    applicationVariants.all { variant ->
        variant.addJavaSourceFoldersToModel(
                new File(buildDir, "generated/ksp/${variant.name}/kotlin")
        )
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_18
        targetCompatibility JavaVersion.VERSION_18
    }
    kotlinOptions {
        jvmTarget = '18'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.4.6'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {
    def exoPlayerVersion = "1.0.2"
    def room_version = "2.5.1"

    def composeBom = platform('androidx.compose:compose-bom:2023.05.01')
    implementation composeBom
    androidTestImplementation composeBom

    implementation 'androidx.core:core-ktx:1.10.1'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
    implementation("androidx.lifecycle:lifecycle-runtime-compose:2.6.1")
    implementation 'androidx.activity:activity-compose:1.7.2' // <-- the culprit
    implementation "androidx.compose.animation:animation-graphics"
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-graphics'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'androidx.compose.material3:material3'
    implementation 'androidx.compose.foundation:foundation'
    implementation 'com.google.android.material:material:1.10.0-alpha04'
    implementation('org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1')

    // ... Other dependencies
}

投掷./gradlew checkDebugAarMetadata次:

> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > 3 issues were found when checking AAR metadata:

       1.  Dependency 'androidx.activity:activity-compose:1.8.0-alpha05' requires libraries and applications that
           depend on it to compile against version 34 or later of the
           Android APIs.

           :app is currently compiled against android-33.

           Also, the maximum recommended compile SDK version for Android Gradle
           plugin 8.0.2 is 33. // <-- this

       2.  Dependency 'androidx.activity:activity-ktx:1.8.0-alpha05' requires libraries and applications that
           depend on it to compile against version 34 or later of the
           Android APIs.

           // same comment above

       3.  Dependency 'androidx.activity:activity:1.8.0-alpha05' requires libraries and applications that
           depend on it to compile against version 34 or later of the
           Android APIs.

           // same comment above

我try 使用Gradle的解析策略,但似乎不起作用:

configurations.all {
    resolutionStrategy {
        force 'androidx.activity:activity-compose:1.7.2'
    }
}

推荐答案

由于您的依赖关系,您的androidx.activity版本正在升级:

implementation 'com.google.android.material:material:1.10.0-alpha04'

根据Material 1.10.0-alpha04 release notes,那个版本requires的androidX活动1.8.0-alpha05,compileSdkVersion的34.

如第this tweet节所述:

随着安卓14‘S API34的定稿,~所有新的Jetpack库版本都已经开始使用API34编译.这意味着您的应用程序还需要使用API 34进行编译.

因此,随着时间的推移,你可能会越来越多地遇到这种情况.

如果你还想not次使用API 34,你需要减少对material 的依赖来使用最新的1.9.0版本:

implementation 'com.google.android.material:material:1.9.0'

Android相关问答推荐

编写视觉转型

在Android Studio中陷入了不兼容的Gradle版本的循环

如何使用视图模型触发可变状态?

滚动屏幕时更改按钮外观

我如何剪裁一个可由另一个合成的

如何在Android Jetpack Compose中找到我的手机屏幕一行有多少个单词

LocalContext.current的问题(@Composable调用只能从@Composable函数的上下文发生)

从片段导航回来

如何在Jetpack Compose中向SearchBar添加边框

如何在卡片视图右侧添加箭头

页面标题未显示在内容页面上

如何在没有人窃取令牌的情况下使用我的移动应用程序中的 API

为什么集成React Native时compileSdkVersion错误?

如何放置在柱子的角落(底端)

使用默认使用 RTL 语言的项目本地化 android 应用程序

java.lang.IllegalArgumentException:与请求匹配的导航目的地 NavDeepLinkRequest

在 Room 中创建一对多关系时,@Relation 类是什么意思?

如何使用jetpack compose实现布局,其中图标在列布局上是绝对位置

更新应用程序是否会取消对应用程序特定文件的权限?

在 compose 屏幕之间传递 uri 会导致:SecurityException: Permission Denial