1

我正在使用 PropertyValuesHolder 为我的 Android 应用程序中的一些视图设置动画。动画在我的设备上运行良好,直到我在没有任何动画的地方进行发布构建。(我认为问题与混淆有关,因为属性名称被称为字符串名称,例如“Panel1W”)

没有抛出异常。只是没有动画。我在http://proguard.sourceforge.net/index.html#manual/troubleshooting.html上能找到的最接近的东西 是 NoSuchMethodException,我们需要在 proguard.cfg 中使用 -keep 命令。我在我的 proguard.cfg 中尝试了以下但没有成功

-keep public class com.mycompany.myapp.HomeActivity { java.lang.Integer getPanel1W(); }
-keep public class com.mycompany.myapp.HomeActivity { void setPanel1W(java.lang.Integer); }
-keep public class com.mycompany.myapp.HomeActivity { java.lang.Integer getPanel2W(); }
-keep public class com.mycompany.myapp.HomeActivity { void setPanel2W(java.lang.Integer); }
-keep public class com.mycompany.myapp.HomeActivity { java.lang.Integer getPanel3W(); }
-keep public class com.mycompany.myapp.HomeActivity { void setPanel3W(java.lang.Integer); }

我错过了什么吗?这是下面的代码。谢谢。

PropertyValuesHolder[] arrayOfPropertyValuesHolder = new PropertyValuesHolder[3];
arrayOfPropertyValuesHolder[0] = PropertyValuesHolder.ofInt("Panel1W", mPanel1.getWidth(), 0);
arrayOfPropertyValuesHolder[1] = PropertyValuesHolder.ofInt("Panel2W", 360, 1280);
arrayOfPropertyValuesHolder[2] = PropertyValuesHolder.ofInt("Panel3W", 0, (int)(screenWidth * 0.65));

ObjectAnimator localObjectAnimator = ObjectAnimator.ofPropertyValuesHolder(this,
arrayOfPropertyValuesHolder).setDuration(time);
localObjectAnimator.setInterpolator(sCollapseInterpolator);
localObjectAnimator.start();

我也有 getter 和 setter 方法。

    public int getPanel1W() {
        return ((ViewGroup.MarginLayoutParams) mPanel1.getLayoutParams()).width;
    }

    public void setPanel1W(int paramInt) {
        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mPanel1.getLayoutParams();
        lp.width = paramInt;
        mPanel1.setLayoutParams(lp);
    }

    public int getPanel2W() {
        return ((ViewGroup.MarginLayoutParams) mPanel2.getLayoutParams()).width;
    }

    public void setPanel2W(int paramInt) {
        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mPanel2.getLayoutParams();
        lp.width = paramInt;
        mPanel2.setLayoutParams(lp);
    }  

    public int getPanel3W() {
        return ((ViewGroup.MarginLayoutParams) mPanel3.getLayoutParams()).width;
    }

    public void setPanel3W(int paramInt) {
        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mPanel3.getLayoutParams();
        lp.width = paramInt;
        mPanel3.setLayoutParams(lp);        
    }
4

2 回答 2

6

诀窍在于 调用的方法PropertyValuesHolderset*or get*,因此ProGuard保留这些方法的规则是:

void set*(***);
*** get*();

因此,基于此,如果您的动画目标只是少数几个类之一,请为每个动画目标类添加以下内容:

-keep class my.package.MyClass {
    void set*(***);
    *** get*();
}

如果您的所有目标都扩展了某个基类,您可以添加一条规则来保存它们:

-keep class * extends my.package.MyBaseClass {
    void set*(***);
    *** get*();
}
于 2013-09-29T08:39:40.027 回答
0

请检查字符串“Panel1W”、“Panel2W”和“Panel3W”是否被proguard混合。我认为您可以在类中定义这些字符串并在proguard.cfg中定义这些字符串以保护这些字符串。

于 2012-07-26T09:01:26.620 回答