raamcosta / compose-destinations

Annotation processing library for type-safe Jetpack Compose navigation with no boilerplate.
https://composedestinations.rafaelcosta.xyz
Apache License 2.0
3.14k stars 129 forks source link

ModuleDestinations$Includes is defined multiple times in Multi-Module project #623

Closed Velord closed 1 month ago

Velord commented 2 months ago

Btw I use "2.1.0-beta02".

com.ramcosta.composedestinations.generated.ModuleDestinations$Includes is defined multiple times: ProjectPath\ui\feature-settings\build\.transforms\2d944e4462518b939e46cbbcdcc610c7\transformed\bundleLibRuntimeToDirDebug\com\ramcosta\composedestinations\generated\ModuleDestinations$Includes.dex, ProjectPath\ui\feature-bottomnavigation\build\.transforms\12913506a8e8a347cda5275057060a14\transformed\bundleLibRuntimeToDirDebug\com\ramcosta\composedestinations\generated\ModuleDestinations$Includes.dex

I have app module which defines all graphs.

DestinationsNavHost(
    navGraph = NavGraphs.mainNavGraph,
    dependenciesContainerBuilder = {
        dependency(CoreFeatureNavigator(navController = navController))
   }
)

private const val MAIN_GRAPH = "main_nav_graph"
@NavHostGraph(
    defaultTransitions = DefaultTransitions::class,
    route = MAIN_GRAPH,
    visibility = CodeGenVisibility.INTERNAL
)
annotation class MainGraph {
    @ExternalDestination<BottomNavigationDestinationsScreenDestination>(start = true)
    companion object Includes
}

class CoreFeatureNavigator(
    private val navController: NavController
) : BottomNavigator {

    override fun getRoute(route: BottomNavigationDestination): DestinationSpec = when(route) {
        BottomNavigationDestination.Camera -> CameraScreenDestination
        BottomNavigationDestination.Demo -> DemoScreenDestination
        BottomNavigationDestination.Settings -> SettingsScreenDestination
    }

    override fun getGraph(): NavHostGraphSpec = NavGraphs.bottomNavigationGraph
}

private const val BOTTOM_NAVIGATION_GRAPH = "bottom_navigation_graph"
@NavHostGraph(route = BOTTOM_NAVIGATION_GRAPH)
annotation class BottomNavigationGraph {
    @ExternalDestination<SettingsScreenDestination>
    companion object FF // trying to rename -> does not help
}

@Composable
private fun TestStackScreen() {
...

@Destination<BottomNavigationGraph>(start = true)
@Composable
fun CameraScreen() {
...

@Destination<BottomNavigationGraph>()
@Composable
fun DemoScreen() {
...

Also bottomnavigation module which defines destination:

interface BottomNavigator {
    fun getRoute(route: BottomNavigationDestination): DestinationSpec
    fun getGraph(): NavHostGraphSpec
}

enum class BottomNavigationDestination {
    Camera,
    Demo,
    Settings;
}

@Destination<ExternalModuleGraph>()
@Composable
fun BottomNavigationDestinationsScreen(
    navigator: BottomNavigator
) {

I am trying to split destinations that belong to bottom navigation graph to different modules. First step is to move 'settings' destination to different module. Exactly at this step error occurs.
My settingsmodule has:

@Destination<ExternalModuleGraph>
@Composable
fun SettingsScreen() {
...
  1. I was trying to rename companion object in BottomNavigationGraph.
  2. I added arg("compose-destinations.moduleName", "settings") and arg("compose-destinations.moduleName", "bottom"). Error occurs in that case: [ksp] com.ramcosta.composedestinations.codegen.commons.IllegalDestinationsSetup: Check com.google.devtools.ksp.symbol.NonExistLocation@3d60ec1b for unresolved symbols.
  3. Also I was trying to add arg("compose-destinations.codeGenPackageName", xxxxx.settings") and arg("compose-destinations.codeGenPackageName", "xxxxx.bottom"). Error occurs in that case: [ksp] com.ramcosta.composedestinations.codegen.commons.IllegalDestinationsSetup: Check com.google.devtools.ksp.symbol.NonExistLocation@41e0988e for unresolved symbols.
raamcosta commented 1 month ago

Hi! 👋

You want to go with your try 2:

After that try again and let me know!

Velord commented 1 month ago

I added to all modules arg("compose-destinations.moduleName", "moduleX") where X is unique name for certain module. After that I received an error on build: e: file:///D:/Android%20Project/ComposeScreenExample/app/build/generated/ksp/developDebug/kotlin/com/ramcosta/composedestinations/generated/moduleapp/navargs/ArgsToSavedStateHandle.kt:6:74 Unresolved reference: navargs

Screenshot_1

raamcosta commented 1 month ago

Issue was reported here and is already fixed.

https://github.com/raamcosta/compose-destinations/issues/631

Will be up soon today.

Velord commented 1 month ago

Thanks, will be waiting