codelab-android-navigation icon indicating copy to clipboard operation
codelab-android-navigation copied to clipboard

Different navigation graph for different flavors

Open Pavel-2705 opened this issue 3 years ago • 2 comments
trafficstars

I have an Android project with two flavor_a, flavor_b. flavor_a and flavor_b share common snippets for navigation, but also have a few differences in their workflow. These are different means, you only need to use one fragment instead of the other (the differences are in 2 fragments out of 5)

I tried to create 2 graph for 2 flavor with the same name, but ids didn't generate. Is it possible to use a different navigation graph with existing fragments and source code?

Source folder structure
-- main   
   -- common fragment_1   
   -- common fragment_2   
   -- common fragment_3   
 --res
    (without graph)
-- flavor_a
   -- src
     -- fragment_a
   -- res
      -- navigation
         --navigation_graph.xml
-- flavor_b
  -- src
    -- fragment_b
   --res
     --navigation
         --navigation_graph.xml

Common issue at stackoverflow: https://stackoverflow.com/questions/64781855/is-it-possible-use-different-navigation-graph-with-different-flavours

Pavel-2705 avatar Jan 05 '22 16:01 Pavel-2705

I don't know if it's the same case as mine, but i was able to resolve this problem.

In my case I want in flavor A destination should launch Fragment A and other flavor launch FragmentB I duplicated the navigation file and for the same navigation Id , let's say destination R.id.navigation_some_screen i just changed to name of fragment to launch in the two file.

I think using navigation programmatically or in compose navigation it's more easy to do this and more clean without duplicating resource files.

Hope this help some one.

issamux avatar Jul 01 '22 21:07 issamux

邮件已经收到了,谢谢!

mtf7101520 avatar Jul 01 '22 21:07 mtf7101520