android - 如何更新项目中的 Jetpack Compose 版本?

标签 android kotlin android-jetpack-compose

我想将依赖项更新到最新版本的 Jetpack Compose。我尝试更改 gradle 文件中的版本文本,但生成错误。我也找不到 Jetpack Compose 的最新版本。

build.gradle(项目)

buildscript {
    ext {
        compose_version = '1.2.0'
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.1' apply false
    id 'com.android.library' version '7.4.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}

build.gradle(模块:应用程序)

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.example.android'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.android"
        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.2.0'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.1'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.compose.material3:material3:1.0.0-alpha11'
    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"
}

我在互联网上尝试和搜索了两天,但总是构建错误。我对这项工作非常菜鸟,所以它不起作用。

最佳答案

Jetpack compose 已改用 Material list (BOM) 来组合兼容的库版本。 查看documentation :

dependencies {
    // Import the Compose BOM
    implementation platform('androidx.compose:compose-bom:2023.01.00')

    // Import other Compose libraries without version numbers
    implementation 'androidx.compose.foundation:foundation'
}

您可以找到最新的BOM版本here .

如果您仍然遇到构建错误,那么您很可能需要更新您的 kotlin 插件版本。

关于android - 如何更新项目中的 Jetpack Compose 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75493950/

相关文章:

android - Jetpack Compose LazyColumn 文本消失

java - 如何在适当的时间通过两个项目之间的随机位置平滑滚动回收器 View

android - 如何以非编程方式在 Android 上配置代理排除列表?

oop - Kotlin 中空类的目的是什么?

android - OnTouchListerner 不应将打开 DrawerLayout 的滑动解释为长按

android - 使用 Coil 和 Jetpack Compose 有条件地显示图库或可绘制资源中的图像

android - 更改广告可见性后 ScrollView 自动滚动

android activitygroup 和 listactivity

android - 对返回 when 语句感到困惑

android - 禁用TextField中标签的向上移动动画(Jetpack compose)