[Closed] Compilations errors if i remove a log.d statement in composables

Good morning everyone,

I’m currently developing a kotlin/compose mobile app and i’m completely lost with the error i got.
My app works fine and i’m trying to clean up my code (removing logs, and things i tried but don’t use and so on).

I’m using NavHost with different composables

NavHost(
    navController = navController,
    startDestination = MarketScreen.Start.name,
    modifier = Modifier
        .fillMaxSize()
        //.verticalScroll(rememberScrollState())
        .padding(innerPadding)
) {
    composable(route = MarketScreen.Start.name) {
        HomeScreen(
            title = stringResource(R.string.home),
            subscriptionStatusRequestState = subscriptionViewModel.subscriptionStatusRequestState,
            qonversionViewModel = qonversionViewModel,
            onSubscribeClick = { navController.navigate(MarketScreen.Subscription.name) },
            onMenuClick = {
                scope.launch {
                    drawerState.open()
                }
            },
            drawerState = drawerState,
            authState = authState
        )
    }

    composable(route = MarketScreen.Subscription.name) {
        SubscriptionScreen(
            activity = activity,
            qonversionViewModel = qonversionViewModel,
            onBackClick = { navController.navigateUp() }
        )
    }

    composable(route = MarketScreen.ProductScreener.name) {
        ProductScreenerScreen(
            productScreenerViewModel = productScreenerViewModel,
            title = stringResource(id = R.string.product_screener),
            onMenuClick = {
                scope.launch {
                    drawerState.open()
                }
            },
            onSearchClick = {
                productScreenerViewModel.fetchData()
                navController.navigate(MarketScreen.ProductList.name)
            },
            onFilterClick = { productScreenerViewModel.onFilterClick() },
            onResetClick = { productScreenerViewModel.resetFilters() },
            onBackClick = {
                productScreenerViewModel.resetFilters()
                navController.navigateUp()
            }
        )
    }

    composable(route = MarketScreen.Search.name) {
        TopBarProductScreen(
            userInput = productScreenViewModel.searchedInput.collectAsState().value,
            displayedProducts = productScreenViewModel.displayedProductUiState.collectAsState().value,
            onUserInputChanged = { productScreenViewModel.onUserInputChanged(it) },
            onMenuClick = {
                scope.launch {
                    drawerState.open()
                }
            },
            onSearchClick = {
                productScreenViewModel.getDetailsByProductCode(productScreenViewModel.searchedInput.value)
                navController.navigate("${MarketScreen.ProductDetails.name}/${productScreenViewModel.searchedInput.value}")
            },
            onProductCardClick = {
                productScreenViewModel.getDetailsByProductCode(it)
                navController.navigate("${MarketScreen.ProductDetails.name}/${it}")
            }
        )
    }

    composable(route = MarketScreen.ProductList.name) {
        Log.d("Composable", "ProductInfoScreen - ProductList")
        ProductListScreen(
            productScreenerRequestState = productScreenerViewModel.productScreenerRequestState,
            sortOrderState = productScreenerViewModel.sortOrderState,
            title = stringResource(id = R.string.product_screener),
            onFilterClick = { sortOrderState ->
                productScreenerViewModel.sortItems(sortOrderState)
            },
            onBackClick = { navController.navigateUp() },
            onProductCardClick = { productCode, productName ->
                Log.d("onProductCardClick", productCode)
                productScreenViewModel.getDetailsByProductCode(productCode)
                productScreenViewModel.updateProductName(productName)
                navController.navigate("${MarketScreen.ProductDetails.name}/$productCode")
            }
        )
    }

    val productCodeArgument = "12345"

    composable(
        route = MarketScreen.ProductDetails.name + "/{$productCodeArgument}",
        arguments = listOf(navArgument(productCodeArgument) { type = NavType.StringType })
    ) { backStackEntry ->

        val productCode = backStackEntry.arguments?.getString(productCodeArgument)
            ?: error("ProductCode Argument cannot be null")

        Log.d("ProductCode", productCode)

        ProductDetailScreen(
            windowSize = windowSize,
            productDataRequestState = productScreenViewModel.productDataRequestState,
            productDetailUiState = productScreenViewModel.productDetailUiState.collectAsState().value,
            onBackClick = {
                navController.navigateUp()
            },
            onInfoClick = { title, content ->
                productScreenViewModel.updateInformationScreenUiState(title, content)
                navController.navigate(ProductInfoScreen.ProductInformation.name)
            },
            productScreenViewModel = productScreenViewModel,
        )
    }
}

