You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android项目androidx.fragment:fragment版本异常问题求助

Android依赖冲突:FragmentActivity版本异常解析为1.0.0

升级项目依赖库后遇到版本解析异常:

  • 按依赖树分析,androidx.fragment:fragment应解析为1.5.4
  • 但在MyActivity->AppCompatActivity->FragmentActivity的依赖链中,AppCompatActivity使用androidx.appcompat:appcompat:1.5.1,FragmentActivity却绑定了androidx.fragment:fragment:1.0.0
  • 相同技术栈、依赖版本的另一个项目中,FragmentActivity解析为1.1.0

已尝试的解决方案均无效:

  • 清理项目、手动删除gradle目录中的1.0.0版本库文件
  • 显式添加implementation 'androidx.fragment:fragment-ktx:1.5.4'依赖
  • 移除shipbook依赖中的exclude group: 'androidx.fragment', module: 'fragment'配置
  • 检查gradle解析的依赖树,未发现1.0.0或1.1.0版本的fragment依赖

需要高版本的FragmentActivity以适配ComponentActivity的新特性。

当前与期望版本

  • 当前使用的FragmentActivity版本(不想要):
    ![androidx.fragment.fragment:1.0.0]
  • 需要的FragmentActivity版本:
    ![androidx.fragment.fragment:1.1.0]

顶层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
    }
}

主模块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'
}

内容的提问来源于stack exchange,提问作者masztalski

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 08:25:26