React Native执行npm run android时安卓构建失败无法安装应用
React Native Android构建失败(mergeDebugAssets任务报错)
问题现象
使用React Native开发移动端应用,在Android模拟器测试时执行npm run android命令出现构建失败。此前尝试修改gradle.build文件、将SDK版本升级至31等操作均未生效,npm install命令可正常执行,无漏洞提示。
完整执行输出如下:
>react-native run-android warn Package react-native-vector-icons has been ignored because it contains invalid configuration. Reason: "dependency.assets" is not allowed info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag. (node:16364) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency (Use `node --trace-warnings ...` to show where the warning was created) Jetifier found 1186 file(s) to forward-jetify. Using 12 workers... info Starting JS server... info Installing the app... > Task :app:mergeDebugAssets FAILED Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. 23 actionable tasks: 23 executed Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01 Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01 Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01 Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01 Warning: élément inattendu (URI : "", local : "base-extension"). Les éléments attendus sont <{}codename>,<{}layoutlib>,<{}api-level> FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:mergeDebugAssets'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Failed to transform react-native-reanimated-69-jsc.aar (project :react-native-reanimated) to match attributes {artifactType=android-assets}. > Execution failed for JetifyTransform: C:\Users\ghars\OneDrive\Bureau\react-navigation-v6-mix\node_modules\react-native-reanimated\android\react-native-reanimated-69-jsc.aar. > Transform's input file does not exist: C:\Users\ghars\OneDrive\Bureau\react-navigation-v6-mix\node_modules\react-native-reanimated\android\react-native-reanimated-69-jsc.aar. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. BUILD FAILED in 8s error Failed to install the app. Make sure you have the Android development environment set up. Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01 Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01 Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01 Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01 Warning: élément inattendu (URI : "", local : "base-extension"). Les éléments attendus sont <{}codename>,<{}layoutlib>,<{}api-level> FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:mergeDebugAssets'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Failed to transform react-native-reanimated-69-jsc.aar (project :react-native-reanimated) to match attributes {artifactType=android-assets}. > Execution failed for JetifyTransform: C:\Users\ghars\OneDrive\Bureau\react-navigation-v6-mix\node_modules\react-native-reanimated\android\react-native-reanimated-69-jsc.aar. > Transform's input file does not exist: C:\Users\ghars\OneDrive\Bureau\react-navigation-v6-mix\node_modules\react-native-reanimated\android\react-native-reanimated-69-jsc.aar. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. BUILD FAILED in 8s at makeError (C:\Users\ghars\OneDrive\Bureau\react-navigation-v6-mix\node_modules\execa\index.js:174:9) at C:\Users\ghars\OneDrive\Bureau\react-navigation-v6-mix\node_modules\execa\index.js:278:16 at processTicksAndRejections (node:internal/process/task_queues:96:5) at async runOnAllDevices (C:\Users\ghars\OneDrive\Bureau\react-navigation-v6-mix\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5) at async Command.handleAction (C:\Users\ghars\OneDrive\Bureau\react-navigation-v6-mix\node_modules\@react-native-community\cli\build\index.js:192:9) info Run CLI with --verbose flag for more details.
报错根因
核心问题是react-native-reanimated依赖的预构建AAR产物缺失,Jetifier转换时找不到对应文件,直接导致mergeDebugAssets任务执行失败。日志里的SDK命名空间映射警告、Gradle版本兼容警告、react-native-vector-icons配置警告都不是本次构建失败的直接原因。
解决步骤
按顺序执行以下操作即可修复:
- 清理项目依赖与缓存
在项目根目录执行命令,Windows环境如果不支持rm命令可手动删除node_modules文件夹:rm -rf node_modules npm cache clean --force npm install - 手动构建reanimated的缺失AAR产物
进入reanimated包的android目录执行构建命令,Windows环境把./gradlew替换为gradlew.bat:cd node_modules/react-native-reanimated/android ./gradlew assembleRelease - 清理Android构建缓存后重新运行项目
回到项目根目录,执行以下命令:cd ../../../ cd android ./gradlew clean cd .. npm run android
- 额外优化:如果要消除react-native-vector-icons的警告,把该依赖升级到6.7.0及以上版本即可,新版本已修复
dependency.assets配置不合法的问题。
内容的提问来源于stack exchange,提问作者Emna Gharsalli
相关产品推荐
相关产品推荐

