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

React Native Android项目运行报错:评估:react-native-gesture-handler项目失败

React Native项目Android构建报错(Gradle/Kotlin版本兼容问题)

问题背景

从GitHub导入RandomChat项目后,执行npm install完成依赖安装,但运行npx react-native run-android时出现构建报错。环境信息如下:

  • 操作系统:Windows
  • React Native版本:9.6.7(通过npm react-native -v查询)
  • Node.js版本:v18.17.1
  • Android Studio版本:Android Studio Dolphin 2021.3.1 Patch 1
  • 项目配置:Android API 33

项目根目录build.gradle内容:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
    }
}

解决方案

1. 指定兼容的Kotlin版本

Android Studio Dolphin搭配的AGP 7.3.1需要Kotlin 1.6.21及以上版本,在根build.gradle中添加Kotlin版本配置:

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33
        ndkVersion = "23.1.7779620"
        kotlinVersion = "1.7.20" // 添加Kotlin版本定义
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") // 添加Kotlin插件依赖
    }
}

2. 匹配Gradle Wrapper版本

AGP 7.3.1要求Gradle版本在7.4及以上,修改gradle/wrapper/gradle-wrapper.properties中的distributionUrl:

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

3. 清理缓存并重新构建

执行以下命令清除旧构建缓存,重新运行项目:

cd android
gradlew clean
cd ..
npx react-native run-android

4. 确认React Native版本准确性

注意:你提供的React Native版本9.6.7不符合常规版本命名(当前稳定版为0.7x系列),建议检查项目package.json中的react-native字段确认实际版本。如果是旧版本,需对应调整AGP和Gradle版本适配(比如RN 0.69+对应AGP 7.3.x、Gradle 7.4+)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 02:18:34