如何proguard防止剥离阵列

how to proguard prevent from stripping array

我已经在布局文件中实现了 gooeymenu:

<com.mschwartz.dailyflightbuddy.ui.GooeyMenu
    android:id="@+id/gooeymenu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_below="@id/btn_text_cockpit"
    android:layout_centerInParent="true"
    android:alpha="0.8"
    app:center_drawable="@drawable/ic_settings_white_48dp"
    app:hide_on_start="true"
    app:itemorientation="LEFT"
    app:menu_reference="@array/gooeymenu_command_array" />

menu_reference 标签指向一个文件 res/values/array.xml,其内容如下:

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

<array name="gooeymenu_command_array">

    <item>@drawable/gooey_info_item</item>
    <item>@drawable/gooey_zoom_item</item>
    <item>@drawable/gooey_center_item</item>
    <item>@drawable/gooey_city_item</item>
    <item>@drawable/gooey_airport_item</item>
    <item>@drawable/gooey_configure_item</item>
</array>

</resources>

当 运行 在调试器中时一切正常,但是当 运行 从剥离的生产版本 gooeymenu 不显示任何项目时。

我已尝试向 proguard-rules.pro 添加几个命令,包括以下命令:

-keepclassmembers class com.mschwartz.dailyflightbuddy.R$array {
    *;
}

-keepclassmembers class **.R$* {
     public static <fields>;
}

但到目前为止没有任何运气。所以我的问题是:

问题是我使用了 ObjectAnimator,它通过按名称引用方法来更改对象的 属性:

'ObjectAnimator animShowAlpha = ObjectAnimator.ofFloat(circlePoint, "Alpha", 0.0f, 1.0f);'

然而,

proguard 破坏了对象的名称,因此方法 CirclePoint.setAlpha(..) 被重命名为 a(..)。所以解决方案是向混淆器添加一行以防止重命名 class CirclePoint:

的方法

-keep class com.mschwartz.dailyflightbuddy.ui.GooeyMenu$CirclePoint { *; }

就是这样。

顺便说一句。要查看 proguard 是否重命名方法,文件 'app/build/outputs/mapping/release/mapping.txt' 有很大帮助(并且不言自明)。