Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Firebase leads to warning about mixing versions can lead to runtime crashes

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

Image Version :-

mixed version can lead to runtime crashes

Text Version :-

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

Another error :

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

Is there any possible solution to remove those warnings?

My project build.gradle is:

// 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
}

My app build.gradle is:

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'
like image 460
Pulkit Avatar asked Apr 10 '18 12:04

Pulkit


1 Answers

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.

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 :-

list of dependencies

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.

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.

Finally, the dependency block looks like this:

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'
}

Here we are adding

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

To fix the second error of

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

In project build.gradle, update the

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

to

classpath 'com.google.gms:google-services:3.2.0'
like image 124
Pulkit Avatar answered Sep 24 '22 18:09

Pulkit