Error
Unable to instantiate fragment androidx.navigation.fragment.NavHostFragment: make sure class name exists, is public, and has an empty constructor that is public.
ActivityLayout
<fragment
android:id="@+id/my_nav_host_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="androidx.navigation.fragment.NavHostFragment"
app:defaultNavHost="true"
app:navGraph="@navigation/app_nav" />
Activity
class HomeActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
}
}
Fragment
class MovieListFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_movie_list, container, false)
}
}
Dependency Used:
implementation('android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha07') {
exclude group: "com.android.support"
}
implementation('android.arch.navigation:navigation-ui-ktx:1.0.0-alpha07') {
exclude group: "com.android.support"
}
If its happening only on the proguarded version, you might have forgotten to add the proguard rule. Add the below rule in your proguard file
-keepnames class androidx.navigation.fragment.NavHostFragment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With