5

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.**
well
  • 647
  • 1
  • 8
  • 20

2 Answers2

11

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 { *; }
Blundell
  • 75,855
  • 30
  • 208
  • 233
  • 2
    Thanks! I went with `-keepclassmembers class com.google.android.gms.maps.model.Marker { *; }`. Can you update the answer, or should I instead keep my personal class that uses ObjectAnimator? – well Mar 01 '14 at 22:18
  • You can do either, personally I would have a class to control the animation but not proguarding the marker is also fine – Blundell Mar 01 '14 at 23:35
2

Nineolddroids library is open sourced already so running proguard on it is pointless.

If you have a choice between obfuscating your own source file or a 3rd party open sourced library it would be wise to choose your own source file.

Add these lines to your proguard-project.txt and your application will work fine.

## Nineolddroid related classes to ignore

-keep class com.nineoldandroids.animation.** { *; }
-keep interface com.nineoldandroids.animation.** { *; }
-keep class com.nineoldandroids.view.** { *; }
-keep interface com.nineoldandroids.view.** { *; }
Arif Nadeem
  • 8,524
  • 7
  • 47
  • 78