NoSuchMethodError for FragmentManager.getFragmentFactory












1














I'm trying to use the new FragmentScenario APIs of the androidx testing libraries but the test fails trying to launch the fragment scenario like so:



fragmentScenario = launchFragmentInContainer<MyFragment>(args)



The stacktrace is:



java.lang.NoSuchMethodError: androidx.fragment.app.FragmentManager.getFragmentFactory()Landroidx/fragment/app/FragmentFactory;

at androidx.fragment.app.testing.FragmentScenario$1.perform(FragmentScenario.java:178)
at androidx.fragment.app.testing.FragmentScenario$1.perform(FragmentScenario.java:171)
at androidx.test.core.app.ActivityScenario.lambda$onActivity$0$ActivityScenario(ActivityScenario.java:478)
at androidx.test.core.app.ActivityScenario$$Lambda$0.run(Unknown Source)
at org.robolectric.android.fakes.RoboMonitoringInstrumentation.runOnMainSync(RoboMonitoringInstrumentation.java:53)
at androidx.test.core.app.ActivityScenario.onActivity(ActivityScenario.java:471)
at androidx.fragment.app.testing.FragmentScenario.internalLaunch(FragmentScenario.java:170)
at androidx.fragment.app.testing.FragmentScenario.launchInContainer(FragmentScenario.java:160)
at com.domain.myapp.ui.pck.pkg.MyFragmentTest.setup(MyFragmentTest.kt:656)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)


If I go the FragmentManager class (androidx.fragment.app FragmentManager) there is no getFragmentFactory method and the FragmentScenario.java class (package androidx.fragment.app.testing) clearly shows that the method does not exist:
See image



I'm guessing my dependencies are configured incorrectly, this is my app/build.gradle file:



android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.domain.app"
minSdkVersion 21
targetSdkVersion 28
versionCode appVersionCode
versionName appVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
abortOnError false
}
testOptions {
unitTests {
includeAndroidResources true
returnDefaultValues true
}
}
}

dependencies {
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "androidx.appcompat:appcompat:1.0.0"

testImplementation "junit:junit:4.12"
testImplementation "org.mockito:mockito-core:2.7.1"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.0.0-RC1"
testImplementation "androidx.test:core:1.0.0"
testImplementation "org.robolectric:robolectric:4.0.2"
testImplementation "org.robolectric:shadows-support-v4:3.0"
testImplementation "androidx.fragment:fragment-testing:1.1.0-alpha01"
testImplementation 'androidx.test:runner:1.1.0'
testImplementation 'androidx.test:rules:1.1.0'
testImplementation "androidx.test.ext:junit:1.0.0"
testImplementation "androidx.test.espresso:espresso-intents:3.1.0"
testImplementation "androidx.test.espresso:espresso-core:3.1.0"
testImplementation "androidx.test.ext:truth:1.0.0"
}









