Thanks Handoko. Following the instructions in aforementioned Android Tutorial, plus some guesswork, I was able to compile the example project androidlcltest for Android 4.2.2 (Jelly Bean, API 17). The generated androidlcltest.apk runs OK in a virtual device running the same Android 4.2.2 on ARMV7 CPU. However it crashes as soon as it launches in other devices I tried:
a. a virtual device running Android 5.0.1 (API-21), same ARMV7 CPU,
b. a generic phone running Android Go (API-26), ARM Cortex-A7,
c. a Kobo Arc 7 tablet running Android 4.2.2 (API-17), MediaTek ARM.
SDK version is 22.2.1. NDK version is 1.8b. I tried both JDK1.6 & JDK1.8 and the result was the same. I removed all components and event handlers in mainform and it didn't crash. I added a single label on the blank form and it crashed as before.
I notice that in the midst of running build_debug_apk.bat, I got the following warning:
d:\androidlcl\android>call java -classpath d:\AndSDKtools\tools\lib\sdklib.jar c
om.android.sdklib.build.ApkBuilderMain D:\androidlcl\android\bin\androidlcltest-
unsigned.apk -v -u -z D:\androidlcl\android\bin\androidlcltest.ap_ -f D:\android
lcl\android\bin\classes.dex
THIS TOOL IS DEPRECATED. See --help for more information.
Packaging androidlcltest-unsigned.apk
D:\androidlcl\android\bin\androidlcltest.ap_:
...
Did that cause the crash?
I used adb logcat -d to capture the log of the crash and the important part is as follows:
Virtual Device 5.0.1 (API-21)
--------- beginning of crash
F/libc ( 1363): Fatal signal 6 (SIGABRT), code -6 in tid 1363 (.pascal.lcltest)
I/DEBUG ( 60): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG ( 60): Build fingerprint: 'generic/sdk_phone_armv7/generic:5.0.2/LSY66K/3079185:eng/test-keys'
I/DEBUG ( 60): Revision: '0'
I/DEBUG ( 60): ABI: 'arm'
I/DEBUG ( 60): pid: 1363, tid: 1363, name: .pascal.lcltest >>> com.pascal.lcltest <<<
I/DEBUG ( 60): signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
I/DEBUG ( 60): Abort message: 'art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: native code passing in reference to invalid stack indirect reference table or invalid reference: 0xbe82a0a0'
I/DEBUG ( 60): r0 00000000 r1 00000553 r2 00000006 r3 00000000
I/DEBUG ( 60): r4 b6fa4114 r5 00000006 r6 00000002 r7 0000010c
I/DEBUG ( 60): r8 00000000 r9 b504f520 sl b5007800 fp 00000e91
I/DEBUG ( 60): ip 00000553 sp be828448 lr b6f2e175 pc b6f51174 cpsr 60000010
I/DEBUG ( 60):
I/DEBUG ( 60): backtrace:
I/DEBUG ( 60): #00 pc 00039174 /system/lib/libc.so (tgkill+12)
I/DEBUG ( 60): #01 pc 00016171 /system/lib/libc.so (pthread_kill+52)
I/DEBUG ( 60): #02 pc 00016d8f /system/lib/libc.so (raise+10)
I/DEBUG ( 60): #03 pc 00013615 /system/lib/libc.so (__libc_android_abort+36)
I/DEBUG ( 60): #04 pc 00012a10 /system/lib/libc.so (abort+4)
I/DEBUG ( 60): #05 pc 00213699 /system/lib/libart.so (art::Runtime::Abort()+160)
I/DEBUG ( 60): #06 pc 000a7a2f /system/lib/libart.so (art::LogMessage::~LogMessage()+1066)
I/DEBUG ( 60): #07 pc 000b0ed5 /system/lib/libart.so (art::JniAbort(char const*, char const*)+1080)
I/DEBUG ( 60): #08 pc 000b1455 /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+60)
I/DEBUG ( 60): #09 pc 000b35c9 /system/lib/libart.so (_ZN3art11ScopedCheck5CheckEbPKcz.constprop.128+672)
I/DEBUG ( 60): #10 pc 000b677b /system/lib/libart.so (art::CheckJNI::SetObjectField(_JNIEnv*, _jobject*, _jfieldID*, _jobject*)+50)
I/DEBUG ( 60): #11 pc 0009c178 /data/app/com.pascal.lcltest-1/lib/arm/liblclapp.so
W/InputConnectionWrapper.ICC( 493): Timed out waiting on IInputContextCallback
E/NativeCrashListener( 350): Exception dealing with report
E/NativeCrashListener( 350): android.system.ErrnoException: read failed: EAGAIN (Try again)
E/NativeCrashListener( 350): at libcore.io.Posix.readBytes(Native Method)
E/NativeCrashListener( 350): at libcore.io.Posix.read(Posix.java:147)
E/NativeCrashListener( 350): at libcore.io.BlockGuardOs.read(BlockGuardOs.java:230)
E/NativeCrashListener( 350): at android.system.Os.read(Os.java:364)
E/NativeCrashListener( 350): at com.android.server.am.NativeCrashListener.consumeNativeCrashData(NativeCrashListener.java:240)
E/NativeCrashListener( 350): at com.android.server.am.NativeCrashListener.run(NativeCrashListener.java:138)
W/InputConnectionWrapper.ICC( 493): Timed out waiting on IInputContextCallback
I/DEBUG ( 60):
I/DEBUG ( 60): Tombstone written to: /data/tombstones/tombstone_04
I/BootReceiver( 350): Copying /data/tombstones/tombstone_04 to DropBox (SYSTEM_TOMBSTONE)
E/SharedPreferencesImpl( 350): Couldn't create directory for SharedPreferences file shared_prefs/log_files.xml
I/WindowState( 350): WIN DEATH: Window{13339769 u0 com.pascal.lcltest/com.pascal.lcltest.LCLActivity}
W/InputDispatcher( 350): channel '13339769 com.pascal.lcltest/com.pascal.lcltest.LCLActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
E/InputDispatcher( 350): channel '13339769 com.pascal.lcltest/com.pascal.lcltest.LCLActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
I/Zygote ( 66): Process 1363 exited due to signal (6)
I/ActivityManager( 350): Process com.pascal.lcltest (pid 1363) has died
W/InputDispatcher( 350): Attempted to unregister already unregistered input channel '13339769 com.pascal.lcltest/com.pascal.lcltest.LCLActivity (server)'
W/ActivityManager( 350): Force removing ActivityRecord{372753d8 u0 com.pascal.lcltest/.LCLActivity t4}: app died, no saved state
W/WindowManager( 350): Failed looking up window
W/WindowManager( 350): java.lang.IllegalArgumentException: Requested window android.view.ViewRootImpl$W@37dd0f97 does not exist
W/WindowManager( 350): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8413)
W/WindowManager( 350): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8404)
W/WindowManager( 350): at com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java:2558)
W/WindowManager( 350): at com.android.server.wm.Session.remove(Session.java:186)
W/WindowManager( 350): at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:2920)
W/WindowManager( 350): at android.view.ViewRootImpl.doDie(ViewRootImpl.java:5390)
On the Android Go phone, I got this message instead:
02-24 09:43:30.193 11126 11126 F DEBUG : Abort message: 'java_vm_ext.cc:534] JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0xbec4c5e0'
What went wrong?