Multi-module Navigation with Architecture Components

前端 未结 3 1562
醉酒成梦
醉酒成梦 2021-01-30 21:48

So I have this structure for my modules in my current app.

I haven\'t found any official documentation on multi-module navigation yet but I found this article r

3条回答
  •  青春惊慌失措
    2021-01-30 22:24

    It is possible to remove all Gradle inter-feature dependencies when you declare each feature nav graph ID explicitly in the base feature. I am not 100% satisfied with this solution since these IDs create "hidden" inter-feature dependencies but otherwise it works fine.

    Here are the key parts of this setup:

    :app

    build.gradle

    dependencies {
        implementation project(':features:feature-base')
        implementation project(':features:feature-one')
        implementation project(':features:feature-two')
    }
    

    :features:feature-base

    build.gradle

    dependencies {
        application project(':app')
        feature project(':features:feature-one')
        feature project(':features:feature-two')
    }
    

    navigation/feature_base_nav_graph.xml

    
        
        
    
    

    values/feature_base_ids.xml

    
        
        
    
    

    :features:feature-one

    build.gradle

    dependencies {
        implementation project(':features:feature-base')
    }
    

    navigation/feature_one_nav_graph.xml

    
    
        
            
        
    
    
    

    navigate

    findNavController().navigate(R.id.navigateToFeatureTwo)
    

    :features:feature-two

    build.gradle

    dependencies {
        implementation project(':features:feature-base')
    }
    

    navigation/feature_two_nav_graph.xml

    
    
        
            
        
    
    
    

    navigate

    findNavController().navigate(R.id.navigateToFeatureOne)
    

提交回复
热议问题