1

When I check the external libraries in my Android Studio Project, I see duplicated libraries in different versions.

Is there any way to find out the reason.

I definitely do not add more than one dependency. But not sure, what causes this. This is my build.gradle file;

// 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:4.2.1'
        

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

    }


}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        mavenCentral()
        maven() {
            url "https://oss.sonatype.org/content/repositories/snapshots"
        }
        maven {
            url "s3://android.maven.s3.amazonaws.com"
            credentials(AwsCredentials) {
                accessKey ""
                secretKey ""
            }
        }
    }
}

subprojects {

    project.evaluationDependsOn(':_ABT')
//[PART TO ADD START]
    project.configurations.all {

        resolutionStrategy.eachDependency { details ->

            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.0"
            }
        }
    }
//[PART TO ADD END]
}

ext {
    supportLibVersion = "28.0.0"
}

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

And this is the dependencies build.gradle file;

apply plugin: 'com.android.library'

android {
    compileSdkVersion 30
    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '30.0.3'
    android {
        lintOptions {
            checkReleaseBuilds false
            abortOnError false
        }
    }
    useLibrary 'android.test.runner'

    useLibrary 'android.test.base'
    useLibrary 'android.test.mock'
    compileOptions {
    sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    api 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    androidTestImplementation 'androidx.test:rules:1.4.0-beta01'
    implementation 'androidx.annotation:annotation:1.2.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.google.zxing:core:3.3.2'
    implementation('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false }
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.gms:play-services-plus:17.0.0'
    implementation 'com.google.firebase:firebase-core:19.0.0'
    implementation 'com.google.firebase:firebase-messaging:22.0.0'
    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
    implementation 'com.stepstone.stepper:material-stepper:4.3.1'
    implementation 'com.github.santalu:mask-edittext:1.0.5'
    implementation 'com.google.android.gms:play-services-base:17.6.0'
    implementation 'com.google.android.gms:play-services-identity:17.0.0'
    implementation 'com.google.android.gms:play-services-auth:19.0.0'
    implementation 'com.google.android.gms:play-services-auth-api-phone:17.5.0'
    implementation('com.github.ozodrukh:CircularReveal:2.0.1@aar') {
        transitive = true;
    }
    implementation 'joda-time:joda-time:2.10'
    implementation 'com.google.android.gms:play-services-maps:17.0.1'
    implementation 'com.google.firebase:firebase-database:20.0.0'
    implementation 'com.google.android.gms:play-services-location:18.0.0'

    //Bibliotecas necessárias para rodar secure mobile token
    implementation 'com.madgag.spongycastle:bctls-jdk15on:1.58.0.0'
    implementation 'com.yakivmospan:scytale:1.0.1'
    implementation 'com.github.instacart.truetime-android:library:3.3'

    implementation group: 'br.com.martonis.library', name: 'PhoneNumberFormatter', version:'1.4', ext: 'aar', classifier: 'release'
    implementation group: 'br.com.martonis.library', name: 'KeyboardStateWatcher', version: '1.2', ext: 'aar', classifier: 'release'
    implementation group: 'br.com.martonis.library', name: 'SecureMobileToken', version: '3.125', ext: 'aar', classifier: 'release'
    implementation group: 'br.com.martonis.library', name: 'CreditCardCustomView', version: '2.10', ext: 'aar', classifier: 'release'
    implementation group: 'br.com.martonis.library', name: 'Updater', version: '2.2', ext: 'aar', classifier: 'release'

    implementation 'com.shawnlin:number-picker:2.4.11'

    implementation 'androidx.core:core:1.5.0'
    implementation 'androidx.legacy:legacy-support-core-ui:1.0.0'
    implementation 'me.toptas.fancyshowcase:fancyshowcaseview:1.1.5'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.31"

    implementation 'androidx.recyclerview:recyclerview:1.2.0'
    implementation 'com.google.android.gms:play-services-vision:20.1.3'
    implementation 'org.greenrobot:eventbus:3.1.1'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.14'
    implementation 'com.google.android.gms:play-services-maps:17.0.1'
    implementation 'com.ethanhua:skeleton:1.1.2'
    implementation 'io.supercharge:shimmerlayout:2.1.0'
    implementation 'org.apache.commons:commons-lang3:3.4'
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
}

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

These are some of the duplicated libraries. For ex, I have 3 libraries for android-core:

androidx.core:core:1.3.1@aar
androidx.core:core:1.3.2@aar
androidx.core:core:1.5.0@aar

And you can see more below:

enter image description here

enter image description here

enter image description here

enter image description here

Is there any way to find out who calls these libraries to find out the sources of them?

Thanks in advance!

Hilal
  • 902
  • 2
  • 22
  • 47

2 Answers2

1

This might be because of something called as Transitive dependency. Lets say you are using android core library version 1.5.0 and you are also using an another library say XyzImage library. Now the XyzImage library internally depends on the android core library version 1.2.0. Now due to this your app dependency tree would look like as follow:

-- Your App
 +-> AndroidCore@1.5.0
 +-> XyzImageLibrary@1.1.0
     +-> AndroidCore@1.2.0

Now the XyzImageLibrary can configure it's gradle file in such a way that the gradle should only use the 1.2.0 version of the AndroidCore library while processing the XyzImageLibrary files. Due to this, gradle would need to download multiple version of same library. You can lookup the dependency tree of your Android App by following the solution https://stackoverflow.com/a/35235229/5309486 .

Ashok
  • 2,411
  • 1
  • 13
  • 23
  • Thank you so much for your answer, I listed the dependencies however there are many under the different titles which are `debugAndroidTestCompileClasspath`,`debugCompileClasspath`, `debugRuntimeClasspath`, `debugUnitTestCompileClasspath` and etc. Now the `debugAndroidTestCompileClasspath` and `debugCompileClasspath` has a different version of `com.google.firebase:firebase-common:19.4.0 -> 20.0.0 (c)` library. First one has a version of `19.4.0` and the second one has the one that I wrote above. How can I fix this ? Thankss – Hilal May 27 '21 at 13:51
  • And those are coming with this `com.google.firebase:firebase-bom:26.1.0` library. – Hilal May 27 '21 at 14:01
  • 1
    They are for different build variant, i.e. `debugAndroidTestCompileClasspath` means dependencies for Debug build for Android automated Test and `debugCompileClasspath` means dependencies for Debug build for source files (excluding tests). The reason for different version of firebase might be because you might have defined different firebase version for source files and android tests. – Ashok May 28 '21 at 13:49
-1

Try

plugin{
   id 'com.android.application'
   id 'com.google.gms.google-services'
 }

In you app level gradle instead of apply plugin

Izhan Ali
  • 567
  • 7
  • 17
  • when I remove the `apply plugin` I get an error like `> Could not find method android() for arguments ` – Hilal May 24 '21 at 18:58