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

React Native 0.72.6 Kotlin版本不兼容错误解决求助

解决React Native 0.72.6 Kotlin版本不兼容及AGP版本为空问题

1. 明确版本对应关系

React Native 0.72.6有严格的依赖版本要求,你当前使用的Gradle 8.4、Kotlin 1.9.0与该版本RN不匹配,这是核心问题。官方推荐的兼容版本组合:

  • Android Gradle Plugin(AGP):7.3.1
  • Kotlin:1.8.20
  • Gradle:7.5

2. 修复AGP版本为空问题

打开项目根目录下的android/build.gradle文件,在buildscript块中明确指定AGP和Kotlin版本:

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33
        // 新增AGP和Kotlin版本配置
        androidGradlePluginVersion = "7.3.1"
        kotlinVersion = "1.8.20"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        // 替换AGP和Kotlin插件依赖
        classpath("com.android.tools.build:gradle:${ext.androidGradlePluginVersion}")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${ext.kotlinVersion}")
        classpath("com.facebook.react:react-native-gradle-plugin:")
    }
}

3. 调整Gradle版本到兼容版本

打开android/gradle/wrapper/gradle-wrapper.properties文件,修改distributionUrl为Gradle 7.5:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip

4. 清理缓存并重新构建

  • 进入android目录执行清理命令:
cd android
./gradlew clean
rm -rf ~/.gradle/caches
  • 返回项目根目录重新构建:
npx react-native run-android

5. 排查第三方依赖冲突

如果问题仍存在,检查是否有第三方依赖强制引入高版本Kotlin。执行以下命令查看依赖树:

cd android
./gradlew app:dependencies

找到引入kotlin-stdlib 1.9.10的依赖后,在app/build.gradle中添加版本强制约束:

configurations.all {
    resolutionStrategy {
        force "org.jetbrains.kotlin:kotlin-stdlib:1.8.20"
        force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.20"
        force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20"
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 23:50:06