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
Zoe
  • 27,060
  • 21
  • 118
  • 148
CLIFFORD P Y
  • 16,974
  • 6
  • 30
  • 45

1 Answers1

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" />
Kaspis
  • 73
  • 5