kittinunf / fuel

The easiest HTTP networking library for Kotlin/Android
https://fuel.gitbook.io/documentation/
MIT License
4.52k stars 427 forks source link

simple GET request fails with IllegalAccessError OkHttp3 #871

Open doums opened 1 year ago

doums commented 1 year ago

Hi, using 3.0.0-alpha1 on my android project when I make a simple GET request on a healthy URL I get the following exception and the request fails:

java.lang.IllegalAccessError: Field 'okhttp3.OkHttpClient$Builder.eventListenerFactory' is inaccessible to class 'okhttp3.OkHttpClient' (declaration of 'okhttp3.OkHttpClient' appears in ../base.apk!classes4.dex

code

import fuel.Fuel
import fuel.get

val spUrl = "https://google.com"
val res = Fuel.get(spUrl)   // <- throws exception

I'm not sure if it's a bug in the lib or something related to my android project?

iNoles commented 1 year ago

Are you override the okhttp versions in your apps? Fuel 3x uses okhttp 5.

doums commented 1 year ago

Nope, you can find the build.gradle here https://github.com/nymtech/nym/blob/bbce67902b1040d9cc5a3b609215a885291e30b6/nym-connect/native/android/app/build.gradle#L126C42-L126C46

Could it be related to proguard? Like a missing rule?

iNoles commented 1 year ago

Oh okay, I think I figured out what went wrong.

on alpha1, I had okhttp as implementation instead api. The snapshot already had api. I believe your android apps is looking at the okttp library, but it is not found. Hence errors. As for temporary workaround, you can put okhttp 5 library on your apps.

doums commented 1 year ago

Adding okhttp in build.gradle dependencies does not solve the problem

    implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11'

I still get the same error

doums commented 1 year ago

@iNoles any news on this?

iNoles commented 1 year ago

Sorry, no updates for now.

doums commented 1 year ago

Ok sorry to bother you, but do you have an idea of what could be the issue? I shared my project link, so it might help you to identify the issue. If not I will drop fuel to use another solution to make HTTP requests. To bad but I don't have really the choice.

iNoles commented 1 year ago

I built my own News app that uses Fuel 3.0 alpha 01 and compose multiplatform. https://github.com/iNoles/News

I hope it would help you.

doums commented 1 year ago

Thx, but no it does not help since your android project is almost empty (you forgot to push maybe?).

Anyway, I downgraded to latest stable 2.3.1 and the library works as expected. But I left the issue open for 3.0.0-alpha1.

iNoles commented 1 year ago

That is because shared modules contain the android library.