在我的六个物理设备和仿真器中,应用程序没有崩溃,但是在Firebase 4/10设备中进行测试时,测试失败:
java.lang.OutOfMemoryError:无法分配42465612字节分配 具有13253240个空闲字节和12MB直到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)
答案 0 :(得分:0)
正如Christophe在评论中已经提到的那样,这看起来像Firebase Test Lab的问题。它实际上是在告诉您您没有充分利用可用的设备资源。
该错误消息表明您的应用尝试分配40 MB的图像,这肯定太多了。
尝试使您对图片的使用更加合理:
VectorDrawable
,因为在相同质量下,它们的压缩率比GIF更好ShapeDrawable
或NinePatchDrawable
,对于需要根据设备尺寸和屏幕密度进行缩放的背景而言,这尤其有用。