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

使用Expo Go构建React Native项目时遇Gradle配置错误

Expo Go构建React Native项目时的Gradle错误解决

问题详情

使用Expo Go构建React Native项目时出现Gradle构建失败,所有依赖(含expo-ads-admob)已更新至最新版本,错误日志如下:

> Configure project :app
 ℹ️  Applying gradle plugin 'expo-dev-launcher-gradle-plugin' (expo-dev-launcher@5.0.31)
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* Where:
Build file '/home/expo/workingdir/build/node_modules/expo-ads-admob/android/build.gradle' line: 40
* What went wrong:
A problem occurred evaluating project ':expo-ads-admob'.
> Could not set unknown property 'classifier' for task ':expo-ads-admob:androidSourcesJar' of type org.gradle.api.tasks.bundling.Jar.
* Try:
> Run with --stacktrace option to get the stack trace.
>
Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
>
Get more help at https://help.gradle.org.
==============================================================================
2: Task failed with an exception.
-----------
* Where:
Script '/home/expo/workingdir/build/node_modules/expo-modules-core/android/ExpoModulesCorePlugin.gradle' line: 95
* What went wrong:
A problem occurred configuring project ':expo'.
>
Could not get unknown property 'release' for SoftwareComponent container of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or
--debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org
==============================================================================
BUILD FAILED in 1m 32s
18 actionable tasks: 18 executed

解决步骤

1. 修复expo-ads-admob的classifier属性错误

Gradle 7.0+ 废弃了Jar任务的classifier属性,改用archiveClassifier,需修改依赖的构建配置:

  • 安装补丁工具:
    npm install patch-package --save-dev
    
  • 打开node_modules/expo-ads-admob/android/build.gradle,找到第40行的classifier = 'sources',替换为:
    archiveClassifier = 'sources'
    
  • 生成并保存补丁:
    npx patch-package expo-ads-admob
    

2. 修复expo项目的release组件错误

该问题多由Gradle版本与Expo模块不兼容导致,执行以下操作:

  • 检查android/build.gradle中的Gradle版本,确保与当前Expo SDK版本匹配(比如Expo SDK 49对应Gradle 7.5及以上)
  • 清理缓存并重建项目:
    rm -rf node_modules package-lock.json yarn.lock
    npm install
    npx expo prebuild --clean
    
  • 若使用EAS构建,确认eas.json中配置的Gradle版本符合要求

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 20:04:55