Fixed
Status Update
Comments
se...@google.com <se...@google.com> #2
The removal of the nested graphs and using popUpTo the given fragment appears to prevent the crash from happening in 1.0.0-alpha11.
yb...@google.com <yb...@google.com> #3
Project: platform/prebuilts/androidx/internal
Branch: androidx-master-dev
commit 63bc1ff1fe7c348138295ee7efb8cdc2999622c0
Author: Ian Lake <ilake@google.com>
Date: Sun Feb 03 15:18:53 2019
Update prebuilts for Navigation 1.0.0-beta01
Include fix for b/123803044
Test: ./gradlew bOS
Change-Id: Icb2a50975541a7bd3327054c72a591c7689c9741
M android/arch/navigation/navigation-common/1.0.0-beta01/navigation-common-1.0.0-beta01.aar
M android/arch/navigation/navigation-common/1.0.0-beta01/navigation-common-1.0.0-beta01.aar.md5
M android/arch/navigation/navigation-common/1.0.0-beta01/navigation-common-1.0.0-beta01.aar.sha1
M android/arch/navigation/navigation-fragment/1.0.0-beta01/navigation-fragment-1.0.0-beta01-sources.jar
M android/arch/navigation/navigation-fragment/1.0.0-beta01/navigation-fragment-1.0.0-beta01-sources.jar.md5
M android/arch/navigation/navigation-fragment/1.0.0-beta01/navigation-fragment-1.0.0-beta01-sources.jar.sha1
M android/arch/navigation/navigation-fragment/1.0.0-beta01/navigation-fragment-1.0.0-beta01.aar
M android/arch/navigation/navigation-fragment/1.0.0-beta01/navigation-fragment-1.0.0-beta01.aar.md5
M android/arch/navigation/navigation-fragment/1.0.0-beta01/navigation-fragment-1.0.0-beta01.aar.sha1
M android/arch/navigation/navigation-runtime/1.0.0-beta01/navigation-runtime-1.0.0-beta01.aar
M android/arch/navigation/navigation-runtime/1.0.0-beta01/navigation-runtime-1.0.0-beta01.aar.md5
M android/arch/navigation/navigation-runtime/1.0.0-beta01/navigation-runtime-1.0.0-beta01.aar.sha1
M android/arch/navigation/navigation-ui/1.0.0-beta01/navigation-ui-1.0.0-beta01.aar
M android/arch/navigation/navigation-ui/1.0.0-beta01/navigation-ui-1.0.0-beta01.aar.md5
M android/arch/navigation/navigation-ui/1.0.0-beta01/navigation-ui-1.0.0-beta01.aar.sha1
https://android-review.googlesource.com/892878
https://goto.google.com/android-sha1/63bc1ff1fe7c348138295ee7efb8cdc2999622c0
Branch: androidx-master-dev
commit 63bc1ff1fe7c348138295ee7efb8cdc2999622c0
Author: Ian Lake <ilake@google.com>
Date: Sun Feb 03 15:18:53 2019
Update prebuilts for Navigation 1.0.0-beta01
Include fix for
Test: ./gradlew bOS
Change-Id: Icb2a50975541a7bd3327054c72a591c7689c9741
M android/arch/navigation/navigation-common/1.0.0-beta01/navigation-common-1.0.0-beta01.aar
M android/arch/navigation/navigation-common/1.0.0-beta01/navigation-common-1.0.0-beta01.aar.md5
M android/arch/navigation/navigation-common/1.0.0-beta01/navigation-common-1.0.0-beta01.aar.sha1
M android/arch/navigation/navigation-fragment/1.0.0-beta01/navigation-fragment-1.0.0-beta01-sources.jar
M android/arch/navigation/navigation-fragment/1.0.0-beta01/navigation-fragment-1.0.0-beta01-sources.jar.md5
M android/arch/navigation/navigation-fragment/1.0.0-beta01/navigation-fragment-1.0.0-beta01-sources.jar.sha1
M android/arch/navigation/navigation-fragment/1.0.0-beta01/navigation-fragment-1.0.0-beta01.aar
M android/arch/navigation/navigation-fragment/1.0.0-beta01/navigation-fragment-1.0.0-beta01.aar.md5
M android/arch/navigation/navigation-fragment/1.0.0-beta01/navigation-fragment-1.0.0-beta01.aar.sha1
M android/arch/navigation/navigation-runtime/1.0.0-beta01/navigation-runtime-1.0.0-beta01.aar
M android/arch/navigation/navigation-runtime/1.0.0-beta01/navigation-runtime-1.0.0-beta01.aar.md5
M android/arch/navigation/navigation-runtime/1.0.0-beta01/navigation-runtime-1.0.0-beta01.aar.sha1
M android/arch/navigation/navigation-ui/1.0.0-beta01/navigation-ui-1.0.0-beta01.aar
M android/arch/navigation/navigation-ui/1.0.0-beta01/navigation-ui-1.0.0-beta01.aar.md5
M android/arch/navigation/navigation-ui/1.0.0-beta01/navigation-ui-1.0.0-beta01.aar.sha1
yb...@google.com <yb...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-master-dev
commit c775e5d1ae2ab4b194ee3c0f18523c603cf4d6ec
Author: Ian Lake <ilake@google.com>
Date: Sun Feb 03 15:04:21 2019
Return true when popping from FragmentNavigator
Since NavController only updates its back stack when
a Navigator returns true from popBackStack(), ensure
that all updates to the FragmentNavigator's back stack
(i.e., calling removeLast()) are paired with returning
true from popBackStack().
This ensures that the FragmentManager state and the
NavController states don't get out of sync.
Test: Updated FragmentNavigatorTest test
Test: tested in sample app from bug
BUG: 123803044
Change-Id: I8cfc87cba0a0369b5ae5c3ac610e31b5556ba04e
M navigation/fragment/src/androidTest/java/androidx/navigation/fragment/FragmentNavigatorTest.kt
M navigation/fragment/src/main/java/androidx/navigation/fragment/FragmentNavigator.java
https://android-review.googlesource.com/892996
https://goto.google.com/android-sha1/c775e5d1ae2ab4b194ee3c0f18523c603cf4d6ec
Branch: androidx-master-dev
commit c775e5d1ae2ab4b194ee3c0f18523c603cf4d6ec
Author: Ian Lake <ilake@google.com>
Date: Sun Feb 03 15:04:21 2019
Return true when popping from FragmentNavigator
Since NavController only updates its back stack when
a Navigator returns true from popBackStack(), ensure
that all updates to the FragmentNavigator's back stack
(i.e., calling removeLast()) are paired with returning
true from popBackStack().
This ensures that the FragmentManager state and the
NavController states don't get out of sync.
Test: Updated FragmentNavigatorTest test
Test: tested in sample app from bug
BUG: 123803044
Change-Id: I8cfc87cba0a0369b5ae5c3ac610e31b5556ba04e
M navigation/fragment/src/androidTest/java/androidx/navigation/fragment/FragmentNavigatorTest.kt
M navigation/fragment/src/main/java/androidx/navigation/fragment/FragmentNavigator.java
yb...@google.com <yb...@google.com> #5
This is actually an issue where the NavController's back stack state is going out of sync with the FragmentManager / FragmentNavigator's state. This has been fixed and will be available in the next release.
da...@gmail.com <da...@gmail.com> #6
Nice job! A quick response!
yb...@google.com <yb...@google.com> #7
I still get this error using the lastest 1.0.0 release :
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0'
implementation "android.arch.navigation:navigation-ui-ktx:1.0.0"
I'm using nested graphs.
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0'
implementation "android.arch.navigation:navigation-ui-ktx:1.0.0"
I'm using nested graphs.
ap...@google.com <ap...@google.com> #8
Re #7 - please file a new bug with a sample app that reproduces your issue.
Description
Version used: 2.2.0-alpha01
Devices/Android versions reproduced on: Android 9
I'm having some random crashes due to CoroutineLiveData
```
Fatal Exception: java.lang.IllegalArgumentException: This source was already added with the different observer
at androidx.lifecycle.MediatorLiveData.addSource + 89(MediatorLiveData.java:89)
at androidx.lifecycle.CoroutineLiveDataKt.addDisposableSource + 102(CoroutineLiveDataKt.java:102)
at androidx.lifecycle.CoroutineLiveData.emitSource$lifecycle_livedata_ktx_release + 200(CoroutineLiveData.java:200)
at androidx.lifecycle.LiveDataScopeImpl$emitSource$2.invokeSuspend + 89(LiveDataScopeImpl.java:89)
at androidx.lifecycle.LiveDataScopeImpl$emitSource$2.invoke(LiveDataScopeImpl.java:11)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn + 91(UndispatchedKt.java:91)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext + 156(BuildersKt__Builders_commonKt.java:156)
at kotlinx.coroutines.BuildersKt.withContext + 1(BuildersKt.java:1)
at androidx.lifecycle.LiveDataScopeImpl.emitSource + 88(LiveDataScopeImpl.java:88)
at com.geekorum.ttrss.articles_list.FeedsViewModel$refreshed$1.invokeSuspend + 90(FeedsViewModel.java:90)
at com.geekorum.ttrss.articles_list.FeedsViewModel$refreshed$1.invoke(FeedsViewModel.java:8)
at androidx.lifecycle.BlockRunner$maybeRun$1.invokeSuspend + 147(BlockRunner.java:147)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith + 33(BaseContinuationImpl.java:33)
at kotlinx.coroutines.DispatchedTask.run + 241(DispatchedTask.java:241)
at android.os.Handler.handleCallback + 873(Handler.java:873)
at android.os.Handler.dispatchMessage + 99(Handler.java:99)
at android.os.Looper.loop + 193(Looper.java:193)
at android.app.ActivityThread.main + 6898(ActivityThread.java:6898)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 537(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main + 858(ZygoteInit.java:858)
```
From what I understand of CoroutineLiveData source code, when calling `LiveDataScope.emitSource()` the previous source is removed before adding the new one on MediatorLiveData.
```
@MainThread
internal fun emitSource(source: LiveData<T>): DisposableHandle {
clearSource()
val newSource = addDisposableSource(source)
emittedSource = newSource
return newSource
}
```
However the removing is done by launching a new coroutine
```
internal fun <T> MediatorLiveData<T>.addDisposableSource(
source: LiveData<T>
): DisposableHandle {
val disposed = AtomicBoolean(false)
addSource(source) {
if (!disposed.get()) {
value = it
} else {
removeSource(source)
}
}
return object : DisposableHandle {
override fun dispose() {
if (disposed.compareAndSet(false, true)) {
CoroutineScope(Dispatchers.Main).launch {
removeSource(source)
}
}
}
}
}
```
So there is no guarantee that `MediatorLiveData.addSource()` will be called after the removing coroutine is executed. This leads to the IllegalArgumentException in `MediatorLiveData.addSource()`
```
@MainThread
public <S> void addSource(@NonNull LiveData<S> source, @NonNull Observer<? super S> onChanged) {
Source<S> e = new Source<>(source, onChanged);
Source<?> existing = mSources.putIfAbsent(source, e);
if (existing != null && existing.mObserver != onChanged) {
throw new IllegalArgumentException(
"This source was already added with the different observer");
}
if (existing != null) {
return;
}
if (hasActiveObservers()) {
e.plug();
}
}
```