question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fuel Coroutines Failing on Android with NetworkOnMainThreadException after upgrade

See original GitHub issue

Hello 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:

success_fuelv1 13 0_coroutinesv0 22 5

Here is the screen shot from the bad_version branch:

failure_fuelv1 14 0_coroutinesv0 23 4

Thanks for your time!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
markGilchristcommented, Jul 22, 2018

#387 is now merged, let me know when you are happy to close this issue?

1reaction
avaitlacommented, Jul 15, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found