You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, prehistory. I've published an app which I was working on to Google Play as alpha version and got strange crash reports in Crashlytics with StackOverflowError. I'm not even sure that the problem is related to coroutines (it seems to be more related to ProGuard or R8 tools), but stacktraces include links to coroutines, so that's why I'm placing an issue here.
I created a simple repository as example to show the issue. It's simplified a lot, production app has much more complicated architecture and uses coroutines as base for domain layer.
Example has a simple view model, which has live data based on state:
privateval_state=MutableLiveData(MainViewState())
val state:LiveData<MainViewState>
get() =_state
State is a data class:
data classMainViewState(vallist:List<Int> = emptyList())
In the production app view model collects flow returned by Room library in init block. In the example repo I just created a simple flow:
init {
viewModelScope.launch {
flow {
val list = arrayListOf<Int>()
for (i in0..100) {
list.add(Random(100).nextInt())
}
emit(list)
}.flowOn(Dispatchers.Default)
.distinctUntilChanged()
.collect { list ->Log.e("Collect list", list.toString())
}
}
}
flowOn(Dispatchers.Default) and distinctUntilChanged() methods are placed here just to match the behavior of the actual app. Also I emulated release mode by setting the following in build.gradle:
And android.enableR8.fullMode=true in gradle.properties.
Actual issue is in that app crashes with these parameters, but everything works fine with another variations. I've got the following results. Crash doesn't appear if:
Set debuggable to true
Using proguard-android.txt instead of proguard-android-optimize.txt
Removing android.enableR8.fullMode=true. Works for both proguard-android.txt and proguard-android-optimize.txt
Removing .flowOn(Dispatchers.Default) from chain
Using the same dispatchers for .flowOn() and viewModelScope.launch()
Each item in the above list describes changing of single parameter without affecting the rest. Maybe I missed something or just misunderstood basic concepts, but it's interesting why stacktrace points to StackOverflowError exception.
Deobfuscated stacktrace for example app is attached: stacktrace.txt.
The text was updated successfully, but these errors were encountered:
Hi there.
First, prehistory. I've published an app which I was working on to Google Play as alpha version and got strange crash reports in Crashlytics with
StackOverflowError
. I'm not even sure that the problem is related to coroutines (it seems to be more related to ProGuard or R8 tools), but stacktraces include links to coroutines, so that's why I'm placing an issue here.I created a simple repository as example to show the issue. It's simplified a lot, production app has much more complicated architecture and uses coroutines as base for domain layer.
Example has a simple view model, which has live data based on state:
State is a data class:
Activity observes this live data state:
In the production app view model collects flow returned by
Room
library ininit
block. In the example repo I just created a simple flow:flowOn(Dispatchers.Default)
anddistinctUntilChanged()
methods are placed here just to match the behavior of the actual app. Also I emulatedrelease
mode by setting the following inbuild.gradle
:And
android.enableR8.fullMode=true
ingradle.properties
.Actual issue is in that app crashes with these parameters, but everything works fine with another variations. I've got the following results. Crash doesn't appear if:
debuggable
totrue
proguard-android.txt
instead ofproguard-android-optimize.txt
android.enableR8.fullMode=true
. Works for bothproguard-android.txt
andproguard-android-optimize.txt
.flowOn(Dispatchers.Default)
from chain.flowOn()
andviewModelScope.launch()
Each item in the above list describes changing of single parameter without affecting the rest. Maybe I missed something or just misunderstood basic concepts, but it's interesting why stacktrace points to
StackOverflowError
exception.Deobfuscated stacktrace for example app is attached: stacktrace.txt.
The text was updated successfully, but these errors were encountered: