更新 firebase 11 对 Android Gradle 的依赖

Update firebase 11 dependency on Android Gradle

我有以下app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        ...
        minSdkVersion 19
        targetSdkVersion 27
        ...
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    useLibrary 'org.apache.http.legacy'
}

dependencies {
    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.google.firebase:firebase-messaging:11.8.0'
    implementation 'com.google.firebase:firebase-core:11.8.0'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.github.IntruderShanky:scatter-piechart:1.0.0'
    implementation 'com.etsy.android.grid:library:1.0.5'
    implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
    implementation 'com.google.zxing:core:3.3.0'
    testImplementation 'junit:junit:4.12'
}

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

并关注project/build.gralde

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:3.2.1'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://jitpack.io"
        }
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

当我将鼠标悬停在 firebase 实现上方时,我收到以下警告

implementation 'com.google.firebase:firebase-messaging:11.8.0' 告诉我

A newer version of com.google.firebase:firebase-messaging than 11.8.0 is available: 17.1.0

implementation 'com.google.firebase:firebase-core:11.8.0'给我看

A newer version of com.google.firebase:firebase-core than 11.8.0 is available: 16.0.1

然后我进行建议并将我的实现更新为可用版本,如下所示

implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.google.firebase:firebase-core:16.0.1'

sync 我的项目。但是项目向我显示了以下错误

Failed to resolve: play-services-base Open File

Failed to resolve: play-services-tasks Open File

Failed to resolve: play-services-stats Open File

Failed to resolve: play-services-ads-identifier Open File

Failed to resolve: play-services-basement Open File

我试了很久都没解决。请帮我解决一下!

在顶级 gradle 文件中添加以下内容:

   buildscript {
      repositories {
              google()
              jcenter()
          }



 dependencies {
      classpath 'com.android.tools.build:gradle:3.1.3'
      classpath 'com.google.gms:google-services:4.0.2'
       }
    }

    allprojects {
         repositories {
                  google()
                 jcenter()
      }
    }

 task clean(type: Delete) {
   delete rootProject.buildDir
 }

jcenter()之前添加google() repo并使用最新的google服务插件版本4.0.2

https://bintray.com/android/android-tools/com.google.gms.google-services/

确保您连接到良好的网络

尝试将 Google maven 存储库添加到应用程序的 build.gradle 文件中:

repositories {
    maven { url "https://maven.google.com" }
}

如果第 1 步不起作用,请从您的项目根文件夹中删除 gradle 并再次重建您的项目。

再试一次

Goto >file -> other settings -> Under build, execution, and deployment -> you will see Gradle. uncheck the checkbox offline work