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

React Native 0.74.x(Expo SDK 51)环境下react-native-keyboard-controller编译失败求助

React Native 0.74.x(Expo SDK 51)环境下react-native-keyboard-controller编译失败求助

各位大佬好,我最近碰到了一个卡了好久的编译问题,想过来请教下大家的思路:

我当前的项目基于 React Native 0.74.x(对应 Expo SDK 51),不管是用 EAS 构建(本地和云端都试过),还是直接跑 npm run android,都会卡在同一个 Kotlin 编译错误上:

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':react-native-keyboard-controller:compileDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
Compilation error. See log for more details

我已经尝试过这些操作,但都没解决问题:

  • 升级到 React Native 0.75.x,同步更新了所有相关依赖包,错误依旧存在
  • 修改了 ./android/build.gradle 文件中的配置,把 Kotlin 版本调整到 1.9.23,同时对齐了编译 SDK、构建工具等参数(具体配置见下方)

我的 package.json 依赖内容

"dependencies": {
  "@expo/vector-icons": "^14.0.2",
  "@gorhom/bottom-sheet": "^5.1.1",
  "@react-navigation/native": "^6.0.2",
  "@tanstack/react-query": "^5.76.1",
  "calendars": "^0.0.1-alpha",
  "clsx": "^2.1.1",
  "date-fns": "^4.1.0",
  "dotenv": "^16.4.7",
  "expo": "~51.0.28",
  "expo-constants": "~16.0.2",
  "expo-dev-client": "~4.0.28",
  "expo-document-picker": "~12.0.2",
  "expo-env": "^1.1.1",
  "expo-font": "~12.0.9",
  "expo-linking": "~6.3.1",
  "expo-location": "~17.0.1",
  "expo-router": "~3.5.23",
  "expo-secure-store": "~13.0.2",
  "expo-splash-screen": "~0.27.7",
  "expo-status-bar": "~1.12.1",
  "expo-system-ui": "~3.0.7",
  "expo-web-browser": "~13.0.3",
  "nativewind": "^2.0.11",
  "ngrok": "^5.0.0-beta.2",
  "node-forge": "^1.3.1",
  "react": "18.2.0",
  "react-dom": "18.2.0",
  "react-native": "^0.74.5",
  "react-native-calendars": "^1.1313.0",
  "react-native-gesture-handler": "~2.16.1",
  "react-native-keyboard-controller": "^1.16.2",
  "react-native-maps": "1.14.0",
  "react-native-paper": "^5.13.1",
  "react-native-reanimated": "3.16.0",
  "react-native-rsa-native": "^2.0.5",
  "react-native-safe-area-context": "4.10.5",
  "react-native-screens": "3.31.1",
  "react-native-svg-transformer": "^1.5.0",
  "react-native-vector-icons": "^10.2.0",
  "react-native-web": "~0.19.10",
  "tailwindcss": "3.3.2",
  "zustand": "^5.0.3",
  "expo-linear-gradient": "~13.0.2"
},
"devDependencies": {
  "@babel/core": "^7.20.0",
  "@expo/ngrok": "^4.1.3",
  "@types/jest": "^29.5.12",
  "@types/lodash": "^4.17.16",
  "@types/react": "~18.2.45",
  "@types/react-native-calendars": "^1.1264.7",
  "@types/react-test-renderer": "^18.0.7",
  "eslint": "^8.57.0",
  "eslint-config-expo": "~7.1.2",
  "eslint-config-prettier": "^10.1.1",
  "eslint-plugin-prettier": "^5.2.3",
  "husky": "^9.1.7",
  "jest": "^29.2.1",
  "jest-expo": "~51.0.3",
  "prettier": "^3.5.3",
  "react-test-renderer": "18.2.0",
  "typescript": "~5.3.3"
}

修改后的 ./android/build.gradle 配置

buildscript {
    ext {
        buildToolsVersion = findProperty('android.buildToolsVersion') ?: '34.0.0'
        minSdkVersion = Integer.parseInt(findProperty('android.minSdkVersion') ?: '23')
        compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '34')
        targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '34')
        kotlinVersion = findProperty('android.kotlinVersion') ?: '1.9.23'
        ndkVersion = "26.1.10909125"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath('com.android.tools.build:gradle')
        classpath('com.facebook.react:react-native-gradle-plugin')
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
    }
}

apply plugin: "com.facebook.react.rootproject"

allprojects {
    repositories {
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url(new File(['node', '--print', "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), '../android'))
        }
        maven {
            // Android JSC is installed from npm
            url(new File(['node', '--print', "require.resolve('jsc-android/package.json', { paths: [rootDir.getAbsolutePath()] })"].execute(null, rootDir).text.trim(), '../dist'))
        }
        google()
        mavenCentral()
        maven { url 'https://www.jitpack.io' }
    }
}

(注:原配置最后一行有输入截断,我补全了常见的 JSC 仓库配置)

想请教下大家,有没有遇到过类似的情况?或者有什么排查方向可以推荐?比如是不是 Kotlin 版本和依赖库不兼容?还是某个依赖之间的冲突导致的?


内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.07 13:04:32