27

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
  • 534
  • 1
  • 6
  • 14
  • The issue has been reported and can be tracked on https://issuetracker.google.com/issues/118842646 – mdev May 23 '19 at 13:33

2 Answers2

19

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
Community
  • 1
  • 1
kuelye
  • 636
  • 7
  • 9
  • 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 Nov 07 '18 at 11:09
  • 2
    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! – mdev Nov 13 '18 at 12:53
  • 7
    Disabling R8 is not a solution, you just suppress the issue and mislead the developer from a Tool google is pushing to the mainstream. – originx Apr 26 '19 at 06:02
-1

I think this is because this class is written in Java8, but the project is compiled in Java7.so I update following:

compileOptions {
     sourceCompatibility JavaVersion.VERSION_1_8
     targetCompatibility JavaVersion.VERSION_1_8
 }

this fixes my problem

王楠楠
  • 19
  • 1
  • 1
    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. – mdev May 23 '19 at 10:27