Fixed
Status Update
Comments
il...@google.com <il...@google.com>
il...@google.com <il...@google.com> #2
A number of improvements have been made for alpha08 including https://android-review.googlesource.com/833717 which seems to fix this issue.
Description
Version used: 1.0.0-alpha05
Devices/Android versions reproduced on: Nexus 5X emulator API 27 (Android 8.1 with Google Play)
I'm encountering crash when using deep link in fairly complex navigation graph that is split into several files and utilizes graph <include>s and has inclusive popUpTo in the middle. Deep link should redirect navigation to the farthest fragment in graph. Here it is:
// graph.xml
<navigation xmlns:android="
xmlns:app="
app:startDestination="@+id/fragmentA">
<fragment
android:id="@+id/fragmentA"
android:name="bugs.aacnav.crash2.FragmentA"
android:label="FragmentA">
<action
android:id="@+id/to_fragment_b"
app:destination="@id/destination_fragmentB"
app:popUpTo="@id/fragmentA"
app:popUpToInclusive="true"/>
</fragment>
<include app:graph="@navigation/graph_b" />
<include app:graph="@navigation/graph_c" />
</navigation>
// graph_b.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="
xmlns:app="
android:id="@id/destination_fragmentB"
app:startDestination="@+id/fragmentB">
<fragment
android:id="@+id/fragmentB"
android:name="bugs.aacnav.crash2.FragmentB"
android:label="FragmentB">
<action
android:id="@+id/to_fragment_c"
app:destination="@id/destination_fragmentC"
/>
</fragment>
</navigation>
// graph_c.xml.
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="
xmlns:app="
android:id="@id/destination_fragmentC"
app:startDestination="@+id/fragment1">
<fragment
android:id="@+id/fragment1"
android:name="bugs.aacnav.crash2.FragmentB"
android:label="Fragment1">
<action
android:id="@+id/to_fragment_2"
app:destination="@id/fragment2"
/>
</fragment>
<fragment
android:id="@+id/fragment2"
android:name="bugs.aacnav.crash2.FragmentB"
android:label="Fragment2">
<action
android:id="@+id/to_fragment_c"
app:destination="@id/fragmentC"
/>
</fragment>
<fragment
android:id="@+id/fragmentC"
android:name="bugs.aacnav.crash2.FragmentDeepLink"
android:label="FragmentDeepLink">
<deepLink app:uri="
</fragment>
</navigation>
// ids.xml. Defines destinations used in the graph
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="destination_fragmentB"/>
<item type="id" name="destination_fragmentC"/>
</resources>
Testing deep link with ADB works as intended: adb shell am start -W -a android.intent.action.VIEW -d "
However, if the same link is sent as SMS with emulator phone controls, and then clicked in SMS app (pics attached), it causes crash. Full stacktrace:
Process: bugs.aacnav.navissues, PID: 32279
java.lang.RuntimeException: Unable to start activity ComponentInfo{bugs.aacnav.navissues/bugs.aacnav.crash2.MainActivity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
Caused by: java.lang.IllegalArgumentException: Navigator androidx.navigation.fragment.FragmentNavigator@dbf24b1 reported navigation to unknown destination id bugs.aacnav.navissues:id/fragmentC
at androidx.navigation.NavController$2.onNavigatorNavigated(NavController.java:142)
at androidx.navigation.Navigator.dispatchOnNavigatorNavigated(Navigator.java:217)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:207)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:45)
at androidx.navigation.NavDestination.navigate(NavDestination.java:407)
at androidx.navigation.NavController.onHandleDeepLink(NavController.java:567)
at androidx.navigation.NavController.onGraphCreated(NavController.java:466)
at androidx.navigation.NavController.setGraph(NavController.java:421)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:221)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2331)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at bugs.aacnav.crash2.MainActivity.onCreate(MainActivity.kt:18)
at android.app.Activity.performCreate(Activity.java:6999)
at android.app.Activity.performCreate(Activity.java:6990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
2018-08-28 11:36:58.042 32279-32279/? E/AndroidRuntime: at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
I think key error here is this one: Navigator androidx.navigation.fragment.FragmentNavigator@dbf24b1 reported navigation to unknown destination id bugs.aacnav.navissues:id/fragmentC
I noticed the difference between Intents created by 'adb shell am start' and clicking link in SMS:
// with ADB:
V/Deep link: Intent[@3d18209] content:
V/Deep link: Action : android.intent.action.VIEW
V/Deep link: Category : null
V/Deep link: Data :
V/Deep link: Component: bugs.aacnav.navissues/bugs.aacnav.crash2.MainActivity
V/Deep link: Flags : 10000000000000000000000000000
V/Deep link: Flag : FLAG_ACTIVITY_NEW_TASK
V/Deep link: HasExtras: false
// second intent. I guess it's same as this issue:
V/Deep link: Intent[@8881504] content:
V/Deep link: Action : android.intent.action.VIEW
V/Deep link: Category : null
V/Deep link: Data :
V/Deep link: Component: bugs.aacnav.navissues/bugs.aacnav.crash2.MainActivity
V/Deep link: Flags : 10000000000001100000000000000
V/Deep link: Flag : FLAG_ACTIVITY_CLEAR_TASK
V/Deep link: Flag : FLAG_ACTIVITY_TASK_ON_HOME
V/Deep link: Flag : FLAG_ACTIVITY_NEW_TASK
V/Deep link: HasExtras: false
// link from SMS:
V/Deep link: Intent[@6ff3710] content:
V/Deep link: Action : android.intent.action.VIEW
V/Deep link: Category : null
V/Deep link: Data :
V/Deep link: Component: bugs.aacnav.navissues/bugs.aacnav.crash2.MainActivity
V/Deep link: Flags : 0
V/Deep link: HasExtras: true
V/Deep link: Extra[com.android.browser.application_id] :com.google.android.apps.messaging
The difference is that ADB Intent has FLAG_ACTIVITY_NEW_TASK while Intent from SMS does not have it.
My current workaround is to add FLAG_ACTIVITY_NEW_TASK to Intents that do not have it:
if (intent.action == Intent.ACTION_VIEW) {
if (!intent.hasFlag(Intent.FLAG_ACTIVITY_NEW_TASK)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
}
My assumption is that somehow graph is incorrectly constructed when deep link is handled and Intent does not have FLAG_ACTIVITY_NEW_TASK. It works well on simpler graphs.
Example project: