facebook / fresco

An Android library for managing images and the memory they use.
https://frescolib.org/
MIT License
17.07k stars 3.75k forks source link

When building via App Bundle, Fresco fails to find "libimagepipeline.so" #2253

Closed icerfish closed 5 years ago

icerfish commented 5 years ago

Description

When launching an Activity that uses Fresco, which has been generated via Android App Bundle, it fails to find "libimagepipeline.so" and crashes the application.

Reproduction

  1. Create a sample application that uses Fresco
  2. Generate a signed Bundle
  3. Using Bundle Tool build the APKs from the Bundle
  4. Using Bundle Tool, install the APK on to your device
  5. Navigate to Activity where Fresco is initialised
  6. Observe crash

Solution

I originally thought this might have been an issue with minify, R8, or Proguard, but I disabled all of those, and still observed the same result when building via App Bundle.

I have tested other components of my app that also use native libraries, but they all operate as expected, only with Fresco struggling to load the respective binary.

A temporary, but not ideal solution I found is disabling splitting of APK's by abi using the following configuration, but including all the binaries results in a significantly larger APK size.

android {
    // Rest of your configuration here

    bundle {
        abi {
            enableSplit false
        }
    }
}

Additional Information

KimiChiu commented 5 years ago

Does your error message looks like this one? #2049

icerfish commented 5 years ago

Yes, roughly. However this issue while related I think more focuses on the lack of support for Android App Bundle in either Fresco or SoLoader and splitting binaries that way.

I could be mistaken, but this issue is reproducible on every device I've tested, not just select brands.

And as per Fresco shipping guides, there is no note of the use case of shipping via Android App Bundles, and we can't use the splits key as when you use bundle the splits key is ignored.

On Tue, 11 Dec 2018, 06:40 KimiChiu, notifications@github.com wrote:

Does your error message looks like this one? #2049 https://github.com/facebook/fresco/issues/2049

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/facebook/fresco/issues/2253#issuecomment-446089907, or mute the thread https://github.com/notifications/unsubscribe-auth/ABUQnQ4cZ-sWkG5b72Ea81wiQjS02yjlks5u31NxgaJpZM4ZIsuf .

lambdapioneer commented 5 years ago

Hi @icerfish,

Thank you for filing this issue with all the required details (maybe add a paste of the error if you have time). I can imagine that Fresco might not fully support app bundles and I do not think that we have ever tested the interplay.

I will mark this as a "bug" and "help-wanted" hoping that this is something the open-source community can help us with.

icerfish commented 5 years ago

Hi @lambdapioneer,

Here is the stacktrace:

    Process: com.gobuzzvault.android, PID: 17499
    java.lang.NoClassDefFoundError: com.facebook.imagepipeline.memory.NativeMemoryChunk
        at com.facebook.imagepipeline.memory.NativeMemoryChunkPool.alloc(NativeMemoryChunkPool.java:25)
        at com.facebook.imagepipeline.memory.NativeMemoryChunkPool.alloc(NativeMemoryChunkPool.java:13)
        at com.facebook.imagepipeline.memory.BasePool.get(BasePool.java:267)
        at com.facebook.imagepipeline.memory.MemoryPooledByteBufferOutputStream.<init>(MemoryPooledByteBufferOutputStream.java:51)
        at com.facebook.imagepipeline.memory.MemoryPooledByteBufferFactory.newByteBuffer(MemoryPooledByteBufferFactory.java:73)
        at com.facebook.imagepipeline.memory.MemoryPooledByteBufferFactory.newByteBuffer(MemoryPooledByteBufferFactory.java:24)
        at com.facebook.imagepipeline.producers.LocalFetchProducer.getByteBufferBackedEncodedImage(LocalFetchProducer.java:87)
        at com.facebook.imagepipeline.producers.LocalFetchProducer.getEncodedImage(LocalFetchProducer.java:99)
        at com.facebook.imagepipeline.producers.LocalContentUriFetchProducer.getCameraImage(LocalContentUriFetchProducer.java:100)
        at com.facebook.imagepipeline.producers.LocalContentUriFetchProducer.getEncodedImage(LocalContentUriFetchProducer.java:76)
        at com.facebook.imagepipeline.producers.LocalFetchProducer$1.getResult(LocalFetchProducer.java:52)
        at com.facebook.imagepipeline.producers.LocalFetchProducer$1.getResult(LocalFetchProducer.java:48)
        at com.facebook.common.executors.StatefulRunnable.run(StatefulRunnable.java:43)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at com.facebook.imagepipeline.core.PriorityThreadFactory$1.run(PriorityThreadFactory.java:51)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libimagepipeline.so
        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:703)
        at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:564)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:500)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:455)
        at com.facebook.imagepipeline.nativecode.ImagePipelineNativeLoader.load(ImagePipelineNativeLoader.java:40)
        at com.facebook.imagepipeline.memory.NativeMemoryChunk.<clinit>(NativeMemoryChunk.java:31)
        at com.facebook.imagepipeline.memory.NativeMemoryChunkPool.alloc(NativeMemoryChunkPool.java:25)
        at com.facebook.imagepipeline.memory.NativeMemoryChunkPool.alloc(NativeMemoryChunkPool.java:13)
        at com.facebook.imagepipeline.memory.BasePool.get(BasePool.java:267)
        at com.facebook.imagepipeline.memory.MemoryPooledByteBufferOutputStream.<init>(MemoryPooledByteBufferOutputStream.java:51)
        at com.facebook.imagepipeline.memory.MemoryPooledByteBufferFactory.newByteBuffer(MemoryPooledByteBufferFactory.java:73)
        at com.facebook.imagepipeline.memory.MemoryPooledByteBufferFactory.newByteBuffer(MemoryPooledByteBufferFactory.java:24)
        at com.facebook.imagepipeline.producers.LocalFetchProducer.getByteBufferBackedEncodedImage(LocalFetchProducer.java:87)
        at com.facebook.imagepipeline.producers.LocalFetchProducer.getEncodedImage(LocalFetchProducer.java:99)
        at com.facebook.imagepipeline.producers.LocalContentUriThumbnailFetchProducer.getThumbnail(LocalContentUriThumbnailFetchProducer.java:135)
        at com.facebook.imagepipeline.producers.LocalContentUriThumbnailFetchProducer.getCameraImage(LocalContentUriThumbnailFetchProducer.java:100)
        at com.facebook.imagepipeline.producers.LocalContentUriThumbnailFetchProducer.getEncodedImage(LocalContentUriThumbnailFetchProducer.java:75)
        at com.facebook.imagepipeline.producers.LocalFetchProducer$1.getResult(LocalFetchProducer.java:52) 
        at com.facebook.imagepipeline.producers.LocalFetchProducer$1.getResult(LocalFetchProducer.java:48) 
        at com.facebook.common.executors.StatefulRunnable.run(StatefulRunnable.java:43) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
        at com.facebook.imagepipeline.core.PriorityThreadFactory$1.run(PriorityThreadFactory.java:51) 
        at java.lang.Thread.run(Thread.java:764)

