0

An API Im making request on is returning a plain string (image url). Im using GSON with Retrofit.

This is the error message Retrofit is returning when Im making the request:

Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $

I added

.addConverterFactory(ScalarsConverterFactory.create())

But then when app is started it crashes with this error:

java.lang.NoClassDefFoundError: Failed resolution of: Lretrofit2/converter/scalars/ScalarsConverterFactory;

Im using the latest version of retrofit (2.9.0)

Does anyone have any idea why this would happen?

I tried this Retrofit with String response I tried ScalarsConverterFactory

Marcono1234
  • 5,856
  • 1
  • 25
  • 43
TemZy
  • 23
  • 4
  • Could you please verify that there are no dependency exclusions configured which might omit the `com.squareup.retrofit2:converter-scalars` artifact? If the cause of the `NoClassDefFoundError` is a `ClassNotFoundException` then most likely the classes of that dependency are omitted from your app for some reason. However, if the cause is a different exception type please add the complete stack trace to your question. – Marcono1234 Nov 15 '22 at 23:36
  • Could ProGuard rules have to do anything with this? – TemZy Nov 16 '22 at 07:10
  • I don't think so; ProGuard (or R8) should notice that the class is used and not omit it. Though to be sure you can try to disable it and see if that makes a difference. – Marcono1234 Nov 16 '22 at 21:57
  • Where are dependency exclusions configured? I tried searching for any kind of "converter-scalars" keyword trough the project and cant find anything – TemZy Nov 17 '22 at 11:53
  • Maybe then try adding an explicit dependency on `converter-scalars`; though it is a bit weird that you can compile against it in the first place. You can also try [debugging the dependencies](https://docs.gradle.org/current/userguide/viewing_debugging_dependencies.html#sec:listing_dependencies) to find out where `converter-scalars` is coming from (and why it might not be present in your app). This question and its answers might be useful as well: https://stackoverflow.com/q/39008887 – Marcono1234 Nov 18 '22 at 17:33

0 Answers0