Android Studio 3.3.1 Gradle4.4构建报错:未定义仓库无法解析依赖
Hey, let's tackle this Gradle sync error you're seeing. The root issue here is that your project-level build.gradle is missing the necessary repository configurations and the google-services plugin dependency—without these, Gradle can't locate the required Firebase-related tools.
Here's how to fix it step by step:
1. Update your project-level build.gradle
First, find the build.gradle file in the root folder of your project (not the one inside the app module). Make sure it includes these critical sections:
buildscript { repositories { // Google's Maven repository is mandatory for fetching Firebase dependencies google() jcenter() // Optional, but some older libraries may still require it } dependencies { // Add the google-services plugin classpath. For Gradle 4.4, version 4.3.10 is fully compatible classpath 'com.google.gms:google-services:4.3.10' } } allprojects { repositories { google() jcenter() } }
Note: If you run into issues with
google(), you can replace it withmaven { url 'https://maven.google.com' }—it's the same repository, just the older syntax.
2. Verify your app module's build.gradle
Check your app-level build.gradle to ensure two key things are in place:
- You've added the Firebase Storage dependency
- The google-services plugin is applied at the very end of the file
Here's what it should look like (building off your existing code snippet):
apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { applicationId "com.e..." // Your app's unique ID // Rest of your defaultConfig settings here } // Rest of your Android configuration here } dependencies { // Add Firebase Storage dependency compatible with compileSdk 27 implementation 'com.google.firebase:firebase-storage:17.0.0' // Add any other Firebase dependencies you're using here } // Critical: Apply the google-services plugin LAST to ensure proper dependency processing apply plugin: 'com.google.gms.google-services'
3. Sync and rebuild your project
- Click the
Sync Project with Gradle Filesbutton in the Android Studio toolbar (the refresh-style icon) - If the sync still fails, run
Build > Clean Projectfollowed byBuild > Rebuild Projectto clear any cached build issues
Why this works:
- The
google()repository hosts all official Google libraries (including the google-services plugin and Firebase SDKs)—without it, Gradle has no source to pull these files from - The project-level
classpathdeclaration tells Gradle how to locate the google-services plugin - Applying the plugin at the end ensures all Firebase dependencies are fully resolved before the plugin configures them for your app
内容的提问来源于stack exchange,提问作者Val

