Gradle在我的Android Compose项目中不断提升依赖版本

moiiocjp  于 2023-06-28  发布在  Android
关注(0)|答案(1)|浏览(189)

因此,在我的项目中,Gradle一直在推广我的android compose库(具体来说:'androidx.activity:activity-compose')升级到最新的1.8.0-alpha 05版本。但是,此版本需要运行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

我尝试使用Gradle的解决策略,但似乎不起作用:

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

2vuwiymt1#

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

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

根据Material 1.10.0-alpha04 release notes,该版本需要AndroidX Activity 1.8.0-alpha 05和34的compileSdkVersion
this tweet所述:
随着Android 14的API 34最终确定,所有新的Jetpack库版本都已开始使用API 34编译。这意味着您的应用程序也需要使用API 34进行编译。
所以随着时间的推移,你可能会遇到越来越多的这种情况。
如果你还不想使用API 34,你需要减少对Material的依赖,使用最新的稳定版本-1.9.0:

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

相关问题