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

React Native Android构建失败:minifyReleaseWithR8任务执行出错

React Native Android构建失败(:app:minifyReleaseWithR8)及相关警告解决方案

一、解决OpenCV与R8混淆冲突

针对jetified-opencv-4.1.0-runtime.jar中org/opencv/android/BaseLoaderCallback$4.class触发的CompilationFailedException,按以下操作处理:

  • 打开android/app/proguard-rules.pro,添加OpenCV专属混淆规则,防止R8误处理关键类:
# 保留OpenCV所有类与方法
-keep class org.opencv.** { *; }
-dontwarn org.opencv.**
  • 若上述规则无效,可禁用OpenCV的Jetifier(无需兼容旧支持库时适用),在android/gradle.properties中添加:
android.jetifier.blacklist=opencv-4.1.0-runtime

二、处理包名重复警告

1. Async Storage包名重复

  • 先卸载现有Async Storage,再重新安装最新版:
    npm用户执行:
    npm uninstall @react-native-async-storage/async-storage
    npm install @react-native-async-storage/async-storage@latest
    
    Yarn用户执行:
    yarn remove @react-native-async-storage/async-storage
    yarn add @react-native-async-storage/async-storage@latest
    

2. OpenCV包名重复

  • 检查android/app/build.gradle的dependencies块,删掉重复的OpenCV依赖,只保留一个版本即可。

三、修复WebView文件提供者声明异常

  • 打开android/app/src/main/AndroidManifest.xml,查找所有<provider>标签里的android.webkit.FileProvider,只保留一个,多余的直接删除。
  • 若重复声明来自第三方库,可通过tools:node="remove"强制移除冲突项:
<provider
    android:name="android.webkit.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true"
    tools:node="remove"/>

注意:根manifest标签需添加xmlns:tools="http://schemas.android.com/tools"才能使用该属性。

四、验证修复效果

  • 清理构建缓存:
cd android
./gradlew clean
  • 重新构建Release包:
./gradlew assembleRelease

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 20:10:25