Android-Studio-1.2.RC在Square的Okio库参考上的Proguard警告

时间:2015-04-27 03:51:18

标签: android android-studio proguard square okio

与Android Studio:1.2.RC

我在.gradle中启用了proguard: ```

minifyEnabled=true

and added these rules to my proguard-rules.pro:

-dontwarn com.squareup.**
-dontwarn okio.**

and added these lint rules to my .gradle file:

warningsAsErrors false
abortOnError false
disable 'InvalidPackage'

```

但是当我尝试在调试模式下运行应用程序时,我仍然会收到这些警告:

```
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
Warning: there were 14 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
:app:proguardDebug FAILED

```

这很奇怪,因为我还将这些规则/选项添加到依赖于OkHttp / Picasso的所有库模块中,我不知道哪里出错了,也许这是Android Studio的错误?有没有人有这个问题的线索?

我在github上打开了issue

2 个答案:

答案 0 :(得分:19)

您已禁用

的警告
-dontwarn com.squareup.**
-dontwarn okio.**

但是对于包(如发布的日志中所示)

-dontwarn org.codehaus
-dontwarn java.nio

无论哪种方式,忽略警告都不是一个好方法。

尝试保持这些类不被缩小:

-keep public class org.codehaus.**
-keep public class java.nio.**

答案 1 :(得分:2)

哦基督,我忘了为我的调试版本指定proguard文件,添加'proguardFiles'规则可以解决问题:

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable false
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationIdSuffix ".debug"
        }
    }

你努力寻找钥匙的那一刻,它就在你的口袋里。