Question

I have a phongap app with a sqlite plugin that runs in both android and iphone. When I try to run it in Ripple i get several errors depending on the inclusion of the cordova version and device I use. Non of them are working at all. In some comments in stackoverflow i've seen people running sqlite in phonegap under ripple.

I'm using the PG-SQLitePlugin-Android plugin in my project, which it acually only supports Phonegap 2.7.0+.

I've found that i can force Ripple to use 2.7.0 by calling it :

file://localhost/Users/----/----/----/www/index.html?enableripple=cordova-2.7.0

Ripple actually loads great after enabling access to file system through chrome.

When i include cordova-2.7.0.js in my script

The index.html pops me a pop up with the following text :

gap:["Device","getDeviceInfo","Device119187522"]

that i can accept or cancel, then 2 more dialogs appeare, if I accept it gets hanged.

the js console shows that cordova 2.7.0 is really running :

Falling back on PROMPT mode since _cordovaNative is missing. Expected for Android 3.2 and lower only. cordova-2.7.0.js:906

deviceready is not fired

When i include cordova-2.9.0.js in my script

It happens the same as 2.7

Falling back on PROMPT mode since _cordovaNative is missing. Expected for Android 3.2 and lower only. cordova-2.7.0.js:906

but this time I get this other errors

Failed to load resource file://localhost/Users/laullobetpayas/-------/---/------/www/cordova/cordova_plugins.json Failed to load resource file://localhost/Users/-------/---/------/www/cordova/cordova_plugins.js

deviceready is not fired

When I don't include any cordova.js in my script

SQLitePlugin.js:31 Uncaught ReferenceError: cordova is not defined SQLitePlugin.js:34

  • Am I using the proper plugin ?
  • which is the propper version of cordova / device tu run with the plugin and ripple ?
  • Do i have to include the cordova.js in my project

Hel will be very apreciated, it's for a long time that I'm trying to solve this. Thank you in advanced.

Was it helpful?

Solution

Phonegap plugins won't work with Ripple because the idea of a Phonegap plugin is that it provides a Javascript interface in order to execute native code. That means, in the case of Android, the Javascript will invoke native Java code and in the case of iOS, the Javascript will invoke native Objective-C.

Ripple is purely Javascript-based, so the Javascript part of the plugin has nothing to interface with.

In the case of the SQLitePlugin, for example, calling SQLitePlugin.close() results in the call:

cordova.exec(null, null, "SQLitePlugin", "close", [this.dbname]);

where SQLitePlugin is the native class name and close is the native function name.

If you want to use the same storage API across Android, iOS and Ripple, maybe consider using lawnchair with appropriate adapters.

As for the issues with Ripple and Phonegap 2.7.0/2.9.0, Ripple has not quite caught up with Phonegap, so you will get these popups and error messages in the console, but that will not stop your Phonegap app (without native plugins) running in Ripple. You can convince yourself of this with a simple test case like:

document.addEventListener("deviceready", function(){
  alert("I'm alive");
});

But the answer is, yes, you do need to include cordova.js in order for it to work at all in Ripple.

OTHER TIPS

The Cordova-SQLitePlugin is a drop-in replacement for the HTML5 SQL API, so when running inside Ripple you don't need to call the Cordova layer you can just replace calls to sqlitePlugin.openDatabase() with window.openDatabase(). I've not yet tested this with Ripple but it should work. There are some database size limitations but this is probably all you need for testing.

There several ways to test if your inside Cordova. You could create a shim for the openDatabase() method based on testing for Cordova on app startup.

Since your primary goal is really to do rapid testing of SQLite with Cordova (rather than specifically to use Ripple) I'd like to suggest another new alternative to using Ripple.

I wrote an app call Sencha Touch Live that can be used for rapid development of Cordova / HTML5 apps by allowing you to Live Edit and Debug the HTML/JS/CSS code on your mobile device simply by updating files on your development computer - so you can skip most recompile/redeploy/restart debugger time costs. It has tons of other cool features. I'm using it myself for SQLite app testing instead of Ripple or Weinre

It's based on the code from Adobe's PhoneGap Developer App so core code is well tested. It's been extensively adapted and tuned for Sench Touch framework though it should also work for jQuery Mobile or any framework that places HTML5 code under the phonegap/www or cordova/www folder. Just start up the server in you PhoneGap or Cordova project folder.

For testing your SQL and controller logic, I recommend using Geny Motion emulator with a version of Android 4.4.x KitKat. Start up an recent version of Chrome on your desktop and once you get your app working on the emulator or real device open chrome://inspect and now you can use the full Chrome debugger on your remote device app. You can also use a recent version of Safari for OSX/iPhone Simulator testing.

You can watch a demo here (starts at the 5 min. mark). Yes! It needs a more polished video with less echoes but you'll get the idea:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top