React Native 0.71.4 Android Gradle适配升级问题求助
React Native 0.71.4 Android编译失败:Gradle/SDK/Kotlin版本兼容问题解决
针对你遇到的编译冲突问题,提供两种可直接落地的解决方案:
方案一:不升级AGP/Gradle,强制降级冲突依赖
问题根源是项目依赖树中引入了androidx.core:core-ktx:1.12.0(要求compileSdk≥34),而当前项目使用compileSdk33。无需升级Gradle体系,直接强制所有模块使用兼容compileSdk33的版本:
- 打开项目根目录的
build.gradle,在allprojects块内添加依赖强制策略:
allprojects { repositories { google() mavenCentral() // 原有仓库配置保留 } // 新增强制依赖配置 configurations.all { resolutionStrategy { force 'androidx.core:core:1.11.0' force 'androidx.core:core-ktx:1.11.0' } } }
- 清理缓存并重新构建:
./gradlew clean ./gradlew app:installDebug -PreactNativeDevServerPort=8081
方案二:升级AGP/Gradle并同步Kotlin版本(适配RN0.71.4)
若需要升级到compileSdk34,需同步调整AGP、Gradle和Kotlin版本,确保和React Native 0.71.4兼容:
- 更新根目录
build.gradle配置:
buildscript { ext { buildToolsVersion = "34.0.0" minSdkVersion = 21 compileSdkVersion = 34 targetSdkVersion = 34 ndkVersion = "23.1.7779620" kotlinVersion = "1.8.22" // 指定兼容RN0.71.4的Kotlin版本 } repositories { google() mavenCentral() } dependencies { classpath("com.android.tools.build:gradle:7.4.2") // AGP7.4.2支持compileSdk34 classpath("com.facebook.react:react-native-gradle-plugin") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}") // 同步Kotlin插件版本 } }
- 修改
gradle-wrapper.properties中的Gradle版本(AGP7.4.2兼容Gradle7.6.1):
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dist
- 清理并重新编译:
./gradlew clean ./gradlew app:installDebug -PreactNativeDevServerPort=8081
内容的提问来源于stack exchange,提问作者user3118363
相关产品推荐
相关产品推荐

