You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kotlin DSL中wearApp配置已废弃,如何消除Gradle同步警告?

问题

项目同时包含移动端应用和Wear OS应用,运行正常,但每次执行Gradle同步时都会收到警告:

wearApp configuration is deprecated and planned to be removed in AGP 9.0. Please do not add any dependencies to it.

尝试用implementation替代wearApp后,编译时提示必须配置dynamicFeatures,但项目并未使用动态功能,也无相关配置痕迹。想了解为何wear模块会被识别为动态功能,以及如何消除该警告。

app模块的Gradle依赖块如下:

dependencies {
    wearApp(project(":wearable"))

    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.lifecycle.runtime.ktx)
    implementation(libs.androidx.activity.compose)
    implementation(platform(libs.androidx.compose.bom))
    implementation(libs.ui.core)
    implementation(libs.androidx.ui.graphics)
    implementation(libs.androidx.ui.tooling.preview)
    implementation(libs.androidx.material3)
    testImplementation(libs.junit)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)
    androidTestImplementation(platform(libs.androidx.compose.bom))
    androidTestImplementation(libs.androidx.ui.test.junit4)
    debugImplementation(libs.androidx.ui.tooling)
    debugImplementation(libs.androidx.ui.test.manifest)
}
解决方案

为什么会触发动态功能要求?

这是AGP的兼容性问题——Wear OS模块默认使用com.android.wear插件,当你用implementation依赖它时,AGP会错误地将其识别为动态功能模块,所以才会提示配置dynamicFeatures,和项目本身是否使用动态功能无关。

消除警告的正确方法

不要用implementation替代,改用官方专门替换wearApp的embeddedWearApp配置,它负责将Wear OS应用嵌入移动端APK,不会触发动态功能相关要求:

修改app模块的依赖块,把wearApp(project(":wearable"))替换为:

embeddedWearApp(project(":wearable"))

额外注意事项

  • 确保:wearable模块的build.gradle.kts中仍使用com.android.wear插件,不要改成动态功能相关插件。
  • 重新同步Gradle后,警告会消失,编译也不会再要求配置dynamicFeatures。

内容的提问来源于stack exchange,提问作者Ludiras

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 14:04:57