升级buildSdkVersion至33后React Native打包Release遇Theme冲突问题
解决方案:解决React Native打包Release时的AndroidManifest主题冲突
升级buildSdkVersion到33后,执行bundleRelease打包出现的主题冲突,核心是测试依赖库androidx.test:core被错误引入到Release构建中,与图片裁剪库com.github.CanHub:Android-Image-Cropper的Manifest配置产生冲突。以下是几种可行解决办法:
方法1:排除裁剪库中的测试依赖
在app模块的build.gradle里,给图片裁剪库的依赖添加排除规则,移除不必要的测试库:
implementation('com.github.CanHub:Android-Image-Cropper:4.3.0') { exclude group: 'androidx.test', module: 'core' }
测试依赖本就不属于Release构建范畴,排除后即可消除冲突。
方法2:限制测试依赖仅在Debug构建加载
检查项目build.gradle,确保所有androidx.test相关依赖都使用debugImplementation而非implementation,避免Release构建加载测试库:
debugImplementation 'androidx.test:core:1.5.0' // 禁止使用 implementation 'androidx.test:core:1.5.0'
方法3:强制统一依赖版本(备选)
若必须保留测试依赖在Release构建中,可在项目根目录build.gradle里强制指定androidx.test:core版本,确保所有依赖使用同一版本:
allprojects { repositories { // 你的仓库配置 } configurations.all { resolutionStrategy.force 'androidx.test:core:1.5.0' // 也可尝试升级到兼容SDK33的新版本,比如1.6.0 } }
方法4:正确配置Manifest的tools替换
如果前几种方法无效,可在主AndroidManifest.xml中直接覆盖冲突的Activity配置,注意先添加tools命名空间:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="你的应用包名"> <!-- 覆盖冲突Activity的主题配置 --> <activity android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity" android:theme="@style/WhiteBackgroundTheme" tools:replace="android:theme" tools:node="merge" /> </manifest>
内容的提问来源于stack exchange,提问作者Nicolas R
相关产品推荐
相关产品推荐

