运行在Android KitKat上的代码在Lollipop设备上崩溃

3

我一直在开发一个社交媒体应用,目前在所有运行Android 4.4及以下系统的设备上表现良好。

但是当我尝试在Lollipop及更高版本的操作系统上运行它时,应用程序崩溃了。

经过几周的调试,我仍然只能看到与我的代码无关的错误消息:

01-22 00:37:09.481 6661-6672/supernet.interactapp A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x74616433 in tid 6672 (FinalizerDaemon)
01-22 00:37:09.480 6661-6676/supernet.interactapp I/art: Background sticky concurrent mark sweep GC freed 7891(375KB) AllocSpace objects, 4(64KB) LOS objects, 35% free, 723KB/1117KB, paused 39.238ms total 140.184ms
01-22 00:37:09.501 5229-5290/supernet.interactapp:remote E/Ultra Admin: retrieve messages called: CONNECTED
01-22 00:37:09.571 6661-6676/supernet.interactapp I/art: Background partial concurrent mark sweep GC freed 447(37KB) AllocSpace objects, 0(0B) LOS objects, 57% free, 764KB/1788KB, paused 6.993ms total 51.547ms
01-22 00:37:09.588 85-85/? I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-22 00:37:09.588 85-85/? I/DEBUG: Build fingerprint: 'generic/vbox86p/vbox86p:5.1/LMY47D/buildbot11172007:userdebug/test-keys'
01-22 00:37:09.588 85-85/? I/DEBUG: Revision: '0'
01-22 00:37:09.588 85-85/? I/DEBUG: ABI: 'x86'
01-22 00:37:09.588 85-85/? I/DEBUG: pid: 6661, tid: 6672, name: FinalizerDaemon  >>> supernet.interactapp <<<
01-22 00:37:09.588 85-85/? I/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x74616433
01-22 00:37:09.651 85-85/? I/DEBUG:     eax 7461642f  ebx f6352bac  ecx 00000001  edx 70612f61
01-22 00:37:09.651 85-85/? I/DEBUG:     esi f3e9ebe0  edi f3e9ebe0
01-22 00:37:09.652 85-85/? I/DEBUG:     xcs 00000023  xds 0000002b  xes 0000002b  xfs 0000003f  xss 0000002b
01-22 00:37:09.652 85-85/? I/DEBUG:     eip f5fd09fb  ebp 00000000  esp eebff950  flags 00210282
01-22 00:37:09.653 85-85/? I/DEBUG:     #00 pc 001019fb  /system/lib/libskia.so (SkBitmap::freePixels()+43)
01-22 00:37:09.653 85-85/? I/DEBUG:     #01 pc 00101a6a  /system/lib/libskia.so (SkBitmap::~SkBitmap()+26)
01-22 00:37:09.667 85-85/? I/DEBUG:     #02 pc 000e02e3  /system/lib/libandroid_runtime.so
01-22 00:37:09.687 85-85/? I/DEBUG:     #03 pc 0001d992  /data/dalvik-cache/x86/system@framework@boot.oat
01-22 00:37:09.697 85-85/? I/DEBUG:     #04 pc 70612f60  <unknown>
01-22 00:37:09.704 85-85/? I/DEBUG:     #05 pc 892cec82  <unknown>
01-22 00:37:09.740 85-85/? W/libbacktrace: virtual bool Backtrace::VerifyReadWordArgs(uintptr_t, word_t*): invalid pointer 0x74616437

我的应用程序中完全没有使用本地代码。

可能是什么原因呢?

我已经尝试在代码中关闭硬件加速,但这没有帮助。当我尝试打开联系人列表时,应用程序崩溃了。我的联系人列表几乎只有3张图片,它们的大小都只有几十千字节。

最后,这是加载位图的代码:

public static Bitmap decodeSampledBitmapFromFile(File data,
                                                     int reqWidth, int reqHeight) {

        // First decode with inJustDecodeBounds=true to check dimensions
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(data.getAbsolutePath(), options);

        // Calculate inSampleSize
        options.inSampleSize = calculateInSampleSize(options, reqWidth,
                reqHeight);

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;
        return BitmapFactory.decodeFile(data.getAbsolutePath(), options);
    }

这个崩溃可能是什么原因引起的?
更新
我注意到系统似乎会因为本地代码中的某些情况而耗尽内存或其他资源?
    01-23 10:30:31.561 2106-2121/? I/art: Background sticky concurrent mark

sweep GC freed 7418(355KB) AllocSpace objects, 3(48KB) LOS objects, 1% free,

 21MB/21MB, paused 7.940ms total 40.757ms

更新

我在一台搭载Android 6.0 MarshMallow系统的Infinix X510上运行应用程序时,出现了错误:

