Android Studio 3.1.1中找不到com.google.firebase:firebase-database:12.0.1求助
Hey there, let's work through this frustrating error you're facing. I've dealt with similar dependency issues when working with older Android Studio versions and Firebase SDKs, so here are the most reliable fixes to try:
1. Verify Google Maven Repository is Configured Correctly
Firebase SDKs (including version 12.0.1) are hosted on Google's Maven repository, not just JCenter. Make sure your top-level build.gradle includes this repository—this is a common oversight.
Here's how your top-level build file should look:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() // Or use maven { url "https://maven.google.com" } for older Gradle versions jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.1.1' // Match this plugin version to your Firebase SDK: 12.0.1 needs 4.0.1 classpath 'com.google.gms:google-services:4.0.1' } } allprojects { repositories { google() // This must come before JCenter for priority jcenter() } }
2. Ensure Google Services Plugin Version Matches Firebase SDK
The google-services plugin version has to align with your Firebase SDK version. For Firebase 12.0.1, the correct plugin version is 4.0.1. Using a mismatched version (too new or too old) will break dependency resolution.
3. Clean Android Studio Cache and Restart
Cached data can often cause false "not found" errors. Let's clear it out:
- Go to
File > Invalidate Caches / Restart - Select Invalidate and Restart from the popup
- Once Studio reboots, re-sync your project with Gradle
4. Double-Check Module-Level Dependency Setup
Make sure your Module: app build.gradle has the correct dependency declaration and the Google Services plugin applied at the end:
dependencies { // Your other app dependencies... implementation 'com.google.firebase:firebase-database:12.0.1' } // Critical: This line must be at the END of the file apply plugin: 'com.google.gms.google-services'
Typos in the dependency string (like missing a colon or wrong version number) are easy to miss—double-check every character!
5. Update Google Repository in SDK Manager
Outdated Google Repository files can prevent Gradle from finding Firebase SDKs:
- Open
Tools > SDK Manager - Switch to the SDK Tools tab
- Check the box for Show Package Details
- Find Google Repository and make sure you have a version that supports Firebase 12.0.1 (the latest available version will work)
- Click Apply to install/update
If none of these steps work, try replacing google() with maven { url "https://maven.google.com" } in both buildscript and allprojects repositories—some older Gradle versions in Android Studio 3.1.1 don't recognize the shorthand google() command.
内容的提问来源于stack exchange,提问作者Vindula Yasas

