Skip to content

Unable to use GIF or WebP in a release apk, Fresco imagepipeline is stripped by ProGuard #7760

Description

@charpeni

If we build an apk in release with ProGuard enabled, when we load a scene that include a GIF or WebP image from the Image component, the application will crash with the following error :

java.lang.UnsatisfiedLinkError: JNI_ERR returned from JNI_OnLoad in "/data/app/com.imagepipeline-1/lib/x86/libgifimage.so"

Tested with react-native@0.26.2.

Steps to reproduce

import { Image } from 'react-native';

export default function ImagePipeline() {
  return (
    <Image
      style={{ flex: 1 }}
      source={{ uri: 'https://media.giphy.com/media/GRld0uPxi1V1C/giphy.gif' }}
      resizeMode={'cover'}
    />
  );
}
  1. Be sure you're using a GIF or WebP icon with the Image component.
  2. Enable ProGuard in release builds. In android/app/build.gradle def enableProguardInReleaseBuilds = true
  3. Build your application in release.
  4. Open the scene that contains the GIF or WebP.
  5. Enjoy the crash.

Proposed solution

Fresco documentation recommends the following ProGuard configuration :

# Keep our interfaces so they can be used by other ProGuard rules.
# See http://sourceforge.net/p/proguard/bugs/466/
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip

# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
    @com.facebook.common.internal.DoNotStrip *;
}

# Keep native methods
-keepclassmembers class * {
    native <methods>;
}

-dontwarn okio.**
-dontwarn com.squareup.okhttp.**
-dontwarn javax.annotation.**
-dontwarn com.android.volley.toolbox.**

So I tested this by adding it to the React Native proguard file like this :

 # React Native

 # Keep our interfaces so they can be used by other ProGuard rules.
 # See http://sourceforge.net/p/proguard/bugs/466/
 -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
 -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
+-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip

 # Do not strip any method/class that is annotated with @DoNotStrip
 -keep @com.facebook.proguard.annotations.DoNotStrip class *
+-keep @com.facebook.common.internal.DoNotStrip class *
 -keepclassmembers class * {
     @com.facebook.proguard.annotations.DoNotStrip *;
+    @com.facebook.common.internal.DoNotStrip *;
 }

I built the apk and everything worked fine.

An another solution would be to add this line to the proguard :

-keep class com.facebook.imagepipeline.** { *; }

I'll do the pull request, but before that I just need your opinion.

Do you think this could have side effects?
Do you prefer a method?
Any other ideas?

cc @AndrewJack, @mkonicek, @janicduplessis

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions