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

修改targetSdkVersion至33后应用编译失败求助

解决targetSdkVersion升级到33后的编译问题

一、修复android:exported缺失导致的编译失败

报错里的EmptyFloatingActivity属于AndroidX测试库组件,旧版本测试库未适配Android 12+的android:exported强制要求,两种解决方式可选:

方法1:升级AndroidX测试依赖版本

在模块级build.gradle中,找到androidx.test相关依赖(比如androidx.test:core、androidx.test.ext:junit等),升级到1.5.0及以上版本,示例配置:

androidTestImplementation 'androidx.test:core:1.5.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

新版本测试库已为相关组件默认添加android:exported属性,可自动解决该问题。

方法2:在Manifest中显式声明该Activity

若暂时不想升级测试库,可在项目的AndroidManifest.xml中手动添加以下代码,为该Activity设置android:exported:

<activity
    android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
    android:exported="false"
    tools:node="merge" />

注意需在Manifest根标签中添加xmlns:tools="http://schemas.android.com/tools",确保tools:node="merge"生效。

二、解决TensorFlow Lite命名空间警告

警告源于你使用的tensorflow-lite:2.7.0和tensorflow-lite-support:0.3.0版本过旧,旧版本Manifest的命名空间与主项目冲突。只需升级这两个依赖到兼容targetSdk33的新版本即可,示例配置:

implementation 'org.tensorflow:tensorflow-lite:2.14.0'
implementation 'org.tensorflow:tensorflow-lite-support:0.4.4'

(可根据官方最新稳定版本调整,确保两个库版本匹配)

最后验证

修改完成后,点击Android Studio的Sync Project with Gradle Files同步配置,重新编译项目即可正常通过。

内容的提问来源于stack exchange,提问作者EA-CS-Teacher

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 20:48:26