trevorpowell / mapbox-gl-js-cordova-offline-example

Example Cordova project using https://github.com/trevorpowell/mapbox-gl-js-cordova-offline
18 stars 7 forks source link

App crashes on startup #1

Closed flamed0011 closed 9 years ago

flamed0011 commented 9 years ago

Hi, just wanted to try your great example app. The app crashes with the logcat output as pasted below. The error "JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0x8b" seems to be thrown when execting the query "SELECT tile_data FROM tiles WHERE zoom_level = ? AND tile_column = ? AND tile_row = ?".

I/chromium(17723): [INFO:CONSOLE(174)] "OPEN database: naturalearth.mbtiles", source: file:///android_asset/www/plugins/io.litehelpers.cordova.sqlite/www/SQLitePlugin.js (174)
V/SQLitePlugin(17723): Android db implementation: sqlite4java (NDK)
I/chromium(17723): [INFO:CONSOLE(105)] "new transaction is waiting for open operation", source: file:///android_asset/www/plugins/io.litehelpers.cordova.sqlite/www/SQLitePlugin.js (105)
V/info    (17723): Open sqlite db: /data/data/com.example.offlinemap/databases/naturalearth.mbtiles
V/sqlg    (17723): db_open /data/data/com.example.offlinemap/databases/naturalearth.mbtiles 6
V/sqlg    (17723): db_open /data/data/com.example.offlinemap/databases/naturalearth.mbtiles result 0 ptr 0xb8db4758
I/chromium(17723): [INFO:CONSOLE(105)] "new transaction is waiting for open operation", source: file:///android_asset/www/plugins/io.litehelpers.cordova.sqlite/www/SQLitePlugin.js (105)
I/chromium(17723): [INFO:CONSOLE(105)] "new transaction is waiting for open operation", source: file:///android_asset/www/plugins/io.litehelpers.cordova.sqlite/www/SQLitePlugin.js (105)
I/chromium(17723): [INFO:CONSOLE(105)] "new transaction is waiting for open operation", source: file:///android_asset/www/plugins/io.litehelpers.cordova.sqlite/www/SQLitePlugin.js (105)
I/chromium(17723): [INFO:CONSOLE(79)] "DB opened: naturalearth.mbtiles", source: file:///android_asset/www/plugins/io.litehelpers.cordova.sqlite/www/SQLitePlugin.js (79)
D/audio_hw_primary(  243): out_standby: enter: stream (0xb79dc938) usecase(1: low-latency-playback)
V/sqlg    (17723): prepare db 0xb8db4758 sql BEGIN
V/sqlg    (17723): sqlc_st_finish 0xb8dcf8e8
V/sqlg    (17723): prepare db 0xb8db4758 sql SELECT tile_data FROM tiles WHERE zoom_level = ? AND tile_column = ? AND tile_row = ?
V/sqlg    (17723): sqlc_st_bind_text_native 0xb8dec830 1 2
V/sqlg    (17723): sqlc_st_bind_text_native 0xb8dec830 2 1
V/sqlg    (17723): sqlc_st_bind_long 0xb8dec830 3 2
V/sqlg    (17723): sqlc_st_column_count 0xb8dec830
V/sqlg    (17723): sqlc_st_column_name 0xb8dec830 0
V/sqlg    (17723): sqlc_st_column_type 0xb8dec830 0
V/sqlg    (17723): sqlc_st_column_text_native 0xb8dec830 0
D/hardware_info(  243): hw_info_append_hw_type : device_name = speaker-lite
F/art     (17723): art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0x8b
F/art     (17723): art/runtime/check_jni.cc:65]     string: ''
F/art     (17723): art/runtime/check_jni.cc:65]     in call to NewStringUTF
F/art     (17723): art/runtime/check_jni.cc:65]     from java.lang.String io.liteglue.SQLiteNative.sqlc_st_column_text_native(long, int)```
trevorpowell commented 9 years ago

Are you trying to run on an Android emulator or device? Unfortunately I don't have an Android device to test with and none of the emulators I've tried support WebGL inside the Cordova Webview. I have managed to do some testing when I've had access to devices and thought this should work on Android 5, but unfortunately I don't have regular access to a device for testing.

These links might help:

Android-specific options for SQLite Plugin: https://github.com/litehelpers/Cordova-sqlite-storage#android-sqlite-implementation

Where sqlitePlugin.openDatabase is called: https://github.com/trevorpowell/mapbox-gl-js-cordova-offline/blob/cordova-offline/js/source/vector_tile_source.js#L88

One solution to get it running on an Android emulator is to use the Cordova Crosswalk plugin. Then you can add a Crosswalk flag to force WebGL to be enabled in the app on the emulator: https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview https://github.com/litehelpers/Cordova-sqlite-storage/issues/247

flamed0011 commented 9 years ago

I'm testing on a device running Android 5.1.1 (Cyanogenmod 12.1). The links you provided helped to find the solution. Thanks alot.

I modified mapgbox-gl.js directly in the minified version (searched for window.sqlitePlugin.openDatabase and added the "androidDatabaseImplementation: 2" parameter. This is described in the first of your links:

window.sqlitePlugin.openDatabase({
    name:t.source+".mbtiles",
    location:2,
    createFromLocation:1,
    androidDatabaseImplementation: 2
})

Before I tried several other things. Just for documentation:

cordova-plugin-crosswalk-webview,cordova-plugin-splashscreen,cordova-plugin-whitelist,io.litehelpers.cordova.sqlite

The app works nicely. I'm hoping to have some time to play with tilemaker.