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

Android Studio 3.3.1 Gradle4.4构建报错:未定义仓库无法解析依赖

Fixing Firebase Storage Gradle Sync Failure (Cannot resolve google-services:3.2.1)

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 with maven { 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 Files button in the Android Studio toolbar (the refresh-style icon)
  • If the sync still fails, run Build > Clean Project followed by Build > Rebuild Project to 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 classpath declaration 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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:47:13