本文介绍了如何解决多个D8警告:< Class X>找不到,则默认的或静态的接口方法必须使用< Class Y>吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从3.1.4升级到3.2.x的Android Gradle插件后,我收到多个警告,例如:

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()`
...

该项目正在使用Java 1.8源兼容性(lambdas),并且警告似乎来自Android gradle类dexer,该警告已在AGP 3.2.0中默认启用.

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. 我尝试通过以下几行在proguard-rules.pro中禁止显示这些警告,但似乎无济于事.

  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.**

  • 我可以使警告消失的唯一方法是在build.gradle文件中将minifyEnableduseProguard设置为false

  • The only way I can make warnings to disappear is to set minifyEnabled and useProguard to false in the build.gradle file

    我尝试了AGP 3.3.0-alpha13和新的AGP 3.2.1,但没有成功.

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

    您可以从 https://github.com/mdawid/D8WarningTest克隆带有示例项目的存储库. a>

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

    推荐答案

    更新:此问题已在Android Gradle插件3.5.0-beta05中得到解决(请参见问题:在D8减震期间可以选择性地禁止显示警告的功能).

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

    对于Android Gradle插件3.2.1-3.4.1,请使用以下解决方法:

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

    来自Android Gradle插件 3.2.1更新日志 :

    From Android Gradle plugin 3.2.1 changelog:

    因此,您应该使用D8(在项目的gradle.properties文件中)禁用去糖功能:

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

    android.enableD8.desugaring=false
    


    如果您使用R8:


    If you use R8:

    android.enableR8 = true
    

    使用R8禁用重复数据删除(在项目的gradle.properties文件中):

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

    android.enableR8.desugaring=false
    

    这篇关于如何解决多个D8警告:&lt; Class X&gt;找不到,则默认的或静态的接口方法必须使用&lt; Class Y&gt;吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 07-17 04:38
    查看更多