question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

launchFragmentInHiltContainer does not appear to work with the 1.2.0-beta02 of androidx.activity/androidx.fragment: "Cannot access 'EmptyFragmentActivity': it is internal in 'FragmentScenario'"

See original GitHub issue

After updating androidx.activity:activity-ktx and androidx.fragment:fragment-ktx to 1.2.0-beta02 from 1.2.0-beta01, the launchFragmentInHiltContainer code example found here and recommended here does not appear to work.

Cannot access 'EmptyFragmentActivity': it is internal in 'FragmentScenario' e: /home/runner/work/libraries/test-config/src/debug/java/com/xxx/test_config/HiltExtensions.kt: (25, 42): Public-API inline function cannot access non-public-API 'public const final val THEME_EXTRAS_BUNDLE_KEY: String defined in androidx.fragment.app.testing.FragmentScenario.EmptyFragmentActivity.Companion' Task :libraries:test-config:compileDevDebugKotlin FAILED

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

25reactions
manuelvicntcommented, Dec 11, 2020

I can replicate using fragment-ktx 1.3.0-beta2. As suspected, it’s because EmptyFragmentActivity is now internal.

If you don’t need to pass in your own theme, then remove themeResId from the parameters of the function and the .putExtra lines of the startActivityIntent.

If you need it, then use the fully qualified key that you can find in the implementation of EmptyFragmentActivity. i.e.

val startActivityIntent = Intent.makeMainActivity(
    ComponentName(
        ApplicationProvider.getApplicationContext(),
        HiltTestActivity::class.java
    )
).putExtra(
    "androidx.fragment.app.testing.FragmentScenario.EmptyFragmentActivity.THEME_EXTRAS_BUNDLE_KEY",
    themeResId
)

That’s a nasty workaround but that’s all we can do for now

1reaction
manuelvicntcommented, Dec 9, 2020

The architecture-samples project use the stable version of androidx.fragment:fragment-ktx:1.2.0. As you’re using a lower version, I’d suggest modifying the launchFragmentInHiltContainer yourself. Remove the themeResId param (line 40) and the putExtra method that sets it (line 48).

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

FragmentScenario.EmptyFragmentActivity isn't available in ...
When I wanted to implement this method for creating an annotated activity for hilt testing I faced not accessing the EmptyFragmentActivity.
Read more >
Test your fragments - Android Developers
FragmentScenario includes the following methods for launching fragments in tests: launchInContainer() , for testing a fragment's user interface.
Read more >
fragment/fragment-testing/src/main/java/androidx ... - Google Git
you may not use this file except in compliance with the License. ... FragmentScenario<F> = launchFragment(fragmentArgs, themeResId) {. instantiate(). }.
Read more >
Fragment Scenario has no way to trigger ... - Issue Tracker
Component used: Fragment Version used: 1.1.0-alpha02. Devices/Android versions reproduced on: emulator. I am trying to test that a menu option is enabled or ......
Read more >
Testing Fragments with Dagger-Hilt - Part 12 - YouTube
In this video I will show you a workaround to be able to test fragments with the help of Dagger-Hilt.⭐ Get certificates for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found