It looks similar to issues that others are having.

From looking around the codebase, it looks like this isn't an issue with Fresco itself, but more the SoLoader library. I will cross post the issue over to that repository, and workload allowing dedicate some time to try work out what is the issue exactly.

beatrizz commented 5 years ago

Hi, I had the same issue when using app bundles, as described in https://github.com/facebook/fresco/issues/2049#issuecomment-441088387

Using Fresco 1.11 and setting .experiment().setNativeCodeDisabled(true) in Fresco's ImagePipelineConfig made static images work for me but GIFs crashed with a different stacktrace, which looked like the same SoLoader issue with a different library. @icerfish , this may help you if you're not using GIFs.

nesterov-n commented 5 years ago

I have found out an issue in SoLoader lib used by Fresco. I have prepared PR with a fix: facebook/soloader#26 That fix makes fresco works fine with app bundle. I have published the patched version of SoLoader lib. You can use it in your project if you can't wait till PR is merged.

repositories {
    maven {
        url  "https://dl.bintray.com/nnesterov/maven" 
    }
}

compile('com.facebook.fresco:fresco:1.10.0') {
    exclude group: 'com.facebook.soloader', module: 'soloader'
}
compile("com.avito.android:patched-soloader:0.1.0")
nesterov-n commented 5 years ago

The previous version of patched-soloader didn't work on pre-lollipop devices. I've fixed it. Use compile("com.avito.android:patched-soloader:0.1.1")

theromis commented 5 years ago

@nesterov-n thanks for great fix, any progress to integrate it into fresco?

sailesh2 commented 5 years ago

@nesterov-n i am also facing the same issue. please let me know when will it be integrated into fresco?

nesterov-n commented 5 years ago

Hi @theromis and @sailesh2 I don't work at Facebook (it's so sad). I'm just a Fresco user but I couldn't wait for a fix. So I had to debug it and fix. Currently, I use the patched version of soloder lib for my project as I described in the comment above. Most recent version is com.avito.android:patched-soloader:0.1.2

My PR to soloader lib is being reviewed now but soloader maintainer tells that there is no estimation of new soloader lib release. So It's impossible to estimate when Fresco will use this new version.

If it's urgent you can use my patched version. We published bundle with fresco to production. Works well.

luizguilhermefr commented 5 years ago

Cannot figure out why isn't this workaround integrated into Fresco yet.

oprisnik commented 5 years ago

We've landed the SoLoader fix. We'll release a new Fresco version soon once the SoLoader version has been released.

iwo commented 5 years ago

@oprisnik what's the ETA for the releases? I get that it requires coordination of 2 teams but at least some rough number would help many developers decide if they should apply workaround above or wait for the release.

oprisnik commented 5 years ago

SoLoader v0.6.0 has just been released and I've updated the Fresco dependency (6fc071d1892166d11d1f237f10e2d9bcdf858087). We want to wait for the MIT licensed Bolts release (#2257). If that release takes longer than expected, we are going to skip it for now and release without that. In any case, the new version should be out in a couple of days.

luizguilhermefr commented 5 years ago

I don't want to be dull, but shouldn't fresco be released? Seems that this issue you pointed out hasn't received any activity for a while.

oprisnik commented 5 years ago

We just released version 1.12.0 that includes the fixed SoLoader version.

ProHzen commented 5 years ago

try add proguard

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 *; }

Do not strip any method/class that is annotated with @DoNotOptimize

-keep @com.facebook.soloader.DoNotOptimize class -keepclassmembers class { @com.facebook.soloader.DoNotOptimize *; }

Keep native methods

-keepclassmembers class * { native ; }

-dontwarn okio. -dontwarn com.squareup.okhttp. -dontwarn okhttp3. -dontwarn javax.annotation. -dontwarn com.android.volley.toolbox. -dontwarn com.facebook.infer.

samyakjain commented 5 years ago

@ProHzen Has this fixed the soloader crash ?

ProHzen commented 5 years ago

Yes, I solved it.

ishroid commented 5 years ago

it is still in fresco 2.0.0, :-( , please suggest workaround i only have issue with nexus devices

funnyzhaov commented 5 years ago

@ProHzen Hello, can you send me your confusion list?I tried it the way you did, but it didn't work. Info: fresco:1.13.0 classpath 'com.android.tools.build:gradle:3.5.1'