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

问题描述 投票:0回答:2

所以在我的项目中,Gradle 不断将我的 android compose 库(具体来说:'androidx.activity:activity-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

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

configurations.all {
    resolutionStrategy {
        force 'androidx.activity:activity-compose:1.7.2'
    }
}
android gradle
2个回答
4
投票

由于您的依赖性,您的

androidx.activity
版本正在升级:

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

根据 Material 1.10.0-alpha04 发行说明,该版本需要 AndroidX Activity 1.8.0-alpha05 和

compileSdkVersion
为 34。

正如这条推文中所解释的:

随着 Android 14 的 API 34 的最终确定,〜所有新的 Jetpack 库版本都已开始使用 API 34 进行编译。这意味着您的应用程序也需要使用 API 34 进行编译。

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

如果您还想使用 API 34,则需要减少对 Material 的依赖以使用最新的稳定版 - 1.9.0:

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

0
投票

如果你想强制 androidx 保留或降级依赖项,例如使用 1.5.0 版本浏览器、compileSdk 33、targetSdkVersion 33 等,你可以在 build.gradle(:app) 中编写:

dependencies {
    implementation("androidx.browser:browser") {
        version {
            strictly("1.5.0")
        }
    }

..............

}
© www.soinside.com 2019 - 2024. All rights reserved.