Fixed
Status Update
Comments
da...@google.com <da...@google.com>
il...@google.com <il...@google.com> #2
Can you include a navigation graph XML file that reproduces your issue?
ma...@gmail.com <ma...@gmail.com> #3
<navigation xmlns:android="http://schemas.android.com/apk/res/android "
xmlns:app="http://schemas.android.com/apk/res-auto "
xmlns:tools="http://schemas.android.com/tools "
android:id="@+id/nav_main"
app:startDestination="@id/homeFragment">
<fragment
android:id="@+id/homeFragment"
android:name="com.example.navtest.HomeFragment"
android:label="HomeFragment"
tools:layout="@layout/fragment_home">
<action
android:id="@+id/action_homeFragment_to_nestedFragment"
app:destination="@id/nestedFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="@+id/nestedFragment"
android:name="com.example.navtest.NestedFragment"
android:label="fragment_nested"
tools:layout="@layout/fragment_nested" >
<argument
android:name="foo"
android:defaultValue='"foo"'
app:argType="string" />
</fragment>
<action
android:id="@+id/action_global_nestedFragment"
app:destination="@id/nestedFragment" />
<include app:graph="@navigation/nav_home" />
</navigation>
The compilation error arises after including the nested graph. From this, the error is avoided by either commenting out the global <action> or the <include> tag.
xmlns:app="
xmlns:tools="
android:id="@+id/nav_main"
app:startDestination="@id/homeFragment">
<fragment
android:id="@+id/homeFragment"
android:name="com.example.navtest.HomeFragment"
android:label="HomeFragment"
tools:layout="@layout/fragment_home">
<action
android:id="@+id/action_homeFragment_to_nestedFragment"
app:destination="@id/nestedFragment"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="@+id/nestedFragment"
android:name="com.example.navtest.NestedFragment"
android:label="fragment_nested"
tools:layout="@layout/fragment_nested" >
<argument
android:name="foo"
android:defaultValue='"foo"'
app:argType="string" />
</fragment>
<action
android:id="@+id/action_global_nestedFragment"
app:destination="@id/nestedFragment" />
<include app:graph="@navigation/nav_home" />
</navigation>
The compilation error arises after including the nested graph. From this, the error is avoided by either commenting out the global <action> or the <include> tag.
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 4855906b13c3adf6bf85833ebf28c3bba74e5969
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Wed Sep 26 12:44:33 2018
Detect <include> graphs as an included destination and not a nested one.
Even though included graphs can be considered nested graph, these are
not currently parsed by the plugin and end up being a stub destination.
This causes problems when there is a global action since a class will
be generated for the nested graph containing the global action, but
since the stub destination has no id nor name, the plugin fails.
This change adds a model, 'IncludedDestination' that represents an
included graph detected by the parser and is stored in a different set
within the containing Destination model. The included graph is not
further discovered. However, by treating it different than a nested
destination we avoid the issue described above. Moreover, this change
helps toward later supporting parsing included graphs.
Bug: 116542123
Test: ./gradlew \
:navigation:navigation-safe-args-gradle-plugin:test \
:navigation:navigation-safe-args-generator:test
Change-Id: I9eba5706e0209247a3a599f8e84d56d36b97938e
M navigation/safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/Context.kt
M navigation/safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/NavParser.kt
M navigation/safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/NavParserErrors.kt
M navigation/safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/models/Destination.kt
A navigation/safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/models/IncludedDestination.kt
M navigation/safe-args-generator/src/tests/kotlin/androidx/navigation/safe/args/generator/InvalidXmlTest.kt
M navigation/safe-args-generator/src/tests/kotlin/androidx/navigation/safe/args/generator/NavParserTest.kt
A navigation/safe-args-generator/src/tests/test-data/invalid_xmls/invalid_include_graph_attr.xml
A navigation/safe-args-generator/src/tests/test-data/invalid_xmls/invalid_include_tag.xml
A navigation/safe-args-generator/src/tests/test-data/nested_include_login_test.xml
https://android-review.googlesource.com/769261
https://goto.google.com/android-sha1/4855906b13c3adf6bf85833ebf28c3bba74e5969
Branch: androidx-master-dev
commit 4855906b13c3adf6bf85833ebf28c3bba74e5969
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Wed Sep 26 12:44:33 2018
Detect <include> graphs as an included destination and not a nested one.
Even though included graphs can be considered nested graph, these are
not currently parsed by the plugin and end up being a stub destination.
This causes problems when there is a global action since a class will
be generated for the nested graph containing the global action, but
since the stub destination has no id nor name, the plugin fails.
This change adds a model, 'IncludedDestination' that represents an
included graph detected by the parser and is stored in a different set
within the containing Destination model. The included graph is not
further discovered. However, by treating it different than a nested
destination we avoid the issue described above. Moreover, this change
helps toward later supporting parsing included graphs.
Bug: 116542123
Test: ./gradlew \
:navigation:navigation-safe-args-gradle-plugin:test \
:navigation:navigation-safe-args-generator:test
Change-Id: I9eba5706e0209247a3a599f8e84d56d36b97938e
M navigation/safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/Context.kt
M navigation/safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/NavParser.kt
M navigation/safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/NavParserErrors.kt
M navigation/safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/models/Destination.kt
A navigation/safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/models/IncludedDestination.kt
M navigation/safe-args-generator/src/tests/kotlin/androidx/navigation/safe/args/generator/InvalidXmlTest.kt
M navigation/safe-args-generator/src/tests/kotlin/androidx/navigation/safe/args/generator/NavParserTest.kt
A navigation/safe-args-generator/src/tests/test-data/invalid_xmls/invalid_include_graph_attr.xml
A navigation/safe-args-generator/src/tests/test-data/invalid_xmls/invalid_include_tag.xml
A navigation/safe-args-generator/src/tests/test-data/nested_include_login_test.xml
il...@google.com <il...@google.com> #5
This is fixed and will be available in 1.0.0-alpha07
Description
Version used: 1.0.0-alpha06
After updating the safe-args plugin from alpha05 to alpha06, my build fails with the following stacktrace:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:generateSafeArgsDebug'
Caused by: java.lang.IllegalStateException: Destination with actions must have name
at androidx.navigation.safe.args.generator.NavWriterKt.generateDirectionsJavaFile(NavWriter.kt:419)
at androidx.navigation.safe.args.generator.NavSafeArgsGeneratorKt$generateSafeArgs$1.invoke(NavSafeArgsGenerator.kt:43)
at androidx.navigation.safe.args.generator.NavSafeArgsGeneratorKt$generateSafeArgs$1.invoke(NavSafeArgsGenerator.kt:55)
at androidx.navigation.safe.args.generator.NavSafeArgsGeneratorKt.generateSafeArgs(NavSafeArgsGenerator.kt:58)
at androidx.navigation.safeargs.gradle.ArgumentsGenerationTask.generateArgs(ArgumentsGenerationTask.kt:54)
at androidx.navigation.safeargs.gradle.ArgumentsGenerationTask.doFullTaskAction(ArgumentsGenerationTask.kt:90)
at androidx.navigation.safeargs.gradle.ArgumentsGenerationTask.taskAction$navigation_safe_args_gradle_plugin(ArgumentsGenerationTask.kt:79)
Reverting to alpha05 makes the build complete.
I think this is related to the commit addressing this issue:
My navigation graph has this structure:
<navigation>
<fragment>
<action />
<argument />
</fragment>
<include app:graph="@navigation/nav_graph_two" />
...
<action />
</navigation>
That is, there are global actions, fragment destinations with arguments, fragment destinations with actions and an included nested graph (in a separate xml). Every single destination has a valid name and every root <navigation> has an id (everything works with version alpha05 of the plugin). I might guess this is related with global actions, which expect the parent destination to have a name that is not resolved with the alpha06 update. In fact, commenting out all the global actions makes the generateSafeArgsDebug task pass. My graphs have ids in the form "@+id/nav_graph_one".