【问题标题】:All gms/firebase libraries must use the exact same version specification Android Studio所有 gms/firebase 库必须使用完全相同的版本规范 Android Studio
【发布时间】:2018-05-15 04:13:41
【问题描述】:

我知道这个问题已被问过很多次,但我无法弄清楚。让我解释一下,5 月 2 日,firebase 宣布 Firebase Android SDK 现在有独立的版本号。在这里查看:Firebase Android Release Notes

所以我根据项目中的文档更改了所有 firebase 库版本号。之后,Android Studio 开始在 implementation 'com.google.android.gms:play-services-auth:15.0.1' 上显示警告消息

但它编译和生成构建成功,没有发生错误,应用程序运行完美。一天后,我注意到 Firebase 崩溃日志中有一些关于我的生产应用程序中的 google-play-service 的问题。我不知道由于变化或其他原因而发生这种情况。所以首先我想在 gradle 文件中删除这个错误信息。 查看:

谷歌服务插件:classpath 'com.google.gms:google-services:3.2.1' 我这里有三个模块是所有模块和项目的gradle文件。

项目等级:

    buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        maven {
            url 'https://maven.fabric.io/public'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.2.1'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
        classpath 'io.fabric.tools:gradle:1.25.4'

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

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

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

应用分级:

    apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "com.xyz.xyz"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 97
        versionName "2.3.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        resConfigs "en", "hi"
    }
    dexOptions {
        javaMaxHeapSize "4072M"
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
        release {
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    aaptOptions {
        cruncherEnabled = false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

greendao {
    schemaVersion 62
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation('com.facebook.android:facebook-android-sdk:[4,5)') {
        exclude group: "com.android.support"
    }
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true
    }
    implementation project(path: ':library')
    implementation project(path: ':showcase')
    implementation project(path: ':cropper')
    /* compile 'org.projectlombok:lombok:1.16.16'*/
    /*annotationProcessor 'org.projectlombok:lombok:1.16.16'*/
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:support-v13:27.1.1'
    implementation 'com.android.support:customtabs:27.1.1'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.volley:volley:1.0.0'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'de.hdodenhof:circleimageview:1.3.0'
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'com.github.jd-alexander:LikeButton:0.2.1'
    implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.google.android.gms:play-services-gcm:15.0.1'
    implementation 'com.google.firebase:firebase-auth:15.1.0'
    implementation 'com.google.firebase:firebase-core:15.0.2'
    implementation 'com.google.firebase:firebase-config:15.0.2'
    implementation 'com.google.firebase:firebase-crash:15.0.2'
    implementation 'com.google.firebase:firebase-invites:15.0.1'
    implementation 'com.google.firebase:firebase-messaging:15.0.2'
    implementation 'com.hbb20:ccp:1.8'
    implementation 'com.googlecode.libphonenumber:libphonenumber:8.4.2'
    implementation 'org.greenrobot:greendao:3.2.2'
    implementation 'com.clevertap.android:clevertap-android-sdk:3.1.4'
    testImplementation 'junit:junit:4.12'
    implementation 'android.arch.lifecycle:runtime:1.1.1'
    implementation 'android.arch.lifecycle:extensions:1.1.1'
    annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
    implementation 'org.jetbrains:annotations:15.0'
    implementation 'com.aurelhubert:ahbottomnavigation:2.1.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'it.sephiroth.android.library.targettooltip:target-tooltip-library:1.3.15'
    implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
    implementation 'com.caverock:androidsvg:1.2.1'
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true
    }
}

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

作物分级

 apply plugin: 'com.android.library'

android {

    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 1
        versionName '2.4.7'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation "com.android.support:exifinterface:27.1.1"
}

图书馆分级:

    apply plugin: 'com.android.library'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0.0"
    }
    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 fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    testImplementation 'junit:junit:4.12'
}

展示 gradle:

    buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

apply plugin: 'com.android.library'
apply plugin: 'maven'

dependencies {
    repositories {
        mavenCentral()
    }
    implementation 'com.android.support:support-annotations:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
}

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0.0"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

【问题讨论】:

  • 当其他依赖play-services库传递的库也包含它时,通常会出现这种类型的错误。他们在 auth 库上显示警告,因为在依赖项列表中,它是第一个 play-services 库。为了让我尝试解决这个问题,请发布您的应用级别和项目级别的完整 build.gradle 文件。
  • @parekhkruti26 我已经添加了项目和模块的 gradle 文件。请检查。
  • 您好@Sunny Dhiman,我无法复制显示给您的警告。我在新项目中添加了所有构建 gradle,但没有出现此警告。尝试使缓存无效并重新启动然后更新。
  • @parekhkruti26 我都试过了。每个人都建议使用谷歌服务将库降级为已知错误。
  • 降级库是唯一的选择,但它会影响降级所有 firebase 和 play-services 库。

标签: android firebase android-gradle-plugin google-play-services


【解决方案1】:

解决办法是:

将您的依赖项更改为 12.0.1 并将 gradle 插件降级到版本 3.2.1。

有一个known issue 关于在多模块应用程序中使用 google-services 3.3。这意味着在修复错误的新版本发布之前,将 google-services 降级到 3.2.1 可能是您唯一的选择。

【讨论】:

  • 我已经在 3.2.1 上。在升级到 3.3.0 或 3.3.1 时出现这样的 gradle 同步错误:[stackoverflow.com/questions/50132601/…
  • 你无法升级。只需转到我在回答中提到的链接即可查看。
  • 降级到 google-services 到 3.2.1 是您唯一的选择。
【解决方案2】:

这一变化是在 Google 服务 3.3 中引入的。所以将你的类路径升级到:

classpath 'com.google.gms:google-services:3.3.0'

由于您使用的是旧版本的 Google 服务,它仍会验证所有版本必须相同的旧逻辑。

另请参阅 Doug 关于此更改的博客文章:https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html

【讨论】:

  • 也可以改成3.3.1
  • Getting gradle sync error: Error:More than one variant of project :library matches the consumer attributes: Configuration ':library:debugApiElements' variant android-aidl:Found artifactType 'android-aidl' but wasn't required........ 有人建议降级到 3.2.1 : [stackoverflow.com/questions/50132601/…
  • @KoustuvGanguly 在 3.3.1 中也出现 gradle 同步错误
  • 尝试将其更改为 3.2.1
【解决方案3】:

您使用的是哪个版本的 Android Studio?该 lint 错误来自 Google Play 服务和 Firebase 库可能具有不同版本之前。 https://developer.android.com/studio/releases/,最新的稳定版(3.1+)Android Studio 应该免除所有较新的 Google Play 服务和 Firebase 库的检查(仍然检查低于 15.0.0 的版本)

博文有更多详情:https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html

这应该与使用的 google-services 插件的版本无关。

【讨论】:

  • 我当前的android studio版本是3.0.1。但它没有在稳定频道中显示任何更新。在 Dev 和 Canery 版本上,它显示 3.2。
  • 好的,我想如果你更新到 Android Studio 3.1 及更高版本,这个 lint 警告会做正确的事情。
【解决方案4】:
syn new all library firebase
implementation 'com.google.firebase:firebase-analytics:17.0.0'
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.google.firebase:firebase-database:17.0.0'
implementation 'com.google.firebase:firebase-storage:17.0.0'

【讨论】:

  • 虽然此代码可以解决 OP 的问题,但最好包含关于您的代码如何解决 OP 问题的说明。这样,未来的访问者可以从您的帖子中学习,并将其应用到他们自己的代码中。 SO 不是编码服务,而是知识资源。此外,高质量、完整的答案更有可能获得支持。这些功能,以及所有帖子都是独立的要求,是 SO 作为一个平台的一些优势,使其与论坛区分开来。您可以编辑以添加其他信息和/或使用源文档补充您的解释。
  • 没错,但是OOP很简单,资源android还有很多,这个答案在Studio中是syn
猜你喜欢
  • 2018-08-12
  • 2018-10-10
  • 2018-05-04
  • 1970-01-01
  • 2019-08-07
  • 1970-01-01
  • 2017-11-12
相关资源
最近更新 更多