Adding dependency to androidx.fragment:fragment-ktx:1.3.0-beta01 causes runtime exception

Viewed 4477

I need to add a dependency to androidx.fragment:fragment-ktx:1.3.0-beta01 in an app that uses Android navigation and dynamic features. I need the dependency to call setFragmentResult, but the app would stop working with an exception of

"no class definition found"

At runtime. Please help...

UPDATE

This is my app build gradle

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

android {
    compileSdkVersion 29

    defaultConfig {
        applicationId "it.kfi.lorikeetmobile"
        minSdkVersion 25
        targetSdkVersion 29
        versionCode 2
        versionName "1.0b"
        multiDexEnabled true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        /*javaCompileOptions {
            annotationProcessorOptions {
                arguments = [
                        "room.incremental":"true",
                        "room.expandProjection":"true"]
            }
        }*/
    }

    //kotlin DSL
//    configurations.all {
//        resolutionStrategy {
//            force("org.antlr:antlr4-runtime:4.7.1")
//            force("org.antlr:antlr4-tool:4.7.1")
//        }
//    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

// To inline the bytecode built with JVM target 1.8 into
// bytecode that is being built with JVM target 1.6. (e.g. navArgs)


    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        // Sets Java compatibility to Java 8
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }

    /*dataBinding {
        enabled = true
    }*/

    kapt { generateStubs = true }

    buildFeatures {
        dataBinding = true
        viewBinding = true
    }

    dynamicFeatures = [":jay", ":stock", ":meddler", ':goods', ':flash', ':inventory', ':harry', ':louis', ':avery']
    buildToolsVersion buildToolsVer
    //kotlin DSL
    /*configurations.all {
        resolutionStrategy {
            force("org.antlr:antlr4-runtime:4.7.1")
            force("org.antlr:antlr4-tool:4.7.1")
        }
    }*/
}

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'com.google.android.material:material:1.2.1'

    implementation 'androidx.viewpager2:viewpager2:1.0.0'

    api 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:$desugar_ver"

    api "androidx.navigation:navigation-ui-ktx:$nav_version"
    api "androidx.navigation:navigation-fragment-ktx:$nav_version"
    api "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"

    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"

    //ROOM
    kapt "androidx.room:room-runtime:$room_version"
    //kapt "android.arch.persistence.room:compiler:$room_version"
    kapt "androidx.room:room-compiler:$room_version" // For Kotlin use kapt instead of annotationProcessor

    // optional - Kotlin Extensions and Coroutines support for Room
    implementation "androidx.room:room-ktx:$room_version"
    //implementation "androidx.room:room-coroutines:$room_version"

    // optional - RxJava support for Room
    implementation "androidx.room:room-rxjava2:$room_version"

    // optional - Guava support for Room, including Optional and ListenableFuture
    implementation "androidx.room:room-guava:$room_version"

    // Test helpers
    testImplementation "androidx.room:room-testing:$room_version"


    //PAGING
    //implementation "androidx.paging:paging-runtime:$paging_version"
    implementation "androidx.paging:paging-runtime-ktx:$paging_version"

    kapt "com.android.databinding:compiler:3.1.4"

    api 'com.squareup.retrofit2:converter-gson:2.9.0'
    api 'com.squareup.retrofit2:retrofit:2.9.0'
    api 'com.squareup.okhttp3:logging-interceptor:4.9.0'

    api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

    implementation project(path: ':avatarLib')
    implementation project(path: ':ScanditCaptureCore')
    implementation project(path: ':ScanditLabelCapture')

    implementation "androidx.recyclerview:recyclerview-selection:1.1.0-rc03"
    implementation "androidx.cardview:cardview:1.0.0"
    implementation "androidx.paging:paging-runtime-ktx:$paging_version"

    implementation "androidx.fragment:fragment-ktx:1.3.0-beta01"
}

UPDATE 2

If I move the dependency from the Dynamic Feature that actually uses it to the main app (app gradle), the app doesn't start and I get the following exception:

Unable to start activity

ComponentInfo{it.kfi.lorikeetmobile/it.kfi.lorikeetmobile.ui.MainActivity}: android.view.InflateException: Binary XML file line #12: Binary XML file line #11: Error inflating class fragment

.... I do not understand what to do more

1 Answers

It looks like you need to add implementation "androidx.activity:activity-ktx:1.1.0" to your dependencies list to work

Related