【问题标题】:Getting Warnings With Proguard (With External Libraries)使用 Proguard 获得警告(使用外部库)
【发布时间】:2016-06-30 20:56:52
【问题描述】:

我已启用 Proguard,我正在尝试构建 APK,但收到很多警告,不知道如何解决。

我正在使用 Retrofit、Jsoup 和其他库存库,我收到以下警告:

 Warning:okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
 Warning:okio.Okio: can't find referenced class java.nio.file.Files
 Warning:okio.Okio: can't find referenced class java.nio.file.Path
 Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption
 Warning:okio.Okio: can't find referenced class java.nio.file.Path
 Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption
 Warning:okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
 Warning:okio.Okio: can't find referenced class java.nio.file.Path
 Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption
 Warning:okio.Okio: can't find referenced class java.nio.file.Path
 Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption
 Warning:okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
 Warning:retrofit2.Platform$Java8: can't find referenced method 'boolean isDefault()' in library class java.lang.reflect.Method
 Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles$Lookup
 Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandle
 Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles
 Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandle
 Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles$Lookup
 Warning:retrofit2.Platform$Java8: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
 Note: the configuration keeps the entry point 'android.support.v7.widget.FitWindowsLinearLayout { void setOnFitSystemWindowsListener(android.support.v7.widget.FitWindowsViewGroup$OnFitSystemWindowsListener); }', but not the descriptor class 'android.support.v7.widget.FitWindowsViewGroup$OnFitSystemWindowsListener'
 Note: the configuration keeps the entry point 'android.support.v7.widget.RecyclerView { void setAccessibilityDelegateCompat(android.support.v7.widget.RecyclerViewAccessibilityDelegate); }', but not the descriptor class 'android.support.v7.widget.RecyclerViewAccessibilityDelegate'
 Note: the configuration keeps the entry point 'android.support.v7.widget.RecyclerView { void setAdapter(android.support.v7.widget.RecyclerView$Adapter); }', but not the descriptor class 'android.support.v7.widget.RecyclerView$Adapter'
 Note: the configuration keeps the entry point 'android.support.v7.widget.RecyclerView { void setRecyclerListener(android.support.v7.widget.RecyclerView$RecyclerListener); }', but not the descriptor class 'android.support.v7.widget.RecyclerView$RecyclerListener'
 Note: the configuration keeps the entry point 'android.support.v7.widget.RecyclerView { void setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager); }', but not the descriptor class 'android.support.v7.widget.RecyclerView$LayoutManager'
 Note: the configuration keeps the entry point 'android.support.v7.widget.RecyclerView { void setRecycledViewPool(android.support.v7.widget.RecyclerView$RecycledViewPool); }', but not the descriptor class 'android.support.v7.widget.RecyclerView$RecycledViewPool'
 Note: the configuration keeps the entry point 'android.support.v7.widget.RecyclerView { void setViewCacheExtension(android.support.v7.widget.RecyclerView$ViewCacheExtension); }', but not the descriptor class 'android.support.v7.widget.RecyclerView$ViewCacheExtension'
 Warning:there were 22 unresolved references to classes or interfaces.
 Warning:there were 1 unresolved references to library class members.
 Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.

这是我的前卫:

 -keep class * implements android.os.Parcelable {
   public static final android.os.Parcelable$Creator *;
 }

 ##---------------Begin: proguard configuration for Gson  ----------
 # Gson uses generic type information stored in a class file when working with fields. Proguard
 # removes such information by default, so configure it to keep all of it.
 -keepattributes Signature


 # Gson specific classes
 -keep class com.abohani.tdroms.SharedPreferencesTools { *; }
 #-keep class com.google.gson.stream.** { *; }


 # Application classes that will be serialized/deserialized over Gson
 -keep class com.abohani.tdroms.** { *; }

【问题讨论】:

  • 您应该添加 -keep 类或不要使用 okio.Okio 警告。

标签: android proguard


【解决方案1】:

当您使用 ProGuard 时,您必须始终解决所有警告

这些警告告诉您这些库引用了一些代码,并且没有相应的来源。那可能也可能不好。这取决于是否调用了有问题的代码。

在这种情况下,可以忽略 Okio 和 Retrofit2 的警告。包 java.nio.* 在 Android 上不可用,并且永远不会被调用。您可以放心地忽略这些警告。也不会使用 Java 8 类。

将此添加到您的 ProGuard 配置中,它应该可以解决您的问题:

-dontwarn okio.**
-dontwarn retrofit2.Platform$Java8

【讨论】:

  • Android 7 SDK 支持 Java 8 和 java.nio。这个答案在那里仍然正确吗? (免责声明:我对 Okio 知之甚少,如果这是一个愚蠢的问题,请见谅)。
  • 是的,它仍然成立。 Android SDK 包含来自java.nio 的一些类,但它不包含来自java.nio.file 的任何内容。
【解决方案2】:

Retrofit 页面记录了 proguard 版本:

Platform 对 Android 上不存在的类型调用 Class.forName 以确定平台。

-dontnote retrofit2.Platform

在 Java 8 VM 上运行时使用的平台。不会在运行时使用。

-dontwarn retrofit2.Platform$Java8

保留通用类型信息以供转换器和适配器反射使用。

-keepattributes 签名

保留声明的检查异常以供代理实例使用。

-keepattributes 异常

在这里查看:http://square.github.io/retrofit/

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 1970-01-01
    • 2019-12-30
    • 2013-11-02
    • 2017-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多