launchFragmentInContainer<MyFragment> causing compile error in task app:compileDebugAndroidTestKotlin

23 Views Asked by At

Two errors but the first is the most strange, it says:

Cannot access class 'androidx.fragment.app.FragmentFactory'. Check your module classpath for missing or conflicting dependencies

The second error: Type argument is not within its bounds: should be subtype of 'Fragment'

I've tried checking for missing dependencies and other stuff but i'm blocked.

This is my test class:

@RunWith(AndroidJUnit4::class)
class FiltersFragmentTest {

    @Before
    fun init() {
        launchFragmentInContainer<FiltersFragment>(themeResId = R.style.B4workTheme)
    }
}

This is my build.gradle file. I've tested and this method is working in the branch master that uses a old build.gradle file with gradle 4.x plugin and the android 33 target version, but i tried to downgrade plugin to 7.x and 33 version and still not works. I tried also to clean gradlew command and check dependencies. There is a fragment:1.0.0 dependency included in my project but i don't find where is included because in app:dependencies command I see this dependency always updated to 1.6.2 version automatically by gradle. This is the only clue I have because this version (1.0.0) does not have this class

android {
    compileSdk 34
    defaultConfig {
        minSdkVersion 22
        targetSdkVersion 34
        applicationId "my.id"
        versionCode 299
        versionName "5.11.0"
        renderscriptTargetApi 25
        renderscriptSupportModeEnabled true

        multiDexEnabled true
        manifestPlaceholders = [gcm_sender_id        : getGCMSenderId(properties),
                                fbAppId              : getFacebookAppId(properties),
                                fbLoginProtocolScheme: getFacebookLoginProtocolScheme(properties)]

        resValue "string", "google_client_id", getGoogleClientId(properties)
        resValue "string", "deeplink_validate_path", deeplinks.validate

        //Instrumentation testing setup
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        vectorDrawables.useSupportLibrary = true
    }

    sourceSets {
        androidTest {
            java.srcDirs += 'src/androidTest/java'
        }
    }

    kapt {
        generateStubs = true
        mapDiagnosticLocations = true
    }

    buildFeatures {
        dataBinding true
        viewBinding true
        buildConfig true
    }

    useLibrary 'org.apache.http.legacy'
    def propertiesFile = rootProject.file('local.properties')
    def properties = new Properties()
    properties.load(new FileInputStream(propertiesFile))
    println(properties.getProperty("prepro.key.alias"))
    println(properties.getProperty("prepro.key.password"))
    println(properties.getProperty("prepro.store.path"))
    println(properties.getProperty("prepro.store.password"))
    signingConfigs {
        release {
            keyAlias properties.getProperty("prepro.key.alias")
            keyPassword properties.getProperty("prepro.key.password")
            storeFile file(properties.getProperty("prepro.store.path"))
            storePassword properties.getProperty("prepro.store.password")
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            defaultConfig {
                manifestPlaceholders = [manifestApplicationId: "${applicationId}"]
            }
        }

        debug {
            applicationIdSuffix '.debug'
            signingConfig signingConfigs.debug
            debuggable true
            testCoverageEnabled false
            minifyEnabled false
            defaultConfig {
                manifestPlaceholders = [manifestApplicationId: "${applicationId}"]
            }
        }
    }

    // Always show the result of every unit test, even if it passes.
    testOptions.unitTests.all {
        testLogging {
            events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
        }
    }
    bundle {
        language {
            enableSplit = false
        }
        density {
            enableSplit = true
        }
        abi {
            enableSplit = true
        }
    }
}

kotlin {
    jvmToolchain(17)
}

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

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

    //AndroidX
    implementation "androidx.core:core-ktx:1.5.0"
    implementation "androidx.appcompat:appcompat:$androidx_version"
    implementation "androidx.constraintlayout:constraintlayout:2.1.4"
    implementation 'androidx.recyclerview:recyclerview:1.3.2'
    implementation "androidx.cardview:cardview:1.0.0"
    implementation 'androidx.fragment:fragment-ktx:1.6.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "androidx.legacy:legacy-support-core-utils:1.0.0"
    implementation "androidx.percentlayout:percentlayout:1.0.0"
    implementation 'androidx.exifinterface:exifinterface:1.3.2'
    implementation 'com.google.android.material:material:1.3.0'
    implementation("androidx.core:core-splashscreen:1.0.1")

    //DI
    implementation "org.koin:koin-android:$koin_version"
    implementation "org.koin:koin-android-scope:$koin_version"
    implementation "org.koin:koin-android-viewmodel:$koin_version"

    //Lifecycle
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.0"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0"
    implementation "androidx.lifecycle:lifecycle-runtime:2.4.0"

    //Navigation
    implementation "androidx.navigation:navigation-fragment-ktx:2.4.0"
    implementation "androidx.navigation:navigation-ui-ktx:2.4.0"
    implementation 'com.ncapdevi:frag-nav:3.2.0'

    //Redux
    implementation "org.rekotlin:rekotlin:$rekotlin_version"

    //Async - Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

    //Async - Rx
    //Async libraries

    //Network
    //Some libraries...

    //GCM
    // Some libraries...

    //Firebase
    // ..some libraries

    //Utilities
    implementation 'androidx.test.espresso:espresso-idling-resource:3.4.0'

    // TESTING LIBRARIES
    // Unit Testing (test folder)
    testImplementation("androidx.test.ext:junit:1.1.5")
    testImplementation "io.mockk:mockk:1.12.4"
    testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.3'
    testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3'
    testImplementation 'junit:junit:4.12'

    // Instrumented test (androidTest folder)
    androidTestImplementation("androidx.test:core-ktx:1.5.0")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation "androidx.test:runner:1.5.2"
    androidTestImplementation "androidx.test:rules:1.5.0"
    debugImplementation("androidx.fragment:fragment-testing:1.6.2")
    // Optional -- UI testing with Espresso
    androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
}

android {

    packagingOptions {
        resources {
            excludes += ['org/apache/http/version.properties', 'org/apache/http/client/version.properties', 'org/apache/http/entity/mime/version.properties', 'org/apache/http/entity/mime/version.properties', 'META-INF/INDEX.LIST', 'META-INF/io.netty.versions.properties', 'META-INF/DEPENDENCIES', 'META-INF/NOTICE', 'META-INF/LICENSE']
        }
    }
}

/*
All direct/transitive dependencies shared between your test and production APKs need to be
excluded from the test APK! This is necessary because both APKs will contain the same classes. Not
excluding these dependencies from your test configuration will result in an dex pre-verifier error
at runtime. More info in this tools bug: (https://code.google.com/p/android/issues/detail?id=192497)
*/
configurations.implementation.dependencies.each { compileDependency ->
    println "Excluding compile dependency: ${compileDependency.getName()}"
    configurations.androidTestImplementation.dependencies.each {
        androidTestCompileDependency -> configurations.androidTestImplementation.exclude module: "${compileDependency.getName()}"
    }
}

apply plugin: 'com.google.gms.google-services'
repositories {
    mavenCentral()
}

I think it should be a dependency classpath conflict but I don't know how to find it

0

There are 0 best solutions below