在Android中,gif图像的动画无法正常播放
在Android中,gif图像的动画无法正常播放
对于 react native 版本>=0.60 :
在构建自己的原生代码时,默认情况下 Android 不支持 GIF 和 WebP 格式。
根据您的应用程序需求,您需要在 android/app/build.gradle
中添加一些可选模块。
implementation 'com.facebook.fresco:fresco:2.0.0'
implementation 'com.facebook.fresco:animated-gif:2.0.0'
最新的 react native 版本是 0.66 :
implementation 'com.facebook.fresco:animated-gif:2.6.0'
implementation 'com.facebook.fresco:animated-gif:2.6.0'
。 - Annie Tanimplementation 'com.facebook.fresco:animated-gif:2.6.0'
,感谢@KishanBharda。 - DarkHorse更新:react-native@0.57.0
// For animated GIF support
// ./android/app/build.gradle
implementation 'com.facebook.fresco:fresco:1.10.0'
implementation 'com.facebook.fresco:animated-gif:1.10.0'
dependencies {
// If your app supports Android versions before Ice Cream Sandwich (API level 14)
compile 'com.facebook.fresco:animated-base-support:1.3.0'
// For animated GIF support
compile 'com.facebook.fresco:animated-gif:1.3.0'
// For WebP support, including animated WebP
compile 'com.facebook.fresco:animated-webp:1.3.0'
compile 'com.facebook.fresco:webpsupport:1.3.0'
// For WebP support, without animations
compile 'com.facebook.fresco:webpsupport:1.3.0'
}
-keep class com.facebook.imagepipeline.animated.factory.AnimatedFactoryImpl {
public AnimatedFactoryImpl(com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory, com.facebook.imagepipeline.core.ExecutorSupplier);
}
针对React Native版本:0.66.4
在android/app/build.gradle文件中添加以下行:
implementation 'com.facebook.fresco:fresco:2.0.0'
// For animated GIF support
implementation 'com.facebook.fresco:animated-gif:2.6.0'
// For WebP support, including animated WebP
implementation 'com.facebook.fresco:animated-webp:2.0.0'
implementation 'com.facebook.fresco:webpsupport:2.0.0'
然后像这样使用:
<Image
source={require('../assets/splah.gif')}
style={{ width: '100%',height:'100%' }}
/>
我通过在android/app/build.gradle中执行以下操作解决了我的问题
implementation 'com.facebook.fresco:animated-gif:2.6.0'
dependencies {
// If your app supports Android versions before Ice Cream Sandwich (API level 14)
compile 'com.facebook.fresco:animated-base-support:1.3.0'
// For animated GIF support
compile 'com.facebook.fresco:animated-gif:1.3.0'
// For WebP support, including animated WebP
compile 'com.facebook.fresco:animated-webp:1.3.0'
compile 'com.facebook.fresco:webpsupport:1.3.0'
// For WebP support, without animations
compile 'com.facebook.fresco:webpsupport:1.3.0'
}