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

React Native运行报错:':react-native-gesture-handler:compileDebugKotlin'执行失败

解决React Native项目中react-native-gesture-handler的Kotlin编译失败问题

问题背景

克隆React Native项目并执行npm install后,运行npm start时出现构建失败,核心错误为:react-native-gesture-handler:compileDebugKotlin任务执行失败,伴随过时API和未检查操作的警告。

解决方案

方案1:升级Kotlin版本

当前配置的Kotlin版本(1.8.0)与Gradle(8.9)、Android插件(8.7.1)及react-native-gesture-handler(2.18.1)存在兼容性冲突。修改根目录build.gradle中的Kotlin版本:

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 21
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "25.1.8937393"
        kotlinVersion = "1.9.20" // 更新为该版本
    }
    // 其余配置保持不变
}

方案2:适配react-native-gesture-handler版本

若升级Kotlin后问题仍存在,可降级react-native-gesture-handler至与React Native 0.73.0兼容的版本。修改package.json:

"react-native-gesture-handler": "2.14.0"

执行依赖安装:

npm install

清理缓存并重新构建

完成版本调整后,清理缓存确保生效:

  1. 进入Android目录执行Gradle清理:
cd android && ./gradlew clean
  1. 回到项目根目录重置Metro缓存:
npm start -- --reset-cache
  1. 重新启动项目:
npm start

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 00:32:43