简体   繁体   English

如何在Android Eclipse ProGuard规则中修复警告“无法找到引用的类”?

[英]How to fix warning 'can't find referenced class' in Android Eclipse ProGuard Rule?

I am using Eclipse. 我正在使用Eclipse。 In my Android code, I have used ProGuard. 在我的Android代码中,我使用了ProGuard。 But while exporting the APK, I encountered the following warnings: 但是在导出APK时,我遇到了以下警告:

Proguard returned with error code 1. See console
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.Files
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
       You should check if you need to specify additional program jars.
Warning: there were 14 unresolved references to classes or interfaces.
          You may need to specify additional library jars (using '-libraryjars').
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:321)
at proguard.ProGuard.initialize(ProGuard.java:211)
at proguard.ProGuard.execute(ProGuard.java:86)
at proguard.ProGuard.main(ProGuard.java:492)

What's wrong? 怎么了?

You can Solve that by modifying the 'progaurd-rules.pro' which seems that you are using Progaurd for Shrinking your Code. 您可以通过修改'progaurd-rules.pro'来解决这个问题,这似乎是您正在使用Progaurd缩小您的代码。

You must use -dontwarn But be careful before adding this to proguard file as there will not be errors at testing because Proguard had already delete some classes not being used 你必须使用-dontwarn但是在将它添加到proguard文件之前要小心,因为测试时不会出错,因为Proguard已经删除了一些没有使用的类

for case of OKiO add these lines 对于OKiO的情况添加这些行

-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**

For any other library you can see this link for further proguard operations https://github.com/krschultz/android-proguard-snippets 对于任何其他库,您可以看到此链接以进行进一步的proguard操作https://github.com/krschultz/android-proguard-snippets

Probably its better to add Okio rules from android-proguard-snippets: 可能最好从android-proguard-snippets添加Okio规则:

# Okio
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM