raamcosta / compose-destinations

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

"Cannot detect default value for navigation argument" error when updating from 2.0.0-beta09 to 2.0.0-beta10 #668

Closed tomoya0x00 closed 4 months ago

tomoya0x00 commented 4 months ago

When updating from 2.0.0-beta09 to 2.0.0-beta10, the following error occurred.

> Task :app:kspDebugKotlin

[ksp] com.ramcosta.composedestinations.codegen.commons.IllegalDestinationsSetup: Cannot detect default value for navigation argument 'loginId' because we don't have access to source code. Nav argument classes from other modules with default values are not supported!
    at com.ramcosta.composedestinations.ksp.commons.DefaultParameterValueReaderKt.getDefaultValue(DefaultParameterValueReader.kt:234)
    at com.ramcosta.composedestinations.ksp.commons.UtilsKt.toParameter(Utils.kt:248)
    at com.ramcosta.composedestinations.ksp.commons.UtilsKt.getNavArgsDelegateType(Utils.kt:202)
    at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenNavGraphsMapper.getExternalNavGraph(KspToCodeGenNavGraphsMapper.kt:214)
    at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenNavGraphsMapper.access$getExternalNavGraph(KspToCodeGenNavGraphsMapper.kt:30)
    at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenNavGraphsMapper$mapToRawNavGraphGenParams$externalRoutes$2.invoke(KspToCodeGenNavGraphsMapper.kt:82)
    at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenNavGraphsMapper$mapToRawNavGraphGenParams$externalRoutes$2.invoke(KspToCodeGenNavGraphsMapper.kt:78)
    at kotlin.sequences.FlatteningSequence$iterator$1.ensureItemIterator(Sequences.kt:330)
    at kotlin.sequences.FlatteningSequence$iterator$1.hasNext(Sequences.kt:318)
    at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:816)
    at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenNavGraphsMapper.mapToRawNavGraphGenParams(KspToCodeGenNavGraphsMapper.kt:131)
    at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenNavGraphsMapper.access$mapToRawNavGraphGenParams(KspToCodeGenNavGraphsMapper.kt:30)
    at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenNavGraphsMapper$map$2.invoke(KspToCodeGenNavGraphsMapper.kt:42)
    at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenNavGraphsMapper$map$2.invoke(KspToCodeGenNavGraphsMapper.kt:42)
    at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210)
    at kotlin.collections.CollectionsKt__MutableCollectionsKt.addAll(MutableCollections.kt:129)
    at kotlin.collections.CollectionsKt___CollectionsKt.plus(_Collections.kt:3290)
    at com.ramcosta.composedestinations.ksp.processors.KspToCodeGenNavGraphsMapper.map(KspToCodeGenNavGraphsMapper.kt:41)
    at com.ramcosta.composedestinations.ksp.processors.Processor.process(Processor.kt:69)
    at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$8$1.invoke(KotlinSymbolProcessingExtension.kt:310)
    at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$8$1.invoke(KotlinSymbolProcessingExtension.kt:308)
    at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:414)
    at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:308)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:112)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:75)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze$lambda$12(KotlinToJVMBytecodeCompiler.kt:373)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:364)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.runFrontendAndGenerateIrUsingClassicFrontend(KotlinToJVMBytecodeCompiler.kt:195)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:106)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:176)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:50)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:104)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:48)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1556)
    at jdk.internal.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
    at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
    at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Unknown Source)
    at java.rmi/sun.rmi.transport.Transport.serviceCall(Unknown Source)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Unknown Source)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)

My guess is that the following change has made it impossible to get default values in some cases.

https://github.com/raamcosta/compose-destinations/compare/2.0.0-beta09...2.0.0-beta10#diff-eb29417fbe8f288ceb56630797489074bdbe83910eb4037eb465ef23fd1234ffR248

As a concrete example, if a BGraph that an AGraph references in the A module as an ExternalNavGraph exists in the B module, and the startDestination of the BGraph has a default argument, the above error may occur.

For reference, the project structure of the application that is causing the problem is as follows:

:ui:login gradle module

@ActivityDestination<LoginNavGraph>(
    start = true,
    navArgs = LoginNavArgs::class
)
@AndroidEntryPoint
internal class LoginRootActivity : AppCompatActivity() {
  ...
}

data class LoginNavArgs(
    val loginId: String = "",
)

:app gradle module


@NavHostGraph
annotation class MainGraph {
    @ExternalNavGraph<LoginGraph>
}
raamcosta commented 4 months ago

Hi @tomoya0x00 ! 👋

Thank you so much for reporting! I am on it 🙂 Should be an easy fix.

cQuencee commented 4 months ago

not sure if related but we also have this error happening when upgrading to latest version

[ksp] com.ramcosta.composedestinations.codegen.commons.IllegalDestinationsSetup: Navigation arguments using function calls with parameters as their default value are not currently supported (near: 'koinViewModel { parametersOf(productId, eventId, isUserVerified, productName, accessType) },) {MviScreen(state = viewModel.state, onSideEffect = { sideEffect -> consumeSideEffect(sideEffect = sideEffect, navigation = navigation) }, onBackPressed = { viewModel.execute(TokenGatedAccessVerificationIntent.Close) }) { view ->TokenGatedAccessVerificationLandingContent(state = view, executeIntent = viewModel::execute)}LocalLifecycleOwner.current.ObserveLifecycle(onResume = { viewModel.execute(TokenGatedAccessVerificationIntent.OnResume) },onPause = { viewModel.execute(TokenGatedAccessVerificationIntent.OnPause) },)}')

raamcosta commented 4 months ago

Fixed on v2 beta11 versiosn :)

Building now.. in 30min or so it should be available! Let me know if it works for you guys!

tomoya0x00 commented 4 months ago

@raamcosta

Sorry for my late reply. v2 beta11 works fine! Thx for your quick fix 👍