Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NineOldAndroids ObjectAnimators don't work with ProGuard and signed apk

I am using NineOldAndroids' ObjectAnimators to fade in Android Map v2 markers with the following code:

mMarkerSelected = mMap.addMarker(new MarkerOptions()
        .position(location.getLatLng())
        .title(location.getName())
        .snippet(location.getId())
        .icon(BitmapDescriptorFactory.defaultMarker(location.getMarkerHue())));
mMarkerSelected.setAlpha(0.0f);
ObjectAnimator.ofFloat(mMarkerSelected, "alpha", 0.0f, 1.f)
                .setDuration(300).start();

This works perfectly with debuggable versions of the apk.

However, when I sign my apk and use ProGuard, suddenly marker doesn't fade in. My guess is that the alpha attribute has been obfuscated so that passing "alpha" into ObjectAnimator.ofFloat doesn't match up with the obfuscated alpha attribute of the Marker. How can I get the animation to work when using ProGuard?

Just for completeness, this is the only contents of my proguard-rules.txt

-dontwarn com.squareup.okhttp.**
like image 891
well Avatar asked Mar 01 '14 21:03

well


1 Answers

It uses reflection so you need your method names intact i.e. setAlpha(), something like this in your proguard config:

 # This is due to ObjectAnimator using reflection to access get/sets
 -keep class com.your.package.ClassThatUsesObjectAnimator { *; }
like image 59
Blundell Avatar answered Oct 13 '22 01:10

Blundell