React Native项目EAS构建报错:找不到maven插件
解决EAS Build Android预览版构建时的
Plugin with id 'maven' not found错误 执行eas build -p android --profile android-preview构建Android预览版时,出现如下错误:
[stderr] A problem occurred evaluating project ':unimodules-core'.
[stderr] >
[stderr] Plugin with id 'maven' not found.
看到有建议将build.gradle里的apply plugin: 'maven'替换为apply plugin: 'maven-publish',但在项目根目录的build.gradle中找不到相关引用,当前根build.gradle内容如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = findProperty('android.buildToolsVersion') ?: '31.0.0' minSdkVersion = Integer.parseInt(findProperty('android.minSdkVersion') ?: '21') compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '31') targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '31') if (findProperty('android.kotlinVersion')) { kotlinVersion = findProperty('android.kotlinVersion') } frescoVersion = findProperty('expo.frescoVersion') ?: '2.5.0' kotlinVersion: '1.6.20' if (System.properties['os.arch'] == 'aarch64') { // For M1 Users we need to use the NDK 24 which added support for aarch64 ndkVersion = '24.0.8215888' } else { // Otherwise we default to the side-by-side NDK version from AGP. ndkVersion = '21.4.7075529' } } repositories { google() mavenCentral() } dependencies { classpath('com.android.tools.build:gradle:7.2.1') classpath('com.facebook.react:react-native-gradle-plugin') classpath('de.undercouch:gradle-download-task:5.0.1') classpath('org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20') // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } def REACT_NATIVE_VERSION = new File(['node', '--print', "JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim()) allprojects { configurations.all { resolutionStrategy { force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION } } repositories { mavenLocal() 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')"].execute(null, rootDir).text.trim(), '../dist')) } google() mavenCentral { // We don't want to fetch react-native from Maven Central as there are // older versions over there. content { excludeGroup 'com.facebook.react' } } maven { url 'https://www.jitpack.io' } } }
解决方案
错误出现在:unimodules-core模块,说明问题不在根build.gradle,而是在依赖库的内部配置文件中,按以下步骤修复:
方法1:手动修改依赖库文件
- 找到项目中
node_modules/expo-unimodules/unimodules-core/android/build.gradle文件 - 查找其中的
apply plugin: 'maven'代码行 - 将其替换为
apply plugin: 'maven-publish' - 重新执行构建命令
eas build -p android --profile android-preview
方法2:用patch-package永久修复(推荐)
避免每次安装依赖后重复手动修改:
- 安装
patch-package:
npm install patch-package --save-dev
- 完成方法1中的文件修改后,执行命令生成补丁:
npx patch-package expo-unimodules
- 将生成的
patches/expo-unimodules+[对应版本号].patch文件提交到版本控制 - 后续执行
npm install时,patch-package会自动应用这个补丁
方法3:升级依赖版本
如果你的expo-unimodules版本较旧,直接升级到最新稳定版,新版本可能已兼容Gradle 7+:
npm install expo-unimodules@latest
内容的提问来源于stack exchange,提问作者Muirik
相关产品推荐
相关产品推荐