01-23 20:13:12.418 5592-5600/? A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 5600 (FinalizerDaemon)
01-23 20:13:12.474 5695-5695/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-23 20:13:12.474 5695-5695/? A/DEBUG: Build fingerprint: 'Infinix/Infinix_X510/Infinix_X510_sprout:6.0/MRA58K/1452855576:user/release-keys'
01-23 20:13:12.474 5695-5695/? A/DEBUG: Revision: '0'
01-23 20:13:12.475 5695-5695/? A/DEBUG: ABI: 'arm'
01-23 20:13:12.475 5695-5695/? A/DEBUG: pid: 5592, tid: 5600, name: FinalizerDaemon  >>> supernet.interactapp <<<
01-23 20:13:12.475 5695-5695/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0
01-23 20:13:12.499 5695-5695/? A/DEBUG:     r0 afa193c0  r1 afa193a0  r2 00000000  r3 00000000
01-23 20:13:12.499 5695-5695/? A/DEBUG:     r4 ae67bfe0  r5 00000001  r6 ffffffff  r7 ffffffff
01-23 20:13:12.499 5695-5695/? A/DEBUG:     r8 00000000  r9 ab5de800  sl 00000000  fp 12e69e40
01-23 20:13:12.499 5695-5695/? A/DEBUG:     ip b5c804b4  sp b3c5e528  lr b6e9add7  pc 00000000  cpsr 40070010
01-23 20:13:12.500 5695-5695/? E/AEE/LIBAEE: aee_try_get_word: read:5600 addr:0x00000000 ret:-1, 5
01-23 20:13:12.503 5695-5695/? A/DEBUG:     #00 pc 00000000  <unknown>
01-23 20:13:12.503 5695-5695/? A/DEBUG:     #01 pc 0008fdd5  /system/lib/libandroid_runtime.so (android::Bitmap::~Bitmap()+20)
01-23 20:13:12.503 5695-5695/? A/DEBUG:     #02 pc 0008fdff  /system/lib/libandroid_runtime.so (android::Bitmap::detachFromJava()+30)
01-23 20:13:12.503 5695-5695/? A/DEBUG:     #03 pc 72a75785  /data/dalvik-cache/arm/system@framework@boot.oat (offset 0x23a4000)
01-23 20:13:12.808 5695-5695/? E/DEBUG: waitpid failed: tid 5592, No child processes

AND

一个堆栈跟踪:

01-23 20:13:21.458 5699-5699/? D/skia: jpeg_decoder mode 0, colorType 4, w 676, h 931, sample 1, bsLength 99cf!!
01-23 20:13:21.459 5699-5699/? D/skia: jpeg_decoder mode 0, colorType 4, w 676, h 931, sample 1, bsLength 99cf!!
01-23 20:13:21.459 5699-5699/? D/skia: jpeg_decoder mode 1, colorType 4, w 676, h 931, sample 8, bsLength 99cf!!
01-23 20:13:21.543 5699-5699/? D/skia: jpeg_decoder mode 0, colorType 4, w 1914, h 1076, sample 1, bsLength 28d55!!
01-23 20:13:21.544 5699-5699/? D/skia: jpeg_decoder mode 0, colorType 4, w 1914, h 1076, sample 1, bsLength 28d55!!
01-23 20:13:21.544 5699-5699/? D/skia: jpeg_decoder mode 1, colorType 4, w 1914, h 1076, sample 32, bsLength 28d55!!
01-23 20:13:21.605 5699-5699/? D/skia: jpeg_decoder mode 0, colorType 4, w 571, h 559, sample 1, bsLength a716!!
01-23 20:13:21.605 5699-5699/? D/skia: jpeg_decoder mode 0, colorType 4, w 571, h 559, sample 1, bsLength a716!!
01-23 20:13:21.605 5699-5699/? D/skia: jpeg_decoder mode 1, colorType 4, w 571, h 559, sample 8, bsLength a716!!

01-23 20:13:29.093 5699-5708/? E/AndroidRuntime: FATAL EXCEPTION: FinalizerWatchdogDaemon
                                                 Process: supernet.interactapp, PID: 5699
                                                 java.util.concurrent.TimeoutException: android.graphics.Bitmap$BitmapFinalizer.finalize() timed out after 10 seconds
                                                     at android.graphics.Bitmap.nativeDestructor(Native Method)
                                                     at android.graphics.Bitmap.-wrap1(Bitmap.java)
                                                     at android.graphics.Bitmap$BitmapFinalizer.finalize(Bitmap.java:1667)
                                                     at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:212)
                                                     at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:191)
                                                     at java.lang.Thread.run(Thread.java:818)

你的问题似乎出在FinalizerDaemon上...可能不大有帮助,但你是否有一些长时间运行的finalize()方法? - Codebender
那应该在哪里运行呢?我在一个AsyncTask中从文件系统加载联系人的JSON和他们的图片。 - gbenroscience
是的@g2o。但我收到了来自运行Lollipop及更高版本的真实设备Samsung、InJoo等的崩溃投诉。 - gbenroscience
1
你能发布一下如何使用Picasso吗?另外,你是如何创建图像文件的?也许你创建的文件在某种程度上都损坏了? - eriuzo
我这样使用Picasso: Bitmap map = Picasso.with(context).load("file:"+file.getAbsolutePath()).resize(50,50).get(); - gbenroscience
显示剩余12条评论
1个回答

1
当加载位图时,您是否会检查设备的内存?我知道您正在计算inSampleSize,但是我因为将错误的值传递给reqWidth和reqHeight参数而遇到了相同的问题,当然,inSampleSize太大并且会导致设备内存崩溃。这个问题出现在一个照片库中。
我希望这可以帮助您!

谢谢您的评论! 嗯,我实际上这么做了。尺寸大约为50 x 50。相同的代码用于在应用程序的另一页上加载来自服务器的图像,而且工作得非常好。 - gbenroscience
请检查我的编辑。我在运行Android 6.0的Infinix设备上尝试了它,但它再次在本地代码中崩溃,并在发生的位置给了我android的Bitmap代码的堆栈跟踪。似乎是在BitmapFinalizer类的finalize方法中调用的nativeDestructor方法中发生了这种情况。 - gbenroscience

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接