as you can see in the latest composable in the end I’m not using productCode.
I wanted then to delete

Log.d("ProductCode", productCode)"

However when i compile just after doing that I got a lot of compilations errors

Unresolved references “market” pointing out all the import

import com.example.marketapp.ui.screen.market.MarketScreenViewModel
import com.example.marketapp.ui.screen.market.ProductScreenerScreen
import com.example.marketapp.ui.screen.market.ProductScreenerViewModel
import com.example.marketapp.ui.screen.market.ProductListScreen
import com.example.marketapp.ui.screen.market.TopBarProductScreen

Unresolved Reference ProductScreenerViewModel, MarketScreenViewModel pointing out
MarketApp composable (where the previous code is)

@Composable
fun MarketApp(
    activity: Activity,
    windowSize: WindowWidthSizeClass,
    productScreenerViewModel: ProductScreenerViewModel,
    marketScreenViewModel : MarketScreenViewModel,
    productScreenViewModel : ProductScreenViewModel,
    qonversionViewModel: QonversionViewModel,
    subscriptionViewModel : SubscriptionViewModel,
    authState : SignedInState,
    navController: NavHostController = rememberNavController()
) {

Unresolved Reference ProductScreenerScreen, TopBarMarketScreen, ProductListScreen

pointing out the corresponding calls in the navHost composables.

Type mismatch: inferred type is NavBackStackEntry but String was expected

//TopBarProductScreen

            onProductCardClick = {
                productScreenViewModel.getDetailsByProductCode(it)
                navController.navigate("${MarketScreen.ProductDetails.name}/${it}")
            }

Cannot infer a type for this parameter. Please specify it explicitly.
on all parameters sortOrderState, productCode, productName

composable(route = MarketScreen.ProductList.name) {
        Log.d("Composable", "ProductInfoScreen - ProductList")
        ProductListScreen(
            productScreenerRequestState = productScreenerViewModel.productScreenerRequestState,
            sortOrderState = productScreenerViewModel.sortOrderState,
            title = stringResource(id = R.string.product_screener),
            onFilterClick = { sortOrderState ->
                productScreenerViewModel.sortItems(sortOrderState)
            },
            onBackClick = { navController.navigateUp() },
            onProductCardClick = { productCode, productName ->
                Log.d("onProductCardClick", productCode)
                productScreenViewModel.getDetailsByProductCode(productCode)
                productScreenViewModel.updateProductName(productName)
                navController.navigate("${MarketScreen.ProductDetails.name}/$productCode")
            }
        )
    }

Please someone could explain me why i got this error which seems to be incredible to me.
In the end i’m just trying to remove the log.d statement.

later i wanted to transform

    composable(
        route = MarketScreen.ProductDetails.name + "/{$productCodeArgument}",
        arguments = listOf(navArgument(productCodeArgument) { type = NavType.StringType })
    ) 

in a static route like this :

    composable(route = MarketScreen.ProductDetails.name) 

And transforming all the navigate calls accordingly but i got also some similar issues.

For your information if i remove any of the other log.d statement i exactly got similar issues .

Log.d("Composable", "ProductInfoScreen - ProductList")
Log.d("onProductCardClick", productCode)

I’m closing the ticket since It seems it was a bug and It seems I found a solution.

The solution was to clean the project, (build → Clean Project) under Android Studio.

Not sure yet, but it seems it works now.