Open LLin233 opened 5 years ago
@LLin233 You can create a module "navigation" and move your graph(s) there. References to Fragments will be in highlighted red but it compiles and it works.
All your feature modules can take that navigation as dependency in order to access the safeArgs (if you are using them) and the actions.
@LLin233 check my sample https://github.com/hamedsilver/ArchApp
@damienlo is this method still the preferred way? or any other better options are available now?
as an addition to @damienlo fix, you can do a "gradle hack" to share the resources between the navigation module and the app module (assuming it has access to all feature modules), this way the fragment names won't be highlighted as red. credits to @eyal-lezmy in this talk (skip to 44:00): https://www.droidcon.com/media-detail?video=334638906
android { sourceSets.debug.res.srcDirs += "$rootDir/navigation/src/main/sharedRes"}}
android { sourceSets.main.res.srcDirs += "$rootDir/navigation/src/main/sharedRes" }
If I remember well this hack is not "working" anymore with the rendent versions of Android Studio. But in our project we end up using a symbolic link to duplicate the file in both modules.
@eyal-lezmy weird, it is working correctly on our project, using the latest version of navigation component library and android studio 4.1.1.
@engi2nee Can you explaine what does it do?
@P1NG2WIN Refer the video at 44:00. It is discussed what it does behind the scenes.
damienlo I created navigation module and move all nav graphs there. Yes compilation it's ok but it gives runtime error like this:
Caused by: android.view.InflateException: Binary XML file line #52 in com.mypackage:layout/activity_main: Binary XML file line #52 in com.mypackage:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #52 in com.mypackage:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.mypackage.login.splash.SplashFragment: make sure class name exists
Android Studio Flamingo 2022.2.1 Patch 2 AGP version 8.0
https://stackoverflow.com/questions/54616996/android-navigation-component-and-bottomnavigationview-in-a-multi-module-application
I am facing extract same circumstance here... trying to create a multi-module application where every feature is a standalone library (module). Single activity pattern is applied throughout the project, created different navGraphs for different modules and included them in app's navGraph, but can't make it work.
could anyone give me some ideas? Thank you!