【问题标题】:Android Canary dependencies for jetpack composeJetpack compose 的 Android Canary 依赖项
【发布时间】:2021-07-14 20:05:28
【问题描述】:

我刚开始学习 jetpack compose,我有几个问题

  1. 我应该使用“对 Gradle 构建文件使用 kotlin 脚本 (.kts)”吗?如果可以,有什么好处?

  2. 还有我如何跟上依赖关系

    来自developers 的依赖项显示的是旧版本,然后是 android studio canary 中的那个。 其中一些要么根本不存在,要么版本不同

我需要包括这些

implementation 'androidx.compose.foundation:foundation:1.0.0-beta01'
implementation 'androidx.compose.material:material-icons-core:1.0.0-beta01'
implementation 'androidx.compose.material:material-icons-extended:1.0.0-beta01'
implementation 'androidx.compose.runtime:runtime-livedata:1.0.0-beta01'
implementation 'androidx.compose.runtime:runtime-rxjava2:1.0.0-beta01'

implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha02'

我需要包括那个吗

implementation 'androidx.compose.material:material:1.0.0-beta01'

或者被替换为

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

在哪里可以查看新版本以及是否兼容

implementation 'androidx.activity:activity-compose:1.3.0-alpha03'

implementation 'androidx.activity:activity-compose:1.3.0-alpha06

默认包含在 AS canary 中

dependencies {

    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.0-alpha06'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
}

【问题讨论】:

    标签: android-studio kotlin dependencies android-jetpack-compose gradle-kotlin-dsl


    【解决方案1】:
    1. 您可以同时使用 gradle 和 gradle.kts 文件,以适合您的方式。

    您可以在official documentation 中了解 kts 的好处

    如果您对 gradle 文件完全满意,则没有理由切换,但如果您从头开始,我建议您使用 kts

    1. 您始终可以在compose-samples 中找到的当前依赖项集

    此 repo 包含由 compose 维护者制作的示例,并在每个版本中更新。您可以订阅发布通知以始终保持最新状态。

    我目前的部门:

    let composeVersion = "1.0.0-beta05"
    
    "androidx.appcompat:appcompat:1.3.0-beta01"
    "androidx.core:core-ktx:1.3.2"
    "com.google.android.material:material:1.3.0"
    "androidx.activity:activity-ktx:1.2.1"
    "androidx.activity:activity-compose:1.3.0-alpha07"   
    "androidx.compose.ui:ui:$composeVersion"
    "androidx.compose.foundation:foundation:$composeVersion"
    "androidx.compose.material:material:$composeVersion"
    "androidx.compose.material:material-icons-core:$composeVersion"
    

    【讨论】:

    • 更好的 androidx.appcompat:appcompat:1.3.0-beta01 而不是 1.2.0
    • @GabrieleMariotti 谢谢,更新了那个
    • 如果kotlin-dsl 不是一个选项怎么办?如果 kotlin-dsl 被阻止,gradle build 将无法编译(公司基础架构);
    • @JoãoCarlos 我不确定你到底在问什么,但在官方谷歌示例中github.com/android/compose-samples kotlin-dsl 没有使用,所以你可以将它们作为参考来查看
    • 我在这里得到了错误的配置,控制台抱怨一些tsl版本错误;使用 rc02,kotlinCompiler 配置可以删除,所以我这样做了,错误消失了;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    • 2022-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多