Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 979
mdev Avatar asked Oct 12 '18 16:10

mdev


1 Answers

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 
like image 195
kuelye Avatar answered Sep 19 '22 23:09

kuelye