执行npm run build时expo-firebase-core项目评估报错求助
Expo项目构建时
:expo-firebase-core:androidSourcesJar任务classifier属性未知错误 我创建了一个Expo项目并集成了Firebase谷歌认证功能,执行npm run build时出现以下错误:
评估项目':expo-firebase-core'时出现问题。
无法为类型为org.gradle.api.tasks.bundling.Jar的任务':expo-firebase-core:androidSourcesJar'设置未知属性'classifier'。
项目依赖如下:
"@react-native-async-storage/async-storage": "1.18.2", "@rneui/base": "^4.0.0-rc.7", "@rneui/themed": "^4.0.0-rc.8", "expo": "~49.0.7", "expo-application": "~5.3.0", "expo-auth-session": "~5.0.2", "expo-build-properties": "~0.8.3", "expo-constants": "~14.4.2", "expo-crypto": "~12.4.1", "expo-dev-client": "~2.4.8", "expo-firebase-core": "^6.0.0", "expo-firebase-recaptcha": "^2.3.1", "expo-linking": "~5.0.2", "expo-router": "2.0.0", "expo-splash-screen": "~0.20.5", "expo-status-bar": "~1.6.0", "firebase": "^10.2.0", "react": "18.2.0", "react-native": "0.72.4", "react-native-gesture-handler": "~2.12.0", "react-native-safe-area-context": "4.6.3", "react-native-screens": "~3.22.0", "react-native-webview": "13.2.2"
项目根目录build.gradle内容:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = findProperty('android.buildToolsVersion') ?: '33.0.0' minSdkVersion = Integer.parseInt(findProperty('android.minSdkVersion') ?: '21') compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '33') targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '33') kotlinVersion = findProperty('android.kotlinVersion') ?: '1.8.10' frescoVersion = findProperty('expo.frescoVersion') ?: '2.5.0' // 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.4.2') classpath('com.facebook.react:react-native-gradle-plugin') } } allprojects { repositories { 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() maven { url 'https://www.jitpack.io' } } }
修复建议
方案1:修改expo-firebase-core的Gradle配置(推荐)
这个错误是因为Gradle 7.x中Jar任务的classifier属性已被archiveClassifier替代,而expo-firebase-core的旧版本仍在使用废弃属性。可以通过patch-package生成永久补丁:
- 安装
patch-package:npm install patch-package --save-dev - 打开
node_modules/expo-firebase-core/android/build.gradle,找到androidSourcesJar任务:task androidSourcesJar(type: Jar) { classifier = 'sources' from android.sourceSets.main.java.srcDirs } - 将
classifier = 'sources'替换为archiveClassifier = 'sources':task androidSourcesJar(type: Jar) { archiveClassifier = 'sources' from android.sourceSets.main.java.srcDirs } - 生成补丁:
npx patch-package expo-firebase-core - 重新执行构建:
npm run build
方案2:调整expo-firebase-core版本
Expo 49推荐使用expo-firebase-core@~6.0.0,当前使用的^6.0.0可能拉取了不兼容的小版本。修改package.json中的版本:
"expo-firebase-core": "~6.0.0"
然后删除node_modules和package-lock.json,重新安装依赖:
rm -rf node_modules package-lock.json npm install
方案3:清理项目缓存
执行以下命令清理Expo缓存和构建文件:
npx expo prebuild --clean npm run build
内容的提问来源于stack exchange,提问作者Rusty
相关产品推荐
相关产品推荐

