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

构建Expo项目遇Kotlin Gradle插件版本不兼容问题求解决

解决expo-app-auth依赖的Kotlin Gradle插件版本不兼容问题

构建项目时,expo-app-auth的Android构建出现以下错误:

> Configure project :react-native-reanimated
AAR for react-native-reanimated has been found
/home/expo/workingdir/build/node_modules/react-native-reanimated/android/react-native-reanimated-71-hermes.aar

FAILURE: Build failed with an exception.

* What went wrong:

The Android Gradle plugin supports only Kotlin Gradle plugin version 1.5.20 and higher.

The following dependencies do not satisfy the required version:

project ':expo-app-auth' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21

* Try:

> Run with --stacktrace option to get the stack trace.



  repositories {
    maven {
      url = uri("https://plugins.gradle.org/m2/")
    }
  }

  dependencies {
  
    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21")
  }
}

apply(plugin = "org.jetbrains.kotlin.android")

解决方案

  • 强制统一Kotlin Gradle插件版本
    在项目根目录的android/build.gradle中添加版本强制策略,确保所有模块使用兼容的Kotlin版本:

    buildscript {
      ext {
        kotlinVersion = "1.8.21"
      }
      dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        // 保留其他原有依赖
      }
    }
    
    allprojects {
      repositories {
        // 保留原有仓库配置
      }
      configurations.all {
        resolutionStrategy {
          force "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
          force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
          force "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
        }
      }
    }
    
  • 升级expo-app-auth到兼容版本
    直接更新package.json中expo-app-auth的版本号至最新稳定版,执行npm install或yarn install完成依赖更新。新版本通常会适配更高版本的Kotlin插件。

  • 清理构建缓存
    执行以下命令清除Gradle缓存和项目依赖缓存,避免缓存导致的版本冲突:

    cd android && ./gradlew clean
    rm -rf ../node_modules package-lock.json && npm install
    
  • 用patch-package修改expo-app-auth的Gradle配置
    若无法升级依赖,通过补丁修改expo-app-auth的内置Gradle配置:

    1. 安装patch-package:npm install patch-package --save-dev
    2. 打开node_modules/expo-app-auth/android/build.gradle,将其中的Kotlin版本改为1.5.20以上(比如1.8.21)
    3. 生成补丁:npx patch-package expo-app-auth
    4. 后续安装依赖时,补丁会自动应用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 05:00:13