How to resolve multiple D8 warnings: <Class X> was not found, it is required for default or static interface methods desugaring <Class Y>?

15,424

Update: the issue has been fixed in Android Gradle Plugin 3.5.0-beta05 (see issue: Ability to selectively suppress warnings during D8 desugaring).


For Android Gradle Plugins 3.2.1 - 3.4.1 use the following workarounds:

From Android Gradle plugin 3.2.1 changelog:

Desugaring with D8 is now enabled by default.

So you should disable desugaring with D8 (in project's gradle.properties file):

android.enableD8.desugaring=false

If you use R8:

R8 is a new tool for code shrinking and obfuscation that replaces ProGuard. You can start using the preview version of R8 by including the following in your project’s gradle.properties file:

android.enableR8 = true

disable desugaring with R8 (in project's gradle.properties file):

android.enableR8.desugaring=false
Share:
15,424

Related videos on Youtube

mdev
Author by

mdev

Updated on September 15, 2022

Comments

  • mdev
    mdev over 1 year

    After upgrading to Android Gradle Plugin from 3.1.4 to 3.2.x I'm getting multiple warnings such as:

    D8: Type `com.google.gson.reflect.TypeToken` was not found, it is required for default or static interface methods desugaring of `com.google.gson.reflect.TypeToken org.springframework.http.converter.json.GsonHttpMessageConverter.getTypeToken(java.lang.reflect.Type)`
    D8: Type `com.squareup.okhttp.MediaType` was not found, it is required for default or static interface methods desugaring of `com.squareup.okhttp.MediaType org.springframework.http.client.OkHttpClientHttpRequest.getContentType(org.springframework.http.HttpHeaders)`
    D8: Type `org.apache.http.impl.client.HttpClients` was not found, it is required for default or static interface methods desugaring of `void org.springframework.http.client.HttpComponentsClientHttpRequestFactory.<init>()`
    D8: Interface `org.apache.http.HttpEntity` not found. It's needed to make sure desugaring of `org.springframework.http.client.HttpComponentsStreamingClientHttpRequest$StreamingHttpEntity` is correct. Desugaring will assume that this interface has no default method.
    D8: Type `org.conscrypt.Conscrypt` was not found, it is required for default or static interface methods desugaring of `okhttp3.internal.platform.Platform okhttp3.internal.platform.ConscryptPlatform.buildIfSupported()`
    ...
    

    Project is using Java 1.8 source compatibility (lambdas) and it looks like warnings came from the Android gradle class dexer which has been enabled by default in the AGP 3.2.0.

    1. I have tried to suppress these warnings in proguard-rules.pro with the following lines, but nothing seems to work.

      -dontwarn com.google.gson.reflect.TypeToken
      -keep class com.google.gson.reflect.TypeToken { *; }
      -dontwarn org.apache.http.**
      -keep class com.squareup.okhttp.** { *; }
      -dontwarn com.squareup.okhttp.**
      -keep class org.springframework.http.client.** { *; }
      -dontwarn org.springframework.http.client.**
      
    2. The only way I can make warnings to disappear is to set minifyEnabled and useProguard to false in the build.gradle file

    3. I have tried AGP 3.3.0-alpha13 and the new AGP 3.2.1 but without success.

    You can clone repository with sample project from https://github.com/mdawid/D8WarningTest

  • mdev
    mdev over 5 years
    When I try to enable R8 android.enableR8=true > WARNING: The option setting 'android.enableR8=true' is experimental and unsupported. The current default is 'false' and gradle still gives warnings.
  • mdev
    mdev over 5 years
    Warnings are gone when I disable desugaring in D8 by setting property android.enableD8.desugaring=false. You can also disable desugaring in R8 by setting property android.enableR8.desugaring=false. @kuelye Please edit your answer to clarify which settings should be enabled/disabled. Then I will accept your answer. Thanks!
  • originx
    originx about 5 years
    Disabling R8 is not a solution, you just suppress the issue and mislead the developer from a Tool google is pushing to the mainstream.
  • mdev
    mdev almost 5 years
    If you look at the sample project, you'll find that sourceCompatibility has already been set to Java 8. It makes no difference it this case.