card.io-Android-source
card.io-Android-source copied to clipboard
java.lang.NullPointerException: Attempt to read from field 'int android.graphics.Rect.top' on a null object reference
I recently received this crash report from a Nexus 5X running the card.io 5.3.0 android SDK.
the crash occurs because mGuideFrame is null when dereferencing the top property below.
I haven't dug in further to determine why mCardScanner.getGuideFrame is returning null.
mGuideFrame = mCardScanner.getGuideFrame(sv.getWidth(), sv.getHeight());
// adjust for surface view y offset
mGuideFrame.top += sv.getTop();
mGuideFrame.bottom += sv.getTop();
mOverlay.setGuideAndRotation(mGuideFrame, degrees);
mLastDegrees = degrees;
a few lines of logcat prior to this:
03-01 21:52:08.862 D/CardIOActivity(14075): permission denied to camera - requesting it
03-01 21:52:08.873 I/CardIOActivity(14075): onResume()
03-01 21:52:08.944 I/CardIOActivity(14075): onPause()
03-01 21:52:09.028 D/OpenGLRenderer(14075): endAllStagingAnimators on 0xde473580 (ListPopupWindow$DropDownListView) with handle 0xe02b5160
03-01 21:52:10.563 I/card.io (14075): card.io 5.3.0 01/11/2016 16:07:03 -0600
03-01 21:52:10.573 D/card.io (14075): Loaded card.io decider library.
03-01 21:52:10.583 D/card.io (14075): nUseNeon(): true
03-01 21:52:10.584 D/card.io (14075): nUseTegra():false
03-01 21:52:10.584 D/card.io (14075): nUseX86(): false
03-01 21:52:10.598 D/card.io (14075): Loaded opencv core library
03-01 21:52:10.623 D/card.io (14075): Loaded opencv imgproc library
03-01 21:52:10.635 E/card.io (14075): Failed to load native library: JNI_ERR returned from JNI_OnLoad in "/data/app/com.hanhuy.android.keepshare-2/lib/arm/libcardioRecognizer.so"
03-01 21:52:10.636 V/CardScanner(14075): prepareScanner()
03-01 21:52:10.807 V/CardScanner(14075): camera is connected
03-01 21:52:10.814 D/CardScanner(14075): - parameters: android.hardware.Camera$Parameters@84c784d
03-01 21:52:10.841 I/CardIOActivity(14075): onResume()
03-01 21:52:10.841 D/MEMORY (14075): Native memory stats: (free/alloc'd/total)2824680/18277912/21102592
03-01 21:52:10.847 D/CardIOActivity(14075): restartPreview()
03-01 21:52:10.847 V/CardScanner(14075): resumeScanning(android.view.SurfaceView$4@651c013)
03-01 21:52:10.847 V/CardScanner(14075): - mCamera:android.hardware.Camera@b06c250
03-01 21:52:10.847 V/CardScanner(14075): - preview format: 17
03-01 21:52:10.848 V/CardScanner(14075): - bytes per pixel: 1
03-01 21:52:10.848 V/CardScanner(14075): - buffer size: 921600
03-01 21:52:10.848 D/CardScanner(14075): setFlashOn: false
03-01 21:52:10.850 D/CardScanner(14075): setFlashOn: false
03-01 21:52:10.851 D/Torch (14075): Torch OFF
03-01 21:52:10.851 I/CardIOActivity(14075): onResume()
03-01 21:52:10.851 D/MEMORY (14075): Native memory stats: (free/alloc'd/total)2824104/18278488/21102592
03-01 21:52:10.852 D/CardIOActivity(14075): restartPreview()
03-01 21:52:10.852 V/CardScanner(14075): resumeScanning(android.view.SurfaceView$4@651c013)
03-01 21:52:10.852 D/CardScanner(14075): setFlashOn: false
03-01 21:52:10.853 D/CardScanner(14075): setFlashOn: false
03-01 21:52:10.854 D/Torch (14075): Torch OFF
03-01 21:52:10.855 D/Preview (14075): Preview.onMeasure(w:1073742904, h:1073743592) setMeasuredDimension(w:1080, h:1768)
03-01 21:52:10.861 D/Preview (14075): Preview.onMeasure(w:1073742904, h:1073743592) setMeasuredDimension(w:1080, h:1768)
03-01 21:52:10.869 D/Preview (14075): Preview.onMeasure(w:1073742904, h:1073743649) setMeasuredDimension(w:1080, h:1825)
03-01 21:52:10.870 D/Preview (14075): Preview.onLayout()
03-01 21:52:10.879 D/CardScanner(14075): Preview.surfaceCreated()
03-01 21:52:10.880 D/CardScanner(14075): surfaceFrame: Rect(0, 0 - 1080, 1440)
03-01 21:52:10.939 D/CardScanner(14075): startPreview success
03-01 21:52:10.939 D/CardScanner(14075): Preview.surfaceCreated(), surface is valid
03-01 21:52:10.939 D/CardScanner(14075): Preview.surfaceChanged(holder?:true, f:4, w:1080, h:1440 )
03-01 21:52:11.112 D/Preview (14075): Preview.onMeasure(w:1073742904, h:1073743649) setMeasuredDimension(w:1080, h:1825)
03-01 21:52:11.113 D/Preview (14075): Preview.onLayout()
03-01 21:52:11.199 D/CardScanner(14075): mFirstPreviewFrame
03-01 21:52:11.200 D/CardIOActivity(14075): onFirstFrame(1)
03-01 21:52:11.222 D/AndroidRuntime(14075): Shutting down VM
Looks like libcardioRecognizer.so failed to load, which causes the null Rect. lib of my APK
[pfnguyen@galactica keepshare] $ jar tf target/android/output/keepshare-release .apk | grep -w lib
lib/armeabi/libaeskeytrans.so
lib/armeabi/libcardioDecider.so
lib/armeabi-v7a/libaeskeytrans.so
lib/armeabi-v7a/libcardioDecider.so
lib/armeabi-v7a/libcardioRecognizer.so
lib/armeabi-v7a/libcardioRecognizer_tegra2.so
lib/armeabi-v7a/libopencv_core.so
lib/armeabi-v7a/libopencv_imgproc.so
lib/mips/libaeskeytrans.so
lib/mips/libcardioDecider.so
lib/x86/libaeskeytrans.so
lib/x86/libcardioDecider.so
lib/x86/libcardioRecognizer.so
lib/x86/libcardioRecognizer_tegra2.so
lib/x86/libopencv_core.so
lib/x86/libopencv_imgproc.so
5.3.0 aar (perhaps others?) is incorrectly packaged
[pfnguyen@galactica io.card-android-sdk-5.3.0] $ jar tf ~/.ivy2/cache/io.card/a ndroid-sdk/aars/android-sdk-5.3.0.aar | grep -w jni
jni/
jni/arm64-v8a/
jni/arm64-v8a/libcardioDecider.so
jni/arm64-v8a/libcardioRecognizer.so
jni/arm64-v8a/libcardioRecognizer_tegra2.so
jni/arm64-v8a/libopencv_core.so
jni/arm64-v8a/libopencv_imgproc.so
jni/armeabi/
jni/armeabi/libcardioDecider.so
jni/armeabi-v7a/
jni/armeabi-v7a/libcardioDecider.so
jni/armeabi-v7a/libcardioRecognizer.so
jni/armeabi-v7a/libcardioRecognizer_tegra2.so
jni/armeabi-v7a/libopencv_core.so
jni/armeabi-v7a/libopencv_imgproc.so
jni/mips/
jni/mips/libcardioDecider.so
jni/x86/
jni/x86/libcardioDecider.so
jni/x86/libcardioRecognizer.so
jni/x86/libcardioRecognizer_tegra2.so
jni/x86/libopencv_core.so
jni/x86/libopencv_imgproc.so
jni/x86_64/
jni/x86_64/libcardioDecider.so
jni/x86_64/libcardioRecognizer.so
jni/x86_64/libcardioRecognizer_tegra2.so
jni/x86_64/libopencv_core.so
jni/x86_64/libopencv_imgproc.so
(notice mips and armeabi containing incomplete library distributions)
Logs of questions/comments here:
- We don't support
armeabiormips, which is why you see the missing.sofiles. ThelibcardioDecider.sodetects this, and decides not to show the camera. - If the processor is not supported, that line should never be run
- Are you able to reproduce the crash?
- Looks like this may be related to Android 6.0. Can you confirm the OS of the device?
This happens on a Nexus 5X on 6.0.1 as seen at this crash report link http://hanhuy-acra.appspot.com/public/com.hanhuy.android.keepshare/73400337bb30eb791d018a400defdc66ef82b3a9
I don't have a 5X, personally, and do not encounter this crash on a 6P on a 6.0.1
Oh, and my workaround is to set ndk.abiFilter to x86 and armeabi-v7a
Thanks. Looking at the logs, I see the camera permissions requested, yet the jni failed to load. When using card.io, did you first check CardIOActivity.canReadCardWithCamera()? That method would load in the jni files before card.io ever opens.
That is a good point, I didn't see that in the README, and didn't think to check for an api to detect whether it is supported.