No View Found for ID (dynamic feature module)

278 views Asked by At

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

0

There are 0 answers