share|improve this question



























    1














    I'm trying to use the new FragmentScenario APIs of the androidx testing libraries but the test fails trying to launch the fragment scenario like so:



    fragmentScenario = launchFragmentInContainer<MyFragment>(args)



    The stacktrace is:



    java.lang.NoSuchMethodError: androidx.fragment.app.FragmentManager.getFragmentFactory()Landroidx/fragment/app/FragmentFactory;

    at androidx.fragment.app.testing.FragmentScenario$1.perform(FragmentScenario.java:178)
    at androidx.fragment.app.testing.FragmentScenario$1.perform(FragmentScenario.java:171)
    at androidx.test.core.app.ActivityScenario.lambda$onActivity$0$ActivityScenario(ActivityScenario.java:478)
    at androidx.test.core.app.ActivityScenario$$Lambda$0.run(Unknown Source)
    at org.robolectric.android.fakes.RoboMonitoringInstrumentation.runOnMainSync(RoboMonitoringInstrumentation.java:53)
    at androidx.test.core.app.ActivityScenario.onActivity(ActivityScenario.java:471)
    at androidx.fragment.app.testing.FragmentScenario.internalLaunch(FragmentScenario.java:170)
    at androidx.fragment.app.testing.FragmentScenario.launchInContainer(FragmentScenario.java:160)
    at com.domain.myapp.ui.pck.pkg.MyFragmentTest.setup(MyFragmentTest.kt:656)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)


    If I go the FragmentManager class (androidx.fragment.app FragmentManager) there is no getFragmentFactory method and the FragmentScenario.java class (package androidx.fragment.app.testing) clearly shows that the method does not exist:
    See image



    I'm guessing my dependencies are configured incorrectly, this is my app/build.gradle file:



    android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    defaultConfig {
    applicationId "com.domain.app"
    minSdkVersion 21
    targetSdkVersion 28
    versionCode appVersionCode
    versionName appVersionName
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    vectorDrawables {
    useSupportLibrary true
    }
    }
    aaptOptions {
    additionalParameters "--no-version-vectors"
    }
    buildTypes {
    debug {
    applicationIdSuffix ".debug"
    }
    }
    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }
    lintOptions {
    abortOnError false
    }
    testOptions {
    unitTests {
    includeAndroidResources true
    returnDefaultValues true
    }
    }
    }

    dependencies {
    implementation "androidx.legacy:legacy-support-v4:1.0.0"
    implementation "androidx.appcompat:appcompat:1.0.0"

    testImplementation "junit:junit:4.12"
    testImplementation "org.mockito:mockito-core:2.7.1"
    testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.0.0-RC1"
    testImplementation "androidx.test:core:1.0.0"
    testImplementation "org.robolectric:robolectric:4.0.2"
    testImplementation "org.robolectric:shadows-support-v4:3.0"
    testImplementation "androidx.fragment:fragment-testing:1.1.0-alpha01"
    testImplementation 'androidx.test:runner:1.1.0'
    testImplementation 'androidx.test:rules:1.1.0'
    testImplementation "androidx.test.ext:junit:1.0.0"
    testImplementation "androidx.test.espresso:espresso-intents:3.1.0"
    testImplementation "androidx.test.espresso:espresso-core:3.1.0"
    testImplementation "androidx.test.ext:truth:1.0.0"
    }









    share|improve this question

























      1












      1








      1







      I'm trying to use the new FragmentScenario APIs of the androidx testing libraries but the test fails trying to launch the fragment scenario like so:



      fragmentScenario = launchFragmentInContainer<MyFragment>(args)



      The stacktrace is:



      java.lang.NoSuchMethodError: androidx.fragment.app.FragmentManager.getFragmentFactory()Landroidx/fragment/app/FragmentFactory;

      at androidx.fragment.app.testing.FragmentScenario$1.perform(FragmentScenario.java:178)
      at androidx.fragment.app.testing.FragmentScenario$1.perform(FragmentScenario.java:171)
      at androidx.test.core.app.ActivityScenario.lambda$onActivity$0$ActivityScenario(ActivityScenario.java:478)
      at androidx.test.core.app.ActivityScenario$$Lambda$0.run(Unknown Source)
      at org.robolectric.android.fakes.RoboMonitoringInstrumentation.runOnMainSync(RoboMonitoringInstrumentation.java:53)
      at androidx.test.core.app.ActivityScenario.onActivity(ActivityScenario.java:471)
      at androidx.fragment.app.testing.FragmentScenario.internalLaunch(FragmentScenario.java:170)
      at androidx.fragment.app.testing.FragmentScenario.launchInContainer(FragmentScenario.java:160)
      at com.domain.myapp.ui.pck.pkg.MyFragmentTest.setup(MyFragmentTest.kt:656)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)


      If I go the FragmentManager class (androidx.fragment.app FragmentManager) there is no getFragmentFactory method and the FragmentScenario.java class (package androidx.fragment.app.testing) clearly shows that the method does not exist:
      See image



      I'm guessing my dependencies are configured incorrectly, this is my app/build.gradle file:



      android {
      compileSdkVersion 28
      buildToolsVersion '28.0.3'
      defaultConfig {
      applicationId "com.domain.app"
      minSdkVersion 21
      targetSdkVersion 28
      versionCode appVersionCode
      versionName appVersionName
      testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
      vectorDrawables {
      useSupportLibrary true
      }
      }
      aaptOptions {
      additionalParameters "--no-version-vectors"
      }
      buildTypes {
      debug {
      applicationIdSuffix ".debug"
      }
      }
      compileOptions {
      sourceCompatibility JavaVersion.VERSION_1_8
      targetCompatibility JavaVersion.VERSION_1_8
      }
      lintOptions {
      abortOnError false
      }
      testOptions {
      unitTests {
      includeAndroidResources true
      returnDefaultValues true
      }
      }
      }

      dependencies {
      implementation "androidx.legacy:legacy-support-v4:1.0.0"
      implementation "androidx.appcompat:appcompat:1.0.0"

      testImplementation "junit:junit:4.12"
      testImplementation "org.mockito:mockito-core:2.7.1"
      testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.0.0-RC1"
      testImplementation "androidx.test:core:1.0.0"
      testImplementation "org.robolectric:robolectric:4.0.2"
      testImplementation "org.robolectric:shadows-support-v4:3.0"
      testImplementation "androidx.fragment:fragment-testing:1.1.0-alpha01"
      testImplementation 'androidx.test:runner:1.1.0'
      testImplementation 'androidx.test:rules:1.1.0'
      testImplementation "androidx.test.ext:junit:1.0.0"
      testImplementation "androidx.test.espresso:espresso-intents:3.1.0"
      testImplementation "androidx.test.espresso:espresso-core:3.1.0"
      testImplementation "androidx.test.ext:truth:1.0.0"
      }









      share|improve this question













      I'm trying to use the new FragmentScenario APIs of the androidx testing libraries but the test fails trying to launch the fragment scenario like so:



      fragmentScenario = launchFragmentInContainer<MyFragment>(args)



      The stacktrace is:



      java.lang.NoSuchMethodError: androidx.fragment.app.FragmentManager.getFragmentFactory()Landroidx/fragment/app/FragmentFactory;

      at androidx.fragment.app.testing.FragmentScenario$1.perform(FragmentScenario.java:178)
      at androidx.fragment.app.testing.FragmentScenario$1.perform(FragmentScenario.java:171)
      at androidx.test.core.app.ActivityScenario.lambda$onActivity$0$ActivityScenario(ActivityScenario.java:478)
      at androidx.test.core.app.ActivityScenario$$Lambda$0.run(Unknown Source)
      at org.robolectric.android.fakes.RoboMonitoringInstrumentation.runOnMainSync(RoboMonitoringInstrumentation.java:53)
      at androidx.test.core.app.ActivityScenario.onActivity(ActivityScenario.java:471)
      at androidx.fragment.app.testing.FragmentScenario.internalLaunch(FragmentScenario.java:170)
      at androidx.fragment.app.testing.FragmentScenario.launchInContainer(FragmentScenario.java:160)
      at com.domain.myapp.ui.pck.pkg.MyFragmentTest.setup(MyFragmentTest.kt:656)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)


      If I go the FragmentManager class (androidx.fragment.app FragmentManager) there is no getFragmentFactory method and the FragmentScenario.java class (package androidx.fragment.app.testing) clearly shows that the method does not exist:
      See image



      I'm guessing my dependencies are configured incorrectly, this is my app/build.gradle file:



      android {
      compileSdkVersion 28
      buildToolsVersion '28.0.3'
      defaultConfig {
      applicationId "com.domain.app"
      minSdkVersion 21
      targetSdkVersion 28
      versionCode appVersionCode
      versionName appVersionName
      testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
      vectorDrawables {
      useSupportLibrary true
      }
      }
      aaptOptions {
      additionalParameters "--no-version-vectors"
      }
      buildTypes {
      debug {
      applicationIdSuffix ".debug"
      }
      }
      compileOptions {
      sourceCompatibility JavaVersion.VERSION_1_8
      targetCompatibility JavaVersion.VERSION_1_8
      }
      lintOptions {
      abortOnError false
      }
      testOptions {
      unitTests {
      includeAndroidResources true
      returnDefaultValues true
      }
      }
      }

      dependencies {
      implementation "androidx.legacy:legacy-support-v4:1.0.0"
      implementation "androidx.appcompat:appcompat:1.0.0"

      testImplementation "junit:junit:4.12"
      testImplementation "org.mockito:mockito-core:2.7.1"
      testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.0.0-RC1"
      testImplementation "androidx.test:core:1.0.0"
      testImplementation "org.robolectric:robolectric:4.0.2"
      testImplementation "org.robolectric:shadows-support-v4:3.0"
      testImplementation "androidx.fragment:fragment-testing:1.1.0-alpha01"
      testImplementation 'androidx.test:runner:1.1.0'
      testImplementation 'androidx.test:rules:1.1.0'
      testImplementation "androidx.test.ext:junit:1.0.0"
      testImplementation "androidx.test.espresso:espresso-intents:3.1.0"
      testImplementation "androidx.test.espresso:espresso-core:3.1.0"
      testImplementation "androidx.test.ext:truth:1.0.0"
      }






      android android-espresso android-testing robolectric androidx






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 7:20









      Jorge Gil

      357212




      357212
























          1 Answer
          1






          active

          oldest

          votes


















          2














          Your application needs to depend on fragment:1.1.0-alpha01 via an implementation dependency - legacy-support-v4-:1.0.0 and appcompat:1.0.0 only depend on fragment:1.0.0:



          implementation "androidx.fragment:fragment:1.1.0-alpha01"





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442211%2fnosuchmethoderror-for-fragmentmanager-getfragmentfactory%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            Your application needs to depend on fragment:1.1.0-alpha01 via an implementation dependency - legacy-support-v4-:1.0.0 and appcompat:1.0.0 only depend on fragment:1.0.0:



            implementation "androidx.fragment:fragment:1.1.0-alpha01"





            share|improve this answer


























              2














              Your application needs to depend on fragment:1.1.0-alpha01 via an implementation dependency - legacy-support-v4-:1.0.0 and appcompat:1.0.0 only depend on fragment:1.0.0:



              implementation "androidx.fragment:fragment:1.1.0-alpha01"





              share|improve this answer
























                2












                2








                2






                Your application needs to depend on fragment:1.1.0-alpha01 via an implementation dependency - legacy-support-v4-:1.0.0 and appcompat:1.0.0 only depend on fragment:1.0.0:



                implementation "androidx.fragment:fragment:1.1.0-alpha01"





                share|improve this answer












                Your application needs to depend on fragment:1.1.0-alpha01 via an implementation dependency - legacy-support-v4-:1.0.0 and appcompat:1.0.0 only depend on fragment:1.0.0:



                implementation "androidx.fragment:fragment:1.1.0-alpha01"






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 8:14









                ianhanniballake

                103k14214227




                103k14214227






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442211%2fnosuchmethoderror-for-fragmentmanager-getfragmentfactory%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Catalogne

                    Violoncelliste

                    Héron pourpré