0

I have a dynamic feature module with an activity that I'm trying to launch. However, I keep getting this error:

java.lang.IllegalArgumentException: No view found for id 0x81020009 (com.example.dynamicFeatureModule/fragment_container) for fragment MyFragment{49b6ef} (ae09d134-2898-4fd5-9d39-33f371b57e74 id=0x81020009)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:513)
        at

The weird thing is, I am able to access a string using R.string. so not sure why the layout and the id are behaving differently.

class MyActivity : FragmentActivity() {

    override fun attachBaseContext(newBase: Context?) {
        super.attachBaseContext(newBase)
        // Emulates installation of on demand modules using SplitCompat.
        SplitCompat.installActivity(this)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.my_activity)

        val str = getString(R.string.my_string) // this is fine

        supportFragmentManager
            .beginTransaction()
            .add(
                R.id.fragment_container,
                MyFragment::class.java,
            )
            .commit()
    }
}

This is my my_activity.xml layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="visible" />

In my base application class, I have:

@Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        // Emulates installation of future on demand modules using SplitCompat.
        SplitCompat.install(this);
    }

What am I missing?

Update: Filed a bug with Google https://issuetracker.google.com/issues/230101698

VIN
  • 6,385
  • 7
  • 38
  • 77
  • I was able to get this working by placing my layout in another module, and importing it like `com.example.othermodule.R.layout.my_activity` and `com.example.othermodule.R.id.fragment_container` but not sure why I have to do that – VIN Apr 22 '22 at 22:06
  • This could be a bug with the AndroidX Fragment library. Updating to 1.4.1 might fix this: https://stackoverflow.com/a/71986621/4138919 – VIN Apr 26 '22 at 02:20

0 Answers0