Unresolved reference for import androidx.fragment.app.testing.FragmentScenario

Viewed 942

as mentioned in here to use FragmentScenario for testing fragments I add the dependency :

debugImplementation "androidx.fragment:fragment-testing:1.3.2"

but I can't call anything from this library and android studio doesn't know them . there is no access to EmptyFragmentActivity or launchFragmentInContainer .

1 Answers

You need to define Google's Maven Repository in build.gradle first:

allprojects {
    repositories {
        google()

        // If you're using a version of Gradle lower than 4.1, you must instead use:
        // maven {
        //     url 'https://maven.google.com'
        // }
        // An alternative URL is 'https://dl.google.com/dl/android/maven2/'
    }
}

And also your mentioned dependencies for the proper programming language:

dependencies {
    def fragment_version = "1.3.2"

    // Java language implementation
    implementation "androidx.fragment:fragment:$fragment_version"
    // Kotlin
    implementation "androidx.fragment:fragment-ktx:$fragment_version"
    // Testing Fragments in Isolation
    debugImplementation "androidx.fragment:fragment-testing:$fragment_version"
}
Related