2

So, i just created a new project, and before adding any new libraries or anything, i just added the firebase library, and as soon as i synced the gradle it gives me an error saying mixing android libraries can cause problems at appcompat library.

Image that shows the error

What am i doing wrong here ? why am i getting this error and how do i get rid of it ?

Here is the source code to my gradle file :

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.femindharamshi.codifyadmin"
            minSdkVersion 21
            targetSdkVersion 28
            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:28.0.0'
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'com.google.firebase:firebase-core:16.0.4'

    }

    apply plugin: 'com.google.gms.google-services'
Femn Dharamshi
  • 527
  • 1
  • 9
  • 25

4 Answers4

2

You can see this answer. And just need to do this:

implementation ('com.google.firebase:firebase-core:16.0.4') {
    exclude group: "com.android.support"
}
punchman
  • 1,350
  • 1
  • 13
  • 23
1

You have to check/fix dependency conflicts,

  • ./gradlew androidDependencies Or ./gradlew app:dependencies
  • Then you will see modules that duplicated among dependencies with different versions.

Solutions

  1. Force solution:

    //force a resolution
    
    configurations.all {
      resolutionStrategy.force 'com.android.support:support-media-compat:28.0.0'
    }
    
  2. Exclude duplicated module

    //excluding a module!
    
    implementation ("com.android.support:appcompat-v7:28.0.0") {
       exclude group: 'com.android.support', module: 'support-media-compat'
    }
    

Update Force Support libs

ext {
    supportLibVersion = '28.0.0'
}

dependencies {
    // ... Other dependencies 
    implementation "com.android.support:appcompat-v7:$supportLibVersion"
    implementation ("com.android.support:support-v4:$supportLibVersion"){
        force = true
    }
    implementation ("com.android.support:exifinterface:$supportLibVersion"){
        force = true
    }
}
Khaled Lela
  • 7,831
  • 6
  • 45
  • 73
  • if i do the option 2, the error comes on androidTestImplementation 'com.android.support.test:runner:1.0.2' tho i dont know what that is for – Femn Dharamshi Nov 02 '18 at 11:31
  • @UrvikShah check my answer update, with **Force Support libs** solution, Hope that will fix your issue. – Khaled Lela Nov 03 '18 at 14:13
0

Add this implementation :

implementation 'com.android.support:support-media-compat:28.0.0' 

Explanation: You can see in the error that there are different library versions you are currently using. In the part after examples it's showing you which one. Although you may think you are not using it. You are using it indirectly with the main libraries. So you have to explicitly upgrade libraries if there is a lower subversion

Arahasya
  • 525
  • 3
  • 14
0

add this line above your appcompat dependency

//noinspection GradleCompatible
  • This is not a solution. It's only avoiding the problem – Arahasya Oct 28 '18 at 05:42
  • i was facing the same issue. dong this helps for me. –  Oct 28 '18 at 05:47
  • Yes and you might face bugs while running you app. It's must to have the support libraries of same version. – Arahasya Oct 28 '18 at 05:49
  • Read my answer. Add all the implementations the studio is suggesting you to with the latest version. It will solve your problem – Arahasya Oct 28 '18 at 05:49
  • it's problem in android new version. No matter what dependency you use, it will give you that error –  Oct 28 '18 at 05:50
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/182663/discussion-between-jawad-malick-and-arahasya). –  Oct 28 '18 at 05:52
  • @JawadMalick check my answer for fixing dependency conflicts, – Khaled Lela Oct 28 '18 at 06:06