在使用Facebook的fresco 最新版本3.0.0的过程中发现了一个极坑的bug,竟然在加载jpeg图片时会报找不到so的 crash:

Fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed: library "libnative-imagetranscoder.so" not found
       at java.lang.Runtime.loadLibrary0(Runtime.java:1082)
       at java.lang.Runtime.loadLibrary0(Runtime.java:1003)
       at java.lang.System.loadLibrary(System.java:1661)
       at com.facebook.soloader.nativeloader.SystemDelegate.loadLibrary(SystemDelegate.java:24)
       at com.facebook.soloader.nativeloader.NativeLoader.loadLibrary(NativeLoader.java:52)
       at com.facebook.soloader.nativeloader.NativeLoader.loadLibrary(NativeLoader.java:30)
       at com.facebook.imagepipeline.nativecode.NativeJpegTranscoderSoLoader.ensure(NativeJpegTranscoderSoLoader.java:33)
       at com.facebook.imagepipeline.nativecode.NativeJpegTranscoder.<init>(NativeJpegTranscoder.java:59)
       at com.facebook.imagepipeline.nativecode.NativeJpegTranscoderFactory.createImageTranscoder(NativeJpegTranscoderFactory.java:43)
       at com.facebook.imagepipeline.transcoder.MultiImageTranscoderFactory.getNativeImageTranscoder(MultiImageTranscoderFactory.kt:59)
       at com.facebook.imagepipeline.transcoder.MultiImageTranscoderFactory.createImageTranscoder(MultiImageTranscoderFactory.kt:40)
       at com.facebook.imagepipeline.producers.ResizeAndRotateProducer$TransformingConsumer.onNewResultImpl(ResizeAndRotateProducer.java:166)
       at com.facebook.imagepipeline.producers.ResizeAndRotateProducer$TransformingConsumer.onNewResultImpl(ResizeAndRotateProducer.java:84)
       at com.facebook.imagepipeline.producers.BaseConsumer.onNewResult(BaseConsumer.java:89)
       at com.facebook.imagepipeline.producers.AddImageTransformMetaDataProducer$AddImageTransformMetaDataConsumer.onNewResultImpl(AddImageTransformMetaDataProducer.java:49)
       at com.facebook.imagepipeline.producers.AddImageTransformMetaDataProducer$AddImageTransformMetaDataConsumer.onNewResultImpl(AddImageTransformMetaDataProducer.java:33)
       at com.facebook.imagepipeline.producers.BaseConsumer.onNewResult(BaseConsumer.java:89)
       at com.facebook.imagepipeline.producers.MultiplexProducer$Multiplexer.onNextResult(MultiplexProducer.java:510)
       at com.facebook.imagepipeline.producers.MultiplexProducer$Multiplexer$ForwardingConsumer.onNewResultImpl(MultiplexProducer.java:569)
       at com.facebook.imagepipeline.producers.MultiplexProducer$Multiplexer$ForwardingConsumer.onNewResultImpl(MultiplexProducer.java:562)
       at com.facebook.imagepipeline.producers.BaseConsumer.onNewResult(BaseConsumer.java:89)
       at com.facebook.imagepipeline.producers.EncodedMemoryCacheProducer$EncodedMemoryCacheConsumer.onNewResultImpl(EncodedMemoryCacheProducer.java:181)
       at com.facebook.imagepipeline.producers.EncodedMemoryCacheProducer$EncodedMemoryCacheConsumer.onNewResultImpl(EncodedMemoryCacheProducer.java:123)
       at com.facebook.imagepipeline.producers.BaseConsumer.onNewResult(BaseConsumer.java:89)
       at com.facebook.imagepipeline.producers.DiskCacheReadProducer$1.then(DiskCacheReadProducer.java:113)
       at com.facebook.imagepipeline.producers.DiskCacheReadProducer$1.then(DiskCacheReadProducer.java:93)
       at bolts.Task$14.run(Task.java:872)
       at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
       at bolts.Task.completeImmediately(Task.java:863)
       at bolts.Task.access$000(Task.java:32)
       at bolts.Task$10.then(Task.java:654)
       at bolts.Task$10.then(Task.java:651)
       at bolts.Task.runContinuations(Task.java:956)
       at bolts.Task.trySetResult(Task.java:994)
       at bolts.TaskCompletionSource.trySetResult(TaskCompletionSource.java:39)
       at bolts.TaskCompletionSource.setResult(TaskCompletionSource.java:62)
       at bolts.Task$4.run(Task.java:357)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
       at com.facebook.imagepipeline.core.PriorityThreadFactory.newThread$lambda$0(PriorityThreadFactory.kt:37)
       at com.facebook.imagepipeline.core.PriorityThreadFactory.$r8$lambda$IPp7Vm9a1KDy8D4770JTjI9qOG4()
       at com.facebook.imagepipeline.core.PriorityThreadFactory$$ExternalSyntheticLambda0.run(:4)
       at java.lang.Thread.run(Thread.java:1012)

 经过各种分析发现:但“nativeimagetranscoder-2.6.0”几乎有700kb。解压文件,我们可以找到libnative-imagetranscoder.so
https://repo1.maven.org/maven2/com/facebook/fresco/nativeimagetranscoder/2.6.0/nativeimagetranscoder-2.6.0.aar

我们可以在maven中查看文件。“nativeimagetranscoder-3.0.0”只有 7kb。
https://repo1.maven.org/maven2/com/facebook/fresco/nativeimagetranscoder/3.0.0/nativeimagetranscoder-3.0.0.aar

 这就说明在3.0.0的版本中打包发布时忘记了打包资源造成的,Facebook 大厂人员竟然也会犯这种低级错误。

原因找到了,看下解决方案吧:

解决方案一:把fresco版本降到2.6.0版本,该版本可以正常工作

 解决方案二:既然3.0.0版本找不到libnative-imagetranscoder.so库,2.6.0版本可以用,那就把2.6.0中的libnative-imagetranscoder.so引进去:

implementation('com.facebook.fresco:nativeimagetranscoder') {
        version {
            strictly '2.6.0'
        }
}

 解决方案三:将2.6.0下的“libnative imagetranscoder.so”文件复制到项目jniLibs目录下使用

 总结语:还是期待官方及时修复这个严重的问题。可悲的是fresco库好久没有更新了


 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