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

安装react-native-screens时出现CompileSdkVersion未找到错误求助

解决react-native-screens安装时的CompileSdkVersion错误

问题根源分析

你遇到的核心问题有两个:

  1. 根build.gradle的ext配置拼写错误:你写的extnext是无效语法,导致react-native-screens无法读取你定义的compileSdkVersion=31,只能使用默认的28,和项目的31版本冲突。
  2. Kotlin版本未明确配置:react-native-screens依赖Kotlin插件,你的项目未指定适配的Kotlin版本,会引发编译兼容问题。

具体修复步骤

1. 修复根build.gradle的ext配置

打开android/build.gradle,把错误的extnext改成ext,确保配置能被正确读取:

ext {
    buildToolsVersion = "31.0.0"
    minSdkVersion = 21
    compileSdkVersion = 31
    targetSdkVersion = 31
}

2. 添加Kotlin版本配置到根build.gradle

在android/build.gradle的buildscript块中添加适配RN 0.70.6的Kotlin版本:

buildscript {
    ext {
        // 保留上面的ext配置
        kotlinVersion = "1.6.21"
    }
    dependencies {
        // 其他已有依赖...
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

3. 清理缓存并重新构建

执行以下命令清理旧缓存,避免配置残留:

# 清理npm缓存
npm cache clean --force

# 清理Android构建缓存
cd android && ./gradlew clean

# 重新安装依赖
cd .. && npm install

# 重新运行项目
npx react-native run-android

验证逻辑

修改后,react-native-screens的android/build.gradle中通过safeExtGet('compileSdkVersion', 28)会优先读取你根项目定义的31,而非默认的28,整个项目的CompileSdkVersion统一后,版本冲突即可解决。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 19:01:10