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

Expo 49本地eas build开发构建时出现Gradle依赖兼容错误

Expo React Native Android本地构建Gradle Java版本兼容错误修复

问题概述

因react-native-auth0不支持Expo Go,尝试本地构建Expo应用到Android模拟器测试时触发Gradle错误:核心原因是expo-dev-launcher-gradle-plugin、com.android.tools.build:gradle等依赖组件要求Java 11,而构建环境被配置为Java 8。更换JDK 21及多个Gradle版本后问题仍未解决。

错误核心日志

[RUN_GRADLEW] > Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed
[RUN_GRADLEW] a runtime of a component compatible with Java 8

解决方案

1. 切换到Java 11(强制要求)

Expo 49与React Native 0.72.x的构建环境仅兼容Java 11:Java 8版本过低,Java 21过高会与Gradle 7.x系列冲突。

  • 安装OpenJDK 11(推荐Adoptium或Oracle官方JDK 11)
  • 设置JAVA_HOME环境变量指向Java 11安装路径
  • 验证:终端执行java -version,输出需为openjdk version "11.x.x"

2. 锁定Gradle与AGP兼容版本

React Native 0.72.x官方指定AGP版本为7.4.2,对应Gradle版本为7.5:

  • 修改gradle/wrapper/gradle-wrapper.properties:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
    
  • 确认android/build.gradle中的AGP版本:
    buildscript {
        dependencies {
            classpath("com.android.tools.build:gradle:7.4.2")
            // 其他依赖保持原配置
        }
    }
    

3. 彻底清理构建缓存

# 清理Android构建缓存
./gradlew clean
# 重置Node依赖与Expo缓存
rm -rf node_modules package-lock.json
npm install
expo start -c

4. 恢复默认Gradle配置

若之前手动修改过Android端Gradle文件,执行expo prebuild --clean重新生成Expo默认配置,避免自定义配置导致的版本冲突。

用户配置参考

package.json

{
  "name": "first2-app",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "start-clearcache": "expo start -c"
  },
  "dependencies": {
    "@react-navigation/native": "^6.1.9",
    "@react-navigation/native-stack": "^6.9.15",
    "@reduxjs/toolkit": "^1.9.7",
    "axios": "^1.5.1",
    "expo": "~49.0.15",
    "expo-dev-client": "~2.4.11",
    "expo-location": "~16.1.0",
    "expo-splash-screen": "~0.20.5",
    "expo-status-bar": "~1.6.0",
    "nativewind": "^2.0.11",
    "react": "18.2.0",
    "react-native": "0.72.6",
    "react-native-auth0": "^3.0.2",
    "react-native-maps": "1.7.1",
    "react-native-safe-area-context": "4.6.3",
    "react-native-screens": "~3.22.0",
    "react-redux": "^8.1.3"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@types/react": "~18.2.14",
    "tailwindcss": "^3.3.2",
    "typescript": "^5.1.3"
  },
  "private": true
}

eas.json

{
    "cli": {
        "version": ">= 0.42.4"
    },
    "build": {
        "development": {
            "distribution": "internal",
            "android": {
                "gradleCommand": ":app:assembleDebug"
            },
            "ios": {
                "buildConfiguration": "Debug"
            }
        },
        "preview": {
            "distribution": "internal",
            "ios": {
                "simulator": true
            }
        },
        "production": {}
    },
    "submit": {
        "production": {}
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 12:37:03