添加Firebase会导致有关混合版本的警告,可能导致运行时崩溃 [英] Adding Firebase leads to warning about mixing versions can lead to runtime crashes

查看:75
本文介绍了添加Firebase会导致有关混合版本的警告,可能导致运行时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

空项目上,添加 firebase 后,会导致以下错误:

On an empty project, after adding firebase it leads to the following error:

图片版本:-

文本版本:-

所有com.android.support库必须使用完全相同的版本 规范(混合版本可能导致运行时崩溃).成立 版本27.1.1、25.2.0.例子包括 com.android.support:animated-vector-drawable:27.1.1和 com.android.support:support-media-compat:25.2.0

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.1, 25.2.0. Examples include com.android.support:animated-vector-drawable:27.1.1 and com.android.support:support-media-compat:25.2.0

另一个错误:

警告:配置编译"已过时,已被替换 带有实现"和"api".

WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.

是否有消除这些警告的解决方案?

Is there any possible solution to remove those warnings?

我的 project build.gradle 是:

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

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.1'
    }
}

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

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

我的 app build.gradle 是:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.mad.android.firebasetestauth2"
        minSdkVersion 24
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-auth:11.6.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

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

推荐答案

发生错误是因为 google-services 正在实现某些未使用27.1.1版本的库.因此,我们需要覆盖该版本.

The error occurs because google-services is implementing some libraries, which are not using the 27.1.1 version. So we need to override the version.

为此,请始终尝试在android studio的 终端 中运行此代码:

In order to do so, always try to do run this in the terminal of android studio:

./gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath

这将向您显示一个依赖项列表,其中显示了相关的版本号,如下所示:-

This will show you a list of dependencies, which shows the version number along it, something like this :-

在这里,我们需要找到那些未被覆盖并且版本号为 25或26且未覆盖到27 的依赖项.

Here we need to find those dependencies whose haven't been overwritten and have a version number like 25 or 26 and not overwritten to 27.

就像上面的例子一样,我们有com.android.support:support-v4:25.2.0

Like in the above example we have com.android.support:support-v4:25.2.0

现在,我们只需将其与最新版本号一起添加到依赖项块中即可.

Now we just need to add this to the dependencies block with the up to date version number.

最后,依赖项如下所示:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:support-media-compat:27.1.1'

    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-auth:12.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

我们在这里添加

implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:support-media-compat:27.1.1'

要修复

警告:配置编译"已过时,已被替换 带有实现"和"api".

WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.

project build.gradle 中,更新

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

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

这篇关于添加Firebase会导致有关混合版本的警告,可能导致运行时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