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

Maven/Gradle中Jar依赖找不到怎么办?以firebase-database为例

解决Firebase Database依赖找不到Jar包的问题

问题原因

com.google.firebase:firebase-database:20.2.2 是面向Android平台的依赖,发布到Maven仓库的格式为AAR(Android Archive),并非标准Jar包,直接按普通Jar依赖引入会触发找不到构件的错误。

解决方法

1. Maven Android项目配置

在依赖中明确指定类型为aar,同时声明编译范围:

<dependency>
    <groupId>com.google.firebase</groupId>
    <artifactId>firebase-database</artifactId>
    <version>20.2.2</version>
    <type>aar</type>
    <scope>compile</scope>
</dependency>

确保Maven配置已引入Google仓库:

<repositories>
    <repository>
        <id>google-maven</id>
        <url>https://maven.google.com/</url>
    </repository>
</repositories>

2. Gradle Android项目配置

Gradle会自动识别AAR类型,直接使用标准依赖声明即可:

dependencies {
    implementation 'com.google.firebase:firebase-database:20.2.2'
}

同时在项目根目录的build.gradle中配置Google仓库:

repositories {
    google()
    // 也可使用完整URL:maven { url 'https://maven.google.com/' }
}

3. 非Android项目的替代方案

如果是纯Java后端等非Android项目,需改用Firebase Admin SDK(提供Jar包格式):

<!-- Maven配置 -->
<dependency>
    <groupId>com.google.firebase</groupId>
    <artifactId>firebase-admin</artifactId>
    <version>9.2.0</version> <!-- 选择适配的版本 -->
</dependency>
// Gradle配置
implementation 'com.google.firebase:firebase-admin:9.2.0'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 14:52:00