Error with last versions of retrofit

When I compile a project in water wiht oxygen that use the retrofit library in its latest versions, (2.8.1) the following error is thrown:
E: d8: Invoke-customs are only supported starting with Android O (–min-api 26)
Looking for estack overflow there is a thread where the same problem arises in android studio and it was resolved adding in app / build.gradle:

android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

How could I solve this in waters?

I’m not familiar with retrofit, I must admit. But form this error, it sounds like you’re building your project for too low an SDK version, can you make sure your Minimum SDK Version setting is set you 26 or higher (and, presumably, your Target SDK is higher as well)?

The problem is that Retrofit (I believe as of 3.0.0 but possibly earlier) decided to start using Java 8 instead of Java 7, and Java 8 is not supported by Android’s VM until API 26.

The gradle build parameters you posted tell Gradle to use Java 8 to compile, so the direct EBuild equivalent would be to go to Tools > Options in Water and set your JDK to target 1_8 instead of 1_7. I haven’t looked into this myself so I’m not sure if that will ultimately work or not.

You’ll need to de-sugar the Java 8 features somewhere along the way. This is handled by Android’s D8 build tool. Since D8 is supported by default in EBuild now, as long as Java 8 desugaring is enabled it will “just work.” (Desugaring is enabled by default and has to be explicitly disabled with the no-desugaring flag, which I assume is not present in EBuild, but that should be the only “gotcha.”

Actually now that I think of it, another possible “gotcha” is that the build still fails on “API < 26” error. I’m not sure where that error comes from, so I’m not sure what triggers it or stops it.

Right, so you’d just need your active/installed java version to be Java 8, and your target SDK to be 26 or higher, no?

Sure both target sdk and minimum SDK are set to ≥ 26?

@mh I’m not sure, but this seems to indicate a min sdk not a target sdk. Again, I could be wrong. I haven’t looked much into this area of Android’s build chain.

whats the full d8 command line?

Check EBuild source, I am passing --min-api

:man_shrugging:

So as long as the project’s min api is set to 26 it should work. But if you set min api to 26 you only target about 60% of Android users, so that’s not really practical. I’m not sure what Gradle does under the hood to allow Java 8 compiling to api < 26, aside from changing the jdk target and not not desugaring.

Can I bother you to check the build log and get it for me?

I’m not sure i understanding. are you saying this should be usable on APIs below 26, even though the error message clearly indicates that API 26 is required?

I’m actually away from my computer for a couple days and answering from my phone

Android api 26+ can run Java 8 code by default. API versions < 26 can only run Java 8 code if it has been desugared in the build. In Gradle this is done with the directive

android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

I’m not sure exactly what that actually tells Gradle to do under the hood though. But if you add that in Gradle, you can run Java 8 code on devices with api < 26.