Is it possible use different navigation graph with different flavours
Asked Answered
T

1

9

I have an Android project with three flavour_a , flavour_b and flavour_c. flavour_a and flavour_b using the same navigation graph. For flavour_c workflow is different means only need to use a subset of fragments.

Is it possible to use a different navigation graph with existing fragments and source code.

I tried a new navigation graph with existing fragment but failed with error:

AAPT: error: resource id/splashFragment (aka com.sample.app:id/splashFragment) not found.

Source folder structure

-- main
   -- src
   -- res
      -- navigation
         --navigation_graph.xml
-- flavour_c
   --res
     --navigation
         --navigation_graph.xml
Tonry answered 11/11, 2020 at 7:0 Comment(0)
I
0

I had the same issue, I worked it around with dublicating my main activity xml file, which holds the NavHostFragment with a navGraph attached to it. So in my flavor copy of activity xml I pointed NavHostFragment to my copy of nav_graph.xml and it seems working.

Main flavor:

-- main
    -- res
    -- activity_main.xml
    <fragment
        android:name="androidx.navigation.fragment.NavHostFragment"
        ...
        app:navGraph="@navigation/nav_graph" />

Other flavor:
-- flavor1
  -- res
     -- activity_main.xml
    <fragment
        android:name="androidx.navigation.fragment.NavHostFragment"
        ...
        app:navGraph="@navigation/nav_graph_flavor1" />
Imparadise answered 27/10, 2022 at 11:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.