React Native旧项目迁移新PC后Android构建失败求助
老旧React Native项目迁移新PC后Android构建失败解决
问题概述
维护的老旧React Native项目此前运行正常,迁移至新PC后使用Android Studio构建时出现两类核心错误:无法解析Mapbox依赖包,以及Realm模块的NDK工具链缺失。
构建错误日志
* What went wrong: Execution failed for task ':app:mergeDebugAssets'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Could not find mapbox-android-accounts-0.7.0.aar (com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0). Searched in the following locations: https://jcenter.bintray.com/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.aar ============================================================================== 4: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:processDebugManifest'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Could not find mapbox-android-accounts-0.7.0.aar (com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0). Searched in the following locations: https://jcenter.bintray.com/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.aar ============================================================================== 5: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:checkDebugDuplicateClasses'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Could not find mapbox-android-accounts-0.7.0.aar (com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0). Searched in the following locations: https://jcenter.bintray.com/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.aar ============================================================================== 6: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:desugarDebugFileDependencies'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Could not find mapbox-android-accounts-0.7.0.aar (com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0). Searched in the following locations: https://jcenter.bintray.com/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.aar ============================================================================== 7: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':realm:stripDebugDebugSymbols'. > No toolchains found in the NDK toolchains folder for ABI with prefix: arm-linux-androideabi
项目Android根配置(android/build.gradle)
buildscript { ext { buildToolsVersion = "31.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 34 } repositories { google() mavenCentral() // Maven Central repository jcenter() maven { url "$rootDir/../node_modules/react-native/android" } maven { url "https://jitpack.io" } maven { url "https://maven.google.com" } } dependencies { classpath 'com.android.tools.build:gradle:3.5.4' //// <!-- Fix ggmap sdk30 --> classpath 'com.google.gms:google-services:4.3.13' classpath "com.bugsnag:bugsnag-android-gradle-plugin:5.+" } } subprojects { project.configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'com.android.support' && !details.requested.name.contains('multidex') ) { details.useVersion "26.1.0" } } } } allprojects { repositories { exclusiveContent { filter { includeGroup "com.facebook.react" } forRepository { maven { url "$rootDir/../node_modules/react-native/android" } } } mavenLocal() mavenCentral() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url ("$rootDir/../node_modules/react-native/android") } maven { // Android JSC is installed from npm url("$rootDir/../node_modules/jsc-android/dist") } google() jcenter() maven { url 'https://www.jitpack.io' } } }
已尝试的无效操作
- 匹配node、jdk、build Gradle和AGP版本(node v16.20.2,jdk 11,build gradle 6.2,AGP 3.5.4)
- 清除缓存、清理项目并重启Android Studio
- 将compileSdkVersion改为34
- 执行
npm cache clean --force、rmdir /s /q node_modules和npm install
解决方案
1. 解决Mapbox依赖缺失问题
JCenter已停止服务,旧版Mapbox包未同步到Maven Central,需添加Mapbox官方私有仓库:
在allprojects -> repositories中添加Mapbox仓库:
maven { url 'https://api.mapbox.com/downloads/v2/releases/maven' authentication { basic(BasicAuthentication) } credentials { // 用户名留空,密码填入你的Mapbox公开token username = "" password = "你的Mapbox公开token" } }
若未持有Mapbox token,需先登录Mapbox平台获取公开token后填入配置。
2. 解决Realm的NDK工具链缺失问题
旧版Realm依赖低版本NDK的arm-linux-androideabi工具链,需指定兼容的NDK版本:
- 打开项目的
local.properties文件,添加:ndkVersion=21.4.7075529 - 或在
app/build.gradle的android块中配置:android { ndkVersion "21.4.7075529" // 其他配置... }
配置完成后,Android Studio会自动下载对应版本的NDK,重启构建即可。
内容的提问来源于stack exchange,提问作者Nguyễn Tuấn Đạt - B21DCDT008
相关产品推荐
相关产品推荐

