0

I have a deeplink like this:

 <deepLink
    android:id="@+id/applink_one"
    app:uri="https://sample.com/{arg1}/?arg2={arg2}" />

and define args like this:

<argument
    android:name="arg1"
    app:argType="string" />

<argument
    android:name="arg2"
    android:defaultValue="@null"
    app:argType="string[]"
    app:nullable="true"
    />

when calling this:

https://sample.com/tags/?arg2=test&arg2=toast

I get this error and exit the application:

Caused by: android.view.InflateException: Binary XML file line #19 in com.sample.app:layout/activity_nav_host: Error inflating class androidx.fragment.app.FragmentContainerView

Caused by: java.lang.UnsupportedOperationException: Arrays don't support default values.

I can not detect the error.

"Arrays don't support default values."?

what can I do?

My navigation versions:

androidx.navigation:navigation-fragment-ktx:2.2.0
androidx.navigation:navigation-ui-ktx::2.2.0
androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0

the entire stack trace:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.sample.app, PID: 24284
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sample.app/com.sample.app.presentation.NavHostActivity}: android.view.InflateException: Binary XML file line #19 in com.sample.app:layout/activity_nav_host: Binary XML file line #19 in com.sample.app:layout/activity_nav_host: Error inflating class androidx.fragment.app.FragmentContainerView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3835)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4011)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2325)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:246)
        at android.app.ActivityThread.main(ActivityThread.java:8633)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
     Caused by: android.view.InflateException: Binary XML file line #19 in com.sample.app:layout/activity_nav_host: Binary XML file line #19 in com.sample.app:layout/activity_nav_host: Error inflating class androidx.fragment.app.FragmentContainerView
     Caused by: android.view.InflateException: Binary XML file line #19 in com.sample.app:layout/activity_nav_host: Error inflating class androidx.fragment.app.FragmentContainerView
     Caused by: java.lang.UnsupportedOperationException: Arrays don't support default values.
        at androidx.navigation.NavType$11.parseValue(NavType.java:623)
        at androidx.navigation.NavType$11.parseValue(NavType.java:609)
        at androidx.navigation.NavType.parseAndPut(NavType.java:96)
        at androidx.navigation.NavDeepLink.parseArgument(NavDeepLink.java:187)
        at androidx.navigation.NavDeepLink.getMatchingArguments(NavDeepLink.java:174)
        
imany apk
  • 91
  • 1
  • 8

1 Answers1

0

Remove this wrongful default value, which must not be set for type of []:

android:defaultValue="@null"
app:nullable="true"

It also reads R.layout.activity_nav_host, line #19 ...which is probably where to look.


Else the deep-link would have pass String[]:

https://sample.com/tags/?arg2=[test,toast]
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Nope, I tried this, but nothing has changed – imany apk Nov 29 '21 at 06:27
  • The deep-link is referring to `arg2=` twice ...so you're not calling it correctly. There may be some more occurrences of the above wrongful default value, which must not be set for type of `[]`. – Martin Zeitler Nov 29 '21 at 08:21
  • No, it's not a typo, I want to handle arg2 as a list of values; in my example: "https://sample.com/tags/?arg2=test&arg2=toast", arg1 is equal to tags and arg2 is gonna be a list of test & toast : ["test", "toast"]. however, it crashes by calling "https://sample.com/" either. – imany apk Nov 29 '21 at 08:29
  • The deep-link is a typo, because this is not the preferred way to create an input array... when using this twice, the server-side may only register the last one of them (at least in PHP, not sure how the URL scheme is being implemented for deep-links). This "default" value may come from the first one `arg2`, which the second one `arg2` tries to mutate. – Martin Zeitler Nov 29 '21 at 08:33
  • Maybe the `app:uri` URL scheme would already have to represent array input? This is at least where the pattern comes from. – Martin Zeitler Nov 29 '21 at 08:41