从3.1.4升级到3.2.x的Android Gradle插件后,我收到多个警告,例如:
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中默认启用。
我尝试通过以下几行在proguard-rules.pro
中隐藏这些警告,但似乎无济于事。
-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.**
我可以使警告消失的唯一方法是在minifyEnabled
文件中将useProguard
和false
设置为build.gradle
我尝试了AGP 3.3.0-alpha13和新的AGP 3.2.1,但没有成功。
答案 0 :(得分:2)
来自Android Gradle插件3.2.1 changelog:
默认情况下,启用D8的脱糖功能。
因此,您应禁用D8(在项目的gradle.properties
文件中)的反欺诈:
android.enableD8.desugaring=false
如果您使用R8:
R8是替代ProGuard的用于代码收缩和混淆的新工具。您可以通过在项目的
gradle.properties
文件中添加以下内容来开始使用R8预览版:android.enableR8 = true
使用R8禁用重复数据删除(在项目的gradle.properties
文件中):
android.enableR8.desugaring=false
答案 1 :(得分:0)
我认为这是因为此类是用Java8编写的,但是该项目是用Java7编译的,因此我更新了以下内容:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
这解决了我的问题