Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when adding sqlite plugin to Crosswalk Cordova HelloWorld example [x86_64] #247

Closed
trevorpowell opened this issue Apr 24, 2015 · 25 comments

Comments

@trevorpowell
Copy link

I am following the steps to create the Crosswalk Cordova HelloWorld project and adding the sqlite plugin with plugman as documented here:
https://crosswalk-project.org/documentation/cordova/develop_an_application.html

Using the latest versions for everything and all the prerequisites.

The HelloWorld project runs okay in the emulator, but as soon as I install the sqlite plugin with plugman and try running the app again, I get an error "Unfortunately, HelloWorld has stopped." Just installed the plugin. Didn't try to open a database or anything. My emulator is running Android 5.0.1 (API 21) on x86_64. It has 3GB RAM, 512MB for VM Heap, and is using Intel HAXM. Do I need to use ARM instead of x86_64 for the plugin? Any idea what the issue might be?

The log from "adb logcat" when opening the app is below:

I/ActivityManager( 6504): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=org.crosswalkproject.sample/.HelloWorld (has extras)} from uid 10007 on display 0
I/art     ( 7192): Not late-enabling -Xcheck:jni (already on)
I/CordovaLog( 7192): Changing log level to DEBUG(3)
W/System.err( 7192): java.lang.RuntimeException: Use SharedXWalkView if you want to support shared mode
W/System.err( 7192):    at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:237)
W/System.err( 7192):    at org.xwalk.core.ReflectionHelper.init(ReflectionHelper.java:132)
W/System.err( 7192):    at org.xwalk.core.ReflectionHelper.loadClass(ReflectionHelper.java:199)
W/System.err( 7192):    at org.xwalk.core.XWalkPreferences.setValue(XWalkPreferences.java:112)
W/System.err( 7192):    at org.apache.cordova.CordovaWebView.<clinit>(CordovaWebView.java:897)
W/System.err( 7192):    at org.apache.cordova.CordovaActivity.makeWebView(CordovaActivity.java:340)
W/System.err( 7192):    at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:376)
W/System.err( 7192):    at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:368)
W/System.err( 7192):    at org.crosswalkproject.sample.HelloWorld.onCreate(HelloWorld.java:31)
W/System.err( 7192):    at android.app.Activity.performCreate(Activity.java:5937)
W/System.err( 7192):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
W/System.err( 7192):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
W/System.err( 7192):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
W/System.err( 7192):    at android.app.ActivityThread.access$800(ActivityThread.java:144)
W/System.err( 7192):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
W/System.err( 7192):    at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err( 7192):    at android.os.Looper.loop(Looper.java:135)
W/System.err( 7192):    at android.app.ActivityThread.main(ActivityThread.java:5221)
W/System.err( 7192):    at java.lang.reflect.Method.invoke(Native Method)
W/System.err( 7192):    at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err( 7192):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
W/System.err( 7192):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
D/AndroidRuntime( 7192): Shutting down VM
E/AndroidRuntime( 7192): FATAL EXCEPTION: main
E/AndroidRuntime( 7192): Process: org.crosswalkproject.sample, PID: 7192
E/AndroidRuntime( 7192): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 7192):    at org.apache.cordova.CordovaActivity.makeWebView(CordovaActivity.java:340)
E/AndroidRuntime( 7192):    at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:376)
E/AndroidRuntime( 7192):    at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:368)
E/AndroidRuntime( 7192):    at org.crosswalkproject.sample.HelloWorld.onCreate(HelloWorld.java:31)
E/AndroidRuntime( 7192):    at android.app.Activity.performCreate(Activity.java:5937)
E/AndroidRuntime( 7192):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime( 7192):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
E/AndroidRuntime( 7192):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
E/AndroidRuntime( 7192):    at android.app.ActivityThread.access$800(ActivityThread.java:144)
E/AndroidRuntime( 7192):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
E/AndroidRuntime( 7192):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 7192):    at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 7192):    at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime( 7192):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 7192):    at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 7192):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime( 7192):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
E/AndroidRuntime( 7192): Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Use SharedXWalkView if you want to support shared mode
E/AndroidRuntime( 7192):    at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:233)
E/AndroidRuntime( 7192):    at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:237)
E/AndroidRuntime( 7192):    at org.xwalk.core.ReflectionHelper.init(ReflectionHelper.java:132)
E/AndroidRuntime( 7192):    at org.xwalk.core.ReflectionHelper.loadClass(ReflectionHelper.java:199)
E/AndroidRuntime( 7192):    at org.xwalk.core.XWalkPreferences.setValue(XWalkPreferences.java:112)
E/AndroidRuntime( 7192):    at org.apache.cordova.CordovaWebView.<clinit>(CordovaWebView.java:897)
E/AndroidRuntime( 7192):    ... 17 more
E/AndroidRuntime( 7192): Caused by: java.lang.RuntimeException: Use SharedXWalkView if you want to support shared mode
E/AndroidRuntime( 7192):    ... 22 more
D/        ( 6504): HostConnection::get() New Host Connection established 0x7ff45580ec20, tid 6518
E/EGL_emulation(  947): tid 947: eglCreateSyncKHR(1237): error 0x3004 (EGL_BAD_ATTRIBUTE)
D/Atlas   ( 6504): Validating map...
D/        ( 6504): HostConnection::get() New Host Connection established 0x7ff455bbec60, tid 7208
I/OpenGLRenderer( 6504): Initialized EGL, version 1.4
D/OpenGLRenderer( 6504): Enabling debug mode 0
W/ActivityManager( 6504): Activity pause timeout for ActivityRecord{f6a6cf5 u0 org.crosswalkproject.sample/.HelloWorld t16 f}
W/EGL_emulation( 6755): eglSurfaceAttrib not implemented
W/OpenGLRenderer( 6755): Failed to set EGL_SWAP_BEHAVIOR on surface 0x7ff467e37a40, error=EGL_SUCCESS
W/OpenGLRenderer( 6755): Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
W/ActivityManager( 6504): Activity destroy timeout for ActivityRecord{f6a6cf5 u0 org.crosswalkproject.sample/.HelloWorld t16 f}
@brodycj brodycj changed the title Error when adding sqlite plugin to Crosswalk Cordova HelloWorld example Error when adding sqlite plugin to Crosswalk Cordova HelloWorld example [x86_64] Apr 24, 2015
@brodycj
Copy link

