0

In my half a dozens of physical devices and in emulators the app doesn't crashes, but while testing in Firebase 4/10 devices test failed with:

java.lang.OutOfMemoryError: Failed to allocate a 42465612 byte allocation with 13253240 free bytes and 12MB until OOM

FATAL EXCEPTION: main
Process: technocrats.com.gymaholic, PID: 24886
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2150)
at android.content.res.Resources.getDrawable(Resources.java:715)
at android.support.v7.widget.ResourcesWrapper.getDrawable(ResourcesWrapper.java:130)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:46)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:465)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:102)
at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:59)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:79)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:69)
at android.support.v7.app.AppCompatViewInflater.createImageButton(AppCompatViewInflater.java:202)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:122)
at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at technocrats.com.gymaholic.MainActivity.onCreate(MainActivity.java:57)
at android.app.Activity.performCreate(Activity.java:5275)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255)
at android.app.ActivityThread.access$800(ActivityThread.java:142)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5118)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at dalvik.system.NativeStart.main(Native Method)
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
DEXTOR_ANTONY
  • 300
  • 1
  • 12
  • I uploaded a debug apk ! Is that the issue? – DEXTOR_ANTONY Nov 15 '18 at 08:41
  • This doesn't look like a Firebase issue. Are you loading a large bitmap/drawable from resources? Can you share your code from MainActivity, especially line 57 & the onCreate method (`at technocrats.com.gymaholic.MainActivity.onCreate(MainActivity.java:57)`)? – Grimthorr Nov 15 '18 at 08:50
  • I'm not sure whats the problem all i have in line 57 is setContentView(R.layout.activity_main); and I'm using GIF.@Grimthorr – DEXTOR_ANTONY Nov 15 '18 at 08:58
  • How big is the GIF? The error occurs when loading a large resource file into memory (for an `ImageView` for example), so you'll need to reduce the size of the image or reduce the number of images. Alternatively, you can [enable `largeHeap`](https://stackoverflow.com/a/29862316/2754146) which might help. In the meantime, please [edit your question](https://meta.stackexchange.com/a/21789) to include all relevant information to create a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve), including your code and layout XML so we can formulate an answer. – Grimthorr Nov 15 '18 at 09:31
  • i have two GIF 12kb and 800kb, I also figured i have 1.6mb image background on 10 layouts @Grimthorr – DEXTOR_ANTONY Nov 15 '18 at 09:54
  • instead of using bitmapfactory I decided to use the nuget Glide and it solved all my OOM issues. I didn't manage the memory correctly.. and I didn't want to waste my time doing it since someone already did it into this awesome nuget. – Christophe Chenel Nov 15 '18 at 14:26
  • Seriously i have no idea what you're talking about sorry,Do you know the exact reason why this is happening? Can i still publish my app,is it fatal? @Christophe Gudlake – DEXTOR_ANTONY Nov 15 '18 at 14:54
  • You probably put in cache the bitmap, they are too big or something like that. – Christophe Chenel Nov 15 '18 at 15:09
  • In my half a dozen of physical devices it just works fine can still i publish it? @ChristopheGudlake – DEXTOR_ANTONY Nov 15 '18 at 15:35
  • well that's your choice. At this point it's a quality control that fails..So their will be crashes in the field and you will lose your user base if it crashes all the time. You could also just manage your bitmap differently and their will be probably no crashes at all. Take a look at Glide or Picasso to manage your bitmap.https://github.com/bumptech/glide or http://square.github.io/picasso/ – Christophe Chenel Nov 15 '18 at 15:44

1 Answers1

0

As Christophe already mentioned in the comments, this doesn't look like an issue with Firebase Test Lab. It actually is telling you that you are not making good use of the available device resources.

The error message suggests that your app tries to allocate a 40 MB image, which is definitely way too much.

Try to make your usage of images more reasonable:

  • Use PNGs or VectorDrawables as they give you a better compression ratio than GIF for the same quality
  • If you need animations, try out animated vector drawables.
  • Use other types of drawables like ShapeDrawable or NinePatchDrawable, which are especially useful for backgrounds that need to scale based on device dimensions and screen densities.
Maik
  • 3,419
  • 1
  • 23
  • 34
  • I there any quick fix i have like 70+ images in image view,2 GIF,5 mp3 in RAW folder @maik – DEXTOR_ANTONY Nov 16 '18 at 07:16
  • Without more context on how your app works and how it utilizes those images, there's no easy quick fix. Maybe try to understand why you get that error saying that it tries to allocate a 40 MB buffer for an image. As a point of reference: a 32 bit bitmap with width 1024 and height 1024 would take up 4 MB. So, what are you doing that it needs 10 times that amount? – Maik Nov 16 '18 at 08:54