Proguard破坏了可绘制文件 [英] Proguard corrupts drawable files

查看:81
本文介绍了Proguard破坏了可绘制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对proguard遇到了一个奇怪的问题,以某种方式破坏了我的有效可绘制文件.没有proguard可绘制的显示就可以. Proguard是否应该缩小xml drawables?

I have strange issue with proguard, somehow it breaks my valid drawable file. Without proguard drawable shows ok. Is proguard supposed to minify xml drawables?

drawable/wide_btn_round_white.xml :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle" >
            <corners android:radius="25dip" />
            <padding android:bottom="10dp"/>
            <padding android:top="10dp"/>
            <solid android:color="@color/colorOrangeGetStarted" />
        </shape>
    </item>
</selector>

变成这样

<?xml version="1.0" encoding="utf-8"?>
<x />

build.gradle :

release {
        minifyEnabled true
        shrinkResources true
        signingConfig signingConfigs.release
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

proguard-rules.pro :

-keepattributes *Annotation*
-keepattributes Signature
-keepclassmembers class ** {
    @com.squareup.otto.Subscribe public *;
    @com.squareup.otto.Produce public *;
}
-dontwarn okio.**
-dontwarn retrofit2.Platform$Java8
-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
    public static int e(...);
}
-keep class com.stripe.** { *; }
-keepclassmembers class com.myapp.services.http.** {
    <fields>;
}
-keepclassmembers class com.myapp.services.ws.** {
    <fields>;
}
-keepclassmembers class * extends java.lang.Enum {
    <fields>;
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

编辑: 发生此问题的原因是shrinkResources.它混淆了仅在style.xml中指定的所有可绘制对象. 例如,如果我有一个在styles.xmlstyles.xml中的按钮:

EDIT: This issue happens because of shrinkResources. It obfuscates all drawables that are specified ONLY in style.xml. So for example if I have a button that has style="@style/MyStyle" and in styles.xml:

<style name="MyStyle">
    <item name="android:background">@drawable/wide_btn_round_white</it‌​em>
</style>.

wide_btn_round_white.xml将要被打破.但是,如果我直接在按钮上指定背景,一切都会正常.根据维基我可以创建app/src/main/res/values/keep.xml:

wide_btn_round_white.xml is gonna be broken. But if I specify background directly on button everything would work OK. According wiki i can create app/src/main/res/values/keep.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:keep="@drawable/wide_btn_round_white" /> 

但是这个东西不起作用.据我了解,它仅指定不应删除该文件.

But this thing doesn't work. As I understand it only specifies that this file shouldn't be removed.

任何帮助将不胜感激!

最诚挚的问候,

推荐答案

通常,Proguard不适用于xml文件,仅适用于Java.所以我认为您的构建有点破坏您的文件.也许打开一个新项目并复制您的源代码和.git文件(如果有的话)会有所帮助

In general Proguard does not work on xml files, only Java. So I think your build is some how corrupting your file. Perhaps opening a new project and copy there your source and the .git file(if you got one) will help

另一件事可能是 Android收缩资源,因此请尝试将rinkleResources设置为false,看看是否有帮助.如果是这样,请使用 tools:keep 进行保存您有问题的资源要远离收缩器.

The other thing could be Android shrink resources, so try setting shrinkResources to false and see if it helps. If it does, use tools:keep to keep your problematic resources away from shrinker.

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:keep="@layout/l_used*_c,@layout/l_used_a,@layout/l_used_b*"
    tools:discard="@layout/unused2" />

这篇关于Proguard破坏了可绘制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