Android 老项目适配 Compose 混合开发

时间:2024-11-15 14:48:00

app 模块下的 build.gradle 添加:

   buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.4.3"
    }

引用入 compose 组件库:

val compose_version = "1.6.2"
implementation("androidx.compose.ui:ui:$compose_version")
implementation("androidx.compose.material:material:$compose_version")
implementation("androidx.compose.ui:ui-tooling-preview:$compose_version")
debugImplementation("androidx.compose.ui:ui-tooling:$compose_version")
implementation ("androidx.activity:activity-compose:$compose_version")

对于compose的版本管理,官方推荐使用BOM,导入BOM后的好处是:导入compose