【问题标题】:How to solve Could not find com.google.gms:google-services:4.1.0.?如何解决找不到 com.google.gms:google-services:4.1.0.?
【发布时间】:2019-03-27 04:55:25
【问题描述】:

我遇到了这个错误:

Could not find com.google.gms:google-services:4.1.0.
Required by:
    project :app
Search in build.gradle files

我已经尝试过其他提出相同问题的人在堆栈溢出时显示的其他解决方案:

Could not find com.google.gms:google-services:4.1.0. Searched in the following locations:

Could not find any version that matches com.google.android.gms:play-services-base:[15.0.1,16.0.0)

这是我的应用 build.gradle 文件:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "sg.edu.singaporetech.teamproject"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.facebook.android:facebook-login:4.41.0'
    implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
    implementation 'com.google.firebase:firebase-auth:16.2.0'
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-database:16.1.0'
    implementation 'com.google.firebase:firebase-storage:16.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.jjoe64:graphview:4.2.1'
}

apply plugin: 'com.google.gms.google-services'
repositories {
    google()
    jcenter()
    mavenCentral()
    maven { url "https://dl.bintray.com/android/android-tools" }

}

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.1.0'
    }

}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.android.application'

这是我的项目 build.gradle 文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.21'

    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://dl.bintray.com/android/android-tools" }

    }
    dependencies {
        classpath 'com.google.gms:google-services:4.1.0'
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://dl.bintray.com/android/android-tools" }


    }

}

我希望解决此错误,以便我可以成功构建我的项目。

任何帮助将不胜感激,谢谢。

【问题讨论】:

  • 请同时添加项目gradle
  • 嗨 @Basi 我也添加了项目 gradle。
  • 从 app build gradle 底部移除 apply plugin: 'com.android.application' 并尝试
  • 嗨@ZaidMirza,谢谢帮忙!不幸的是,它没有用。错误仍然相同:找不到 com.google.gms:google-services:4.1.0。要求:project :app 在 build.gradle 文件中搜索
  • 还有另一个重复。请在下面尝试我的答案

标签: android gradle build google-api


【解决方案1】:

您添加的插件不止一个。请尝试一下

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "sg.edu.singaporetech.teamproject"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.facebook.android:facebook-login:4.41.0'
    implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
    implementation 'com.google.firebase:firebase-auth:16.2.0'
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-database:16.1.0'
    implementation 'com.google.firebase:firebase-storage:16.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.jjoe64:graphview:4.2.1'
}

repositories {
    google()
    jcenter()
    mavenCentral()
    maven { url "https://dl.bintray.com/android/android-tools" }

}

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.1.0'
    }

}
apply plugin: 'com.google.gms.google-services'

更新

尝试使用这个最新版本'com.google.gms:google-services:4.2.0'

【讨论】:

  • 我试过了,我得到了这个错误:找不到 com.google.gms:google-services:4.1.0。要求:project :app 在 build.gradle 文件中搜索
【解决方案2】:

我认为您需要将这些 build.grdle 文件分成两部分。首先是项目级别的 build.gradle,其次是“app”(模块)级别的 build.gradle。

项目级 Gradle 将具有:-

    apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.android.application' 
repositories {
    google()
    jcenter()
    mavenCentral()
    maven { url "https://dl.bintray.com/android/android-tools" }

}

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.1.0'
    }

}

并且app(模块)级别的build.gradle会有

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "sg.edu.singaporetech.teamproject"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.facebook.android:facebook-login:4.41.0'
    implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
    implementation 'com.google.firebase:firebase-auth:16.2.0'
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-database:16.1.0'
    implementation 'com.google.firebase:firebase-storage:16.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.jjoe64:graphview:4.2.1'
}

您可能还需要在项目级别的 gradle 文件中添加更多内容。

【讨论】:

  • 嗨 Jatin,感谢您的帮助。我确实有一个项目 gradle 和一个应用程序 gradle。对于没有在开始时上传这两个代码,我深表歉意。我已经添加了它。但是,这个错误仍然发生。知道为什么吗?
  • 从 app build.gradle 中删除以下行 :- apply plugin: 'com.google.gms.google-services' repositories { google() jcenter() mavenCentral() maven { url "dl.bintray.com/android/android-tools " } } buildscript { dependencies { classpath 'com.google.gms:google-services:4.1.0' } } 应用插件:'com.google.gms.google-services' 应用插件:'com.android.application' 这些是该文件的最后 15-20 行。
猜你喜欢
  • 2019-05-11
  • 2019-04-17
  • 2018-09-25
  • 2020-11-13
  • 1970-01-01
  • 2019-05-11
  • 2017-11-14
  • 1970-01-01
  • 2019-05-11
相关资源
最近更新 更多