Fuel Coroutines Failing on Android with NetworkOnMainThreadException after upgrade
See original GitHub issueHello Team,
I have encountered issues trying to upgrade my fuel version in my Android App, and would like to see if this is related to the fuel/coroutines package or to my own incorrect usage of coroutines within android.
The app worked great but now breaks with an android.os.NetworkOnMainThreadException when I make the following changes:
1. Fuel Version Bump: v1.13.0 -> v1.14.0
2. Coroutines Version Bump: v0.22.5 -> v0.23.4
3. Replace `awaitObject` with `awaitObjectResponse`
I’ve created a simple repository to reproduce the issue here: https://github.com/avaitla/coroutinesissue It has two branches:
good_v1.13.0 - uses fuel v1.13.0 and coroutines v0.22.5
broken_v1.14.0 - uses fuel v1.14.0 and coroutines v0.23.4
See the diff that breaks things here:
https://github.com/avaitla/coroutinesissue/commit/cba42a68498b217ce48dfdbc1abf7d279558d96f
The main activity class is here:
https://github.com/avaitla/coroutinesissue/blob/good_v1.13.0/app/src/main/java/com/avaitla16/coroutinesissue/MainActivity.kt
I’ve attached a screen shot from the good_version branch:
Here is the screen shot from the bad_version branch:
Thanks for your time!
Issue Analytics
- State:
- Created 5 years ago
- Comments:12
Top Results From Across the Web
NetworkOnMainThreadException while launching coroutines ...
This is strange, given that both coroutines are launched with a context of Dispatchers.IO , not Dispatchers.Main (Android's main UI thread).
Read more >Modern Android Development - Marcos Placona's Blog
The Problem. When your application tries to perform a networking operation on the main thread, an exception is thrown. This exception is only ......
Read more >How Do I Fix NetworkOnMainThreadException? - PSPDFKit
When we select our options item, we will see that after hitting the button, everything freezes, animations stop, and the UI won't respond...
Read more >Android App Crashes Due to Networkonmainthreadexception
Simplifying Android Development with Coroutines and Flows: Learn to use Kotlin ... Im getting the same arm 11 crash error.when pressing start to...
Read more >(PDF) Runtime Verification of Kotlin Coroutines - ResearchGate
PDF | Kotlin was introduced to Android as the recommended ... Another problem is when a coroutine executes using an undesirable dispatcher.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
#387 is now merged, let me know when you are happy to close this issue?
Thanks for taking a look everyone. I agree about making sure the pool is configurable, but just wanted to add that in the simple common cases (this example), using coroutines feels overly difficult without a default configurable scope option in Fuel.
Without it, developers have to ensure they have their request method launched inside the common pool along with having the caller launch their own logic inside the ui pool. It is especially challenging the first time you have to figure this out since the test cases don’t have an illustrative android example so you are somewhat on your own in this regard.
In comparison, for the simple cases, the callback style of fuel feels very pleasant to use since it handles the callback result on the android ui thread for users automatically.