所有的gms/firebase库必须使用完全相同的版本规范Android Studio。

3
我知道这个问题已经被问了很多次,但我还是无法解决。让我在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服务的问题。我不知道这是由于更改还是其他原因导致的。因此,首先我想在gradle文件中删除此错误消息。 请检查: enter image description here enter image description here Google服务插件: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
}

应用程序Gradle:

    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'

裁剪 Gradle
 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"
}

Gradle库:

    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文件,包括应用程序级别和项目级别。 - Kruti Parekh
@parekhkruti26 我已经添加了项目和模块的Gradle文件,请检查。 - Satwinder Singh
你好,@Sunny Dhiman,我无法复制显示给你的警告。我在新项目中添加了所有构建 gradle,但这个警告没有出现。尝试使缓存失效并重新启动,然后进行更新。 - Kruti Parekh
降级库是唯一的选择,但这将导致所有 Firebase 和 Play Services 库都降级。 - Kruti Parekh
@parekhkruti26 但它没有显示任何编译时错误,甚至构建成功。我应该保留这些更改,因为它只显示一个警告消息,没有功能中断吗? - Satwinder Singh
显示剩余2条评论
4个回答

1
解决方案是:
将您的依赖项更改为12.0.1,并将gradle插件降级到版本3.2.1。
使用google-services 3.3在多模块应用程序中存在已知问题。这意味着降级到google-services 3.2.1可能是您唯一的选择,直到发布修复错误的新版本。

我已经在3.2.1上了。升级到3.3.0或3.3.1时,会出现gradle同步错误,如下所示:[https://dev59.com/NlUL5IYBdhLWcg3wlI1w]] - Satwinder Singh
你无法升级。只需转到我在答案中提到的链接即可查看。 - Koustuv Ganguly
降级到 Google-Services 版本 3.2.1 是您唯一的选择。 - Koustuv Ganguly

0

你也可以切换到3.3.1版本。 - Koustuv Ganguly
出现gradle同步错误: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版本:[https://dev59.com/NlUL5IYBdhLWcg3wlI1w] - Satwinder Singh
@KoustuvGanguly 在使用3.3.1版本时也遇到了Gradle同步错误。 - Satwinder Singh
尝试将此更改为3.2.1。 - Koustuv Ganguly

0
你使用的是哪个版本的Android Studio?那个lint错误是在Google Play服务和Firebase库可以是不同版本之前的。最新稳定版(3.1+)的Android Studio https://developer.android.com/studio/releases/应该会免除所有更新的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和Canary版本中,它显示为3.2。 - Satwinder Singh
好的,我认为如果您升级到Android Studio 3.1及以上版本,这个lint警告将会正常工作。 - zfromg

0
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作为一个平台的一些优势,使其与论坛区分开来。您可以编辑以添加其他信息和/或使用源文档补充您的解释。 - ysf
没错,但面向对象编程很简单,而且安卓资源更加丰富,这个答案在Studio中同步。 - user13010293

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接