Fixed
Status Update
Comments
jb...@google.com <jb...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit e1b42da3ee5bcb06756d8cb8377abf6116086e11
Author: Sanura N'Jaka <sanura@google.com>
Date: Tue Sep 07 20:23:52 2021
Make nullable NavDeepLink arguments not required
Removing the inclusion of nullable NavDeepLink
arguments from the "required" argument checking.
RelNote: "Nullable `NavDeepLink` arguments no longer
require a default value."
Test: deepLinkNullableArgumentNotRequired test
Bug: 198689811
Change-Id: Ia14ef04bfe5b25942163688f40adacc30fa7e044
M navigation/navigation-common/src/androidTest/java/androidx/navigation/AddInDefaultArgsTest.kt
M navigation/navigation-common/src/androidTest/java/androidx/navigation/NavDeepLinkTest.kt
M navigation/navigation-common/src/androidTest/java/androidx/navigation/test/NavArgument.kt
M navigation/navigation-common/src/main/java/androidx/navigation/NavDeepLink.kt
https://android-review.googlesource.com/1817360
Branch: androidx-main
commit e1b42da3ee5bcb06756d8cb8377abf6116086e11
Author: Sanura N'Jaka <sanura@google.com>
Date: Tue Sep 07 20:23:52 2021
Make nullable NavDeepLink arguments not required
Removing the inclusion of nullable NavDeepLink
arguments from the "required" argument checking.
RelNote: "Nullable `NavDeepLink` arguments no longer
require a default value."
Test: deepLinkNullableArgumentNotRequired test
Bug: 198689811
Change-Id: Ia14ef04bfe5b25942163688f40adacc30fa7e044
M navigation/navigation-common/src/androidTest/java/androidx/navigation/AddInDefaultArgsTest.kt
M navigation/navigation-common/src/androidTest/java/androidx/navigation/NavDeepLinkTest.kt
M navigation/navigation-common/src/androidTest/java/androidx/navigation/test/NavArgument.kt
M navigation/navigation-common/src/main/java/androidx/navigation/NavDeepLink.kt
il...@google.com <il...@google.com> #3
There's two issues here:
android:defaultValue="@null"
is actually treated as thedefaultValue
attribute not existing at all at runtime (we do still use it for Safe Args)- We enforced every argument without a default value to be present in the URI/route, even if it was nullable.
While we can't fix the first one, we have made the change in Navigation 2.4.0-alpha09
to only check for default values for non-nullable parameters. This should mean that
- Using
android:defaultValue="@null"
won't be a problem - Constructing a type in the Kotlin DSL via
navArgument("argument_name")
and making itnullable = true
without a default value won't be a problem.
sj...@gmail.com <sj...@gmail.com> #4
Unfortunately I still experience this bug with 2.4.0-alpha09 :(
java.lang.IllegalArgumentException: Deep link penny://app/offers can't be used to open destination Destination(de.penny.app.debug:id/offerListFragment) label=OfferListFragment class=de.penny.feature.offer.view.OfferListFragment.
Following required arguments are missing: [sectionIndexOrName, raffleId]
This is the excerpt from my navigation graph XML:
<argument
android:name="sectionIndexOrName"
android:defaultValue="@null"
app:argType="string"
app:nullable="true" />
<argument
android:name="raffleId"
android:defaultValue="@null"
app:argType="string"
app:nullable="true" />
<deepLink
android:id="@+id/offersDeeplink"
app:uri="penny://app/offers" />
As you can see both parameters are nullable and have a default value of null
.
sj...@gmail.com <sj...@gmail.com> #6
I'm sorry, I forgot to upgrade the Safe Args Gradle plugin as well. However when upgrading the plugin I now get
Description
Component used: Navigation Version used: 2.4.0-alpha08 Devices/Android versions reproduced on: All
It seems that the fix for https://issuetracker.google.com/issues/185527157 has introduced another bug. Nullable arguments with an
@null
default value are incorrectly treated as required, and cause the app to crash if they are not present in a deep link. You will get the following error:The Nav Graph defines the argument like this: