Home > Software engineering >  Wrong version of androidx.fragment:fragment used
Wrong version of androidx.fragment:fragment used

Time:12-05

I have issue with performing update of libs in my project. I have bumped everything and mostly seems alright. However issue is with lib androidx.fragment:fragment. According to dependency tree it should be resolved to 1.5.4. Issue is that in tree MyActivity -> AppCompatActivity -> FragmentActivity it turns out that for AppCompatActivity androidx.appcompat:appcompat:1.5.1 is used, however for FragmentActivity androidx.fragment:fragment:1.0.0 . While inspecting another project built with same stack and same version of libs it turns out,that FragmentActivity is resolved as version 1.1.0 .

Top level gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext {
        kotlinVersion = '1.7.22'
        rxJavaVersion = '2.2.21'
        rxKotlinVersion = '2.4.0'
        rxAndroidVersion = '2.1.1'
        bindingLibraryVersion = '4.0.0'
        koinVersion = '3.1.5'
        retrofitVersion = '2.9.0'
        navComponents = "2.5.3"
        corutinesVersion = '1.6.4'
        androidLifecycleVersion = '2.5.1'
        roomVersion = '2.4.3'
        appCenterSdkVersion = '3.3.0'
        playServicesVersion = '21.0.1'
        workVersion = '2.7.1'
        firebaseBOM = '31.1.0'
        cameraxVersion = "1.1.0"
        moshiVersion = "1.13.0"
        stetho = '1.6.0'
        ZxingVersion = "3.4.1"
    }

    repositories {
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath 'com.google.gms:google-services:4.3.14'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navComponents"
    }
}

plugins {
    id "org.jetbrains.kotlin.jvm" version "$kotlinVersion"
}

allprojects {
    ext {
        androidVersionCode = getVersionCode()
        androidVersionName = getVersionName()
        storePassword = getStorePassword()
        minSdkVersion = 26
        targetSdkVersion = 31
        compileSdkVersion = 33
    }

    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
        jcenter()   //left due to shipbook. Cannot find proper repository for it
    }
}

main module gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation project(':data')

    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$androidLifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-process:$androidLifecycleVersion"

    implementation "androidx.navigation:navigation-fragment-ktx:$navComponents"
    implementation "androidx.navigation:navigation-ui-ktx:$navComponents"

    implementation 'com.google.android.material:material:1.7.0'

    implementation "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter:$bindingLibraryVersion"
    implementation "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter-recyclerview:$bindingLibraryVersion"

    implementation "io.insert-koin:koin-android:$koinVersion"
    implementation("io.insert-koin:koin-core:$koinVersion", {
        exclude group: 'androidx.lifecycle', module: 'lifecycle-extensions'
    })

    implementation "com.facebook.stetho:stetho:$stetho"
    implementation "com.facebook.stetho:stetho-okhttp3:$stetho"


    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$corutinesVersion"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${corutinesVersion}"

    // Import the BoM for the Firebase platform
    implementation platform("com.google.firebase:firebase-bom:$firebaseBOM")

    implementation "com.google.firebase:firebase-analytics-ktx"
    implementation 'com.google.firebase:firebase-dynamic-links-ktx'
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-messaging'
    implementation 'com.google.firebase:firebase-perf-ktx'
    implementation 'com.google.firebase:firebase-config-ktx'

    implementation 'com.google.android.gms:play-services-mlkit-barcode-scanning:18.1.0'
    implementation 'com.google.android.gms:play-services-mlkit-text-recognition:18.0.2'
    implementation "androidx.camera:camera-core:$cameraxVersion"
    implementation "androidx.camera:camera-camera2:$cameraxVersion"
    implementation "androidx.camera:camera-lifecycle:$cameraxVersion"
    implementation "androidx.camera:camera-view:$cameraxVersion"  //no newer version can applied for now due to issues with compatibility

    implementation "androidx.security:security-crypto:1.0.0"

    implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
    implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"

    implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
    kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion"

    implementation 'com.caverock:androidsvg-aar:1.4'
    implementation "com.google.zxing:core:$ZxingVersion"

    implementation ('io.shipbook.shipbooksdk:shipbooksdk:1.6.0', {
        exclude group: 'androidx.fragment', module: 'fragment'
    })

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
}

I have been trying cleaning project, removing from gradle directory library files for version 1.0.0 but it keeps coming back. I have no idea what to look for. I have checked dependency tree resolved by gradle but there is nothing about fragment in version 1.0.0 or 1.1.0

I need latest version of FragmentActivity to use required by me version of ComponentActivity for some of its new code.

EDIT Adding

implementation 'androidx.fragment:fragment-ktx:1.5.4'

also don't change anything. Removing suspiscious exclude for shipbook also brings nothing.

EDIT 2: this is FragmentActivity which I don't want: androidx.fragment.fragment:1.0.0

and this is which I need:

androidx.fragment.fragment:1.1.0

CodePudding user response:

Identified issue was dependencies from Firebase BOM package and Play Services Location defined in data layer (clean architecture -> layer responsible only for handling database and API connections). Solution was to exclude fragment dependency from their imports

 implementation("com.google.android.gms:play-services-location:$playServicesLocationVersion", {
        exclude group: 'androidx.fragment'
    })

    // Import the BoM for the Firebase platform
    implementation platform("com.google.firebase:firebase-bom:$firebaseBOMVersion")
    implementation('com.google.firebase:firebase-messaging', {
        exclude group: 'androidx.fragment'
    })
  • Related