brodycj commented Apr 24, 2015

By default, the Android version uses the sqlite4java library which contains a NDK part. A version was built for x86_64, but it has not been tested yet. The workaround for x86_64 is to specify the androidDatabaseImplementation in sqlitePlugin.openDatabase() as specified in README.md. I am busy testing the x86_64 version and will keep you posted.

@brodycj
Copy link

brodycj commented Apr 24, 2015

This project is now tested working OK with x86_64, but for some reason does not seem to work with Crosswalk when using sqlite4java (ref: #235). As I said before, the workaround is to specify the androidDatabaseImplementation option in sqlitePlugin.openDatabase() as described in README.md. I am preparing for a one-week vacation and can work on this when I return.

@trevorpowell
Copy link
Author

Thanks for investigating. For me it seems, the issue is occurring before I call openDatabase or any of the sqlitePlugin methods. The plugin javascript is included by Cordova but that's it. All I did was install the plugin using plugman in the Crosswalk HelloWorld example.

@trevorpowell
Copy link
Author

I was testing this some more and found the sqlite plugin is working for me with Crosswalk when I use the Genymotion Android emulator but not when I use the Android SDK one. All the settings for the SDK emulator seem right and tried both x86_64 and ARM, so not sure what the deal is. I don't have an Android device, so not able to test on that. I also had to use the androidDatabaseImplementation option to get it working in Crosswalk with the Genymotion emulator but not necessarily the androidLockWorkaround option.

@trevorpowell
Copy link
Author

It also works with the Android SDK emulator when I don't use Crosswalk, but then I guess that's the standard Android use case. Also didn't require the two Android-specific initialization options in that case.

@ronycohen
Copy link

We encounter the same issue from the PouchDB layout which use the Sqlite Plugin and Ionic Crosswalk..

plugins/io.litehelpers.cordova.sqlite/www/SQLitePlugin.js:171 OPEN database: _pouch_Db
plugins/io.litehelpers.cordova.sqlite/www/SQLitePlugin.js:102 new transaction is waiting for open operation
plugins/io.litehelpers.cordova.sqlite/www/SQLitePlugin.js:192 OPEN database: _pouch_Db failed, aborting any pending transactions
plugins/io.litehelpers.cordova.sqlite/www/SQLitePlugin.js:79 Could not open database

@brodycj
Copy link

brodycj commented May 1, 2015

On May 1, 2015 1:03 PM, "ronyrun" [email protected] wrote:

We encounter the same issue from the PouchDB layout which use the Sqlite
Plugin and Ionic Crosswalk..

Yes-this is now a known problem-you have to follow the workaround that I
described in some earlier comments. I will investigate this issue sometime
in the next 1-2 weeks.

@ronycohen
Copy link

OK thank you brodybits

@nolanlawson
Copy link
Contributor

@brodybits The PouchDB test suite can be run against this plugin pretty easily. I had to update it, though, on account of the name change and a few bugs in our test structure: pouchdb/pouchdb#3779

In any case, I can confirm that I can run the tests in both iOS and Android against this plugin, although I didn't run them to completion to see if they are at 100%. Most likely they are not at 100% and that will isolate the bug. :)

Anybody have the time/patience to test these? It's literally as easy as:

git clone https://github.com/pouchdb/pouchdb.git
cd pouchdb
npm install
# start up an Android emulator
SQLITE_PLUGIN=true ADAPTERS=websql npm run cordova

Then it will run the test in your emulator like so:

out

@nolanlawson
Copy link
Contributor

Hm, it gets to 49% and then just stops (Android 4.4 emulator + SQLite plugin). In logcat I see a lot of:

GC_FOR_ALLOC freed 1230K, 18% free 6185K/7492K, paused 2ms, total 2ms

But that's only while it's working.

Once it stops working, the last failed test is Test _conflicts key in the replication tests. Also I see in the logs a lot of:

  1821         eglCodecCommon  E  **** ERROR unknown type 0x0 (glSizeof,72)
  1821         eglCodecCommon  E  glUtilsParamSize: unknow param 0x00000b44
  1821         eglCodecCommon  E  glUtilsParamSize: unknow param 0x00000bd0

^ This is repeated over and over again.

@nolanlawson
Copy link
Contributor

I'm guessing this is some kind of memory leak, because once I restart the tests it works fine again... for awhile.

@brodycj
Copy link

brodycj commented May 1, 2015

@brodybits The PouchDB test suite can be run against this plugin pretty
easily.

👍

I had to update it, though, on account of the name change and a few

Stupid name changes :-|

In any case, I can confirm that I can run the tests in both iOS and Android
against this plugin, although I didn't run them to completion to see if they

Are you using the "normal" Android installation or did you dare to try it with Crosswalk?

Also I see in the logs a lot of:

1821 eglCodecCommon E **** ERROR unknown type 0x0 (glSizeof,72)
1821 eglCodecCommon E glUtilsParamSize: unknow param 0x00000b44
1821 eglCodecCommon E glUtilsParamSize: unknow param 0x00000bd0

^ This is repeated over and over again.

Do you think this is (co)rel(l)ated to the plugin? Do you think this is caused by the plugin?

I'm guessing this is some kind of memory leak, because once I restart the tests it works fine again... for awhile.

This definitely needs investigation! One thing: as now documented in README.md, if the result set gets too big the JSON encoding/decoding uses too much memory.

@nolanlawson
Copy link
Contributor

Are you using the "normal" Android installation or did you dare to try it with Crosswalk?

Haven't tried Crosswalk yet. For a Crosswalk-esque experience, though, you can just run a 5.0 emulator.

I agree, though, that the best would be to test Crosswalk itself, since it is slightly different from the WebView.

Do you think this is (co)rel(l)ated to the plugin? Do you think this is caused by the plugin?

The tests pass in WebSQL and IndexedDB in a variety of browsers, so the bug is definitely in this plugin, sad to say. :(

Also FWIW, the PouchDB test suite was passing last summer in both iOS (7+) and Android (4.0+), back when I submitted all those fixes. I'm kicking myself now for not adding automated Cordova tests to either PouchDB or this repo. We probably could have caught these bugs earlier.

@brodycj
Copy link

brodycj commented May 1, 2015

The tests pass in WebSQL and IndexedDB in a variety of browsers, so the bug is definitely in this plugin, sad to say. :(

Also FWIW, the PouchDB test suite was passing last summer in both iOS (7+) and Android (4.0+), back when I submitted all those fixes.

@nolanlawson I filed #255 to capture the problems with PouchDB. For this issue I would like to focus on testing this plugin with the Crosswalk version and finding the (root) cause.

@matb33
Copy link

matb33 commented May 2, 2015

I may be off here, but this may have nothing to do with this plugin, but appears to be specific to cordova 5 and/or the new crosswalk plugin (https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview) . It seems the x86 and armv7 builds are swapped. I created a brand new HelloCordova project using Cordova 5.0.0 and cordova-android 4.0.0, then installed the cordova-plugin-crosswalk-webview, specifying version 13 in config.xml. I successfully built and installed the android-armv7-debug.apk on an android device (Android TV in my case), and when I launch it, it immediately closes and gives me the exact same stack trace as the OP. Googling this didn't turn up much except "oops I was trying the x86 version" -- but I definitely installed the apk labeled with armv7. So on a hunch, I installed android-x86-debug.apk on my android device and now the HelloCordova app launches successfully.

I tried to dig up where this swap occurs, but I haven't been able to track it down. So I'll be making an exception for now and installing the one labeled with x86...

@brodycj
Copy link

brodycj commented May 2, 2015

I may be off here, but this may have nothing to do with this plugin, but
appears to be specific to cordova 5 and/or the new crosswalk plugin (
https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview) . It
seems the x86 and armv7 builds are swapped.

@matb33 that sounds entirely possible-though we should keep in mind that
the OP reported the issue with x86_64. I am still on vacation for a few
more days, will try to take a look tomorrow or perhaps even later tonight.

@matb33
Copy link

matb33 commented May 2, 2015

@trevorpowell can you try running the android-armv7-debug.apk in the emulator? This could help confirm that x86 and armv7 were somehow swapped.

@brodycj
Copy link

brodycj commented May 2, 2015

On May 2, 2015 9:01 PM, "Mathieu Bouchard" [email protected] wrote:

@trevorpowell can you try running the android-armv7-debug.apk in the
emulator? This could help confirm that x86 and armv7 were somehow swapped.

Something else: @trevorpowell already was able to get it working on x86_64
by using androidDatabaseImplementation as described in README.md.

IMHO the right way to solve the problem is to build crosswalk-cordova
from source and then issue a pull request once we verify that we have
solved the root cause.

@trevorpowell
Copy link
Author

I can test using that method and the alternate apk. I was not using Cordova 5 and the Crosswalk plugin for Cordova at the time. I was using Cordova 4.3.0 and following the methods here with Crosswalk 11x:
https://crosswalk-project.org/documentation/cordova/develop_an_application.html

The x86_64 Crosswalk HelloWorld app I built worked fine on an x86_64 Android 21/22 SDK emulator but then stopped working when I installed the sqlite plugin (just installing the plugin, not calling openDatabase or anything). The same apk worked fine in the Genymotion x86 emulator though. Maybe it's some issue with a difference between the emulators or something with Crosswalk. I can try again with the newer versions of Cordova and Crosswalk.

@trevorpowell
Copy link
Author

The issue still occurs for me on the Android SDK emulator when I follow the Crosswalk HelloWorld guide and install the sqlite plugin, but works fine if I start from Cordova and install the Crosswalk webview plugin or if I use the Genymotion emulator. I am fine with closing this issue as the second method is probably the better way to go anyways.

@brodycj
Copy link

brodycj commented May 4, 2015

The issue still occurs for me on the Android SDK emulator when I follow
the Crosswalk HelloWorld guide and install the sqlite plugin, but works
fine if I start from Cordova and install the Crosswalk webview plugin or if
I use the Genymotion emulator. I am fine with closing this issue as the
second method is probably the better way to go anyways.

At the very least this issue really has to be documented in README.md which
I will do later this week.

@ronyrun can you report if this workaround will also work for you or not?

@matb33
Copy link

matb33 commented May 6, 2015

With regards to my particular issue that I thought was related, you can dismiss... turns out the Nexus Player is actually an x86 device. I assumed it was like all others and was arm...

@ronycohen
Copy link

@ronyrun can you report if this workaround will also work for you or not?

YES IT WORKS 👍

@rubensayshi
Copy link

E/SQLitePlugin( 3157): com.almworks.sqlite4java.SQLiteException: [-91] cannot load library: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.ionicframework.btwallet668090-2/base.apk"],nativeLibraryDirectories=[/data/app/com.ionicframework.btwallet668090-2/lib/x86, /vendor/lib, /system/lib]]] couldn't find "libsqlite4java-android-i686.so"
E/SQLitePlugin( 3157):  at com.almworks.sqlite4java.SQLite.loadLibrary(SQLite.java:97)
E/SQLitePlugin( 3157):  at com.almworks.sqlite4java.SQLiteConnection.open0(SQLiteConnection.java:1441)
E/SQLitePlugin( 3157):  at com.almworks.sqlite4java.SQLiteConnection.open(SQLiteConnection.java:282)
E/SQLitePlugin( 3157):  at io.liteglue.SQLitePlugin$SQLiteDatabaseNDK.open(SQLitePlugin.java:375)
E/SQLitePlugin( 3157):  at io.liteglue.SQLitePlugin.openDatabase(SQLitePlugin.java:223)
E/SQLitePlugin( 3157):  at io.liteglue.SQLitePlugin.access$000(SQLitePlugin.java:37)
E/SQLitePlugin( 3157):  at io.liteglue.SQLitePlugin$DBRunner.run(SQLitePlugin.java:598)
E/SQLitePlugin( 3157):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/SQLitePlugin( 3157):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/SQLitePlugin( 3157):  at java.lang.Thread.run(Thread.java:818)
E/SQLitePlugin( 3157): Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.ionicframework.btwallet668090-2/base.apk"],nativeLibraryDirectories=[/data/app/com.ionicframework.btwallet668090-2/lib/x86, /vendor/lib, /system/lib]]] couldn't find "libsqlite4java-android-i686.so"
E/SQLitePlugin( 3157):  at java.lang.Runtime.loadLibrary(Runtime.java:366)
E/SQLitePlugin( 3157):  at java.lang.System.loadLibrary(System.java:989)
E/SQLitePlugin( 3157):  at com.almworks.sqlite4java.Internal.tryLoadFromSystemPath(Internal.java:352)
E/SQLitePlugin( 3157):  at com.almworks.sqlite4java.Internal.loadLibraryX(Internal.java:124)
E/SQLitePlugin( 3157):  at com.almworks.sqlite4java.SQLite.loadLibrary(SQLite.java:95)
E/SQLitePlugin( 3157):  ... 9 more

androidDatabaseImplementation:2 fixed this issue for me too, xwalk also being the thing that introduced all the problems but that might also be because without xwalk it does not build different APKs for each architecture but just one ...?

@hanthomas
Copy link

I think there are 2 separate issues being discussed on this thread.

PROBLEM 1 (as reported by @trevorpowell)
This problem occurs before sqlitePlugin.openDatabase() is called - in fact, it's when Crosswalk attempts to load, and it fails to start. I can reproduce this problem consistently with the following combination when running the x86 APK:

  • cordova-plugin-crosswalk-webview 1.2.0
  • io.litehelpers.cordova.sqlite 0.7.10

However, when I use the following combination, it works fine:

  • cordova-plugin-crosswalk-webview 1.2.0
  • io.litehelpers.cordova.sqlite 0.7.7

Notice, that the only difference is the version of sqlite plugin. In other words, there's a problem introduced with the 0.7.10 version of SQLite plugin on x86 platform that needs to be fixed. (On ARM7, either configuration works just fine.)

PROBLEM 2 (as described by @brodybits)
This problem occurs after the app has loaded successfully, and when sqlitePlugin.openDatabase() is called. So, even after Problem 1 has been resolved, you still need to work around this problem using @brodybits suggestion to include androidDatabaseImplemention :2.

Ideally, both problems should be fixed soon, since neither workarounds are good long terms solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants