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

"Failed to install cordova-sqlite-ext" cordova 9.0.0 #44

Open
mb72 opened this issue Jul 9, 2019 · 10 comments
Open

"Failed to install cordova-sqlite-ext" cordova 9.0.0 #44

mb72 opened this issue Jul 9, 2019 · 10 comments

Comments

@mb72
Copy link

mb72 commented Jul 9, 2019

I get an error when adding Cordova platforms - "Failed to install 'cordova-sqlite-ext': CordovaError: Using "requireCordovaModule" to load non-cordova module "q" is not supported. Instead, add this module to your dependencies and use regular "require" to load it."

@mb72
Copy link
Author

mb72 commented Jul 16, 2019

@HarelM have you had this issue?

@HarelM
Copy link

HarelM commented Jul 16, 2019

I was unable to make Cordova 9.0 fully work on my machine (Win 10). I'm still using 8 due to that fact...

@mb72
Copy link
Author

mb72 commented Jul 18, 2019 via email

@kiRyyy
Copy link

kiRyyy commented Jul 21, 2019

go to \plugins\cordova-sqlite-ext\scripts\beforePluginInstall.js

add --> var Q = require('q');
and comment --> var Q = context.requireCordovaModule('q');

@mb72
Copy link
Author

mb72 commented Aug 8, 2019

Thanks for the tip!

@mb72
Copy link
Author

mb72 commented Aug 20, 2019

@kiRyyy I'm still getting the error and cordova-sqlite-ext is still not installing.
@HarelM What build of Cordova is this working on for you? I tried running Cordova 8 and got the same problem.

@mb72 mb72 closed this as completed Aug 20, 2019
@mb72 mb72 reopened this Aug 20, 2019
@HarelM
Copy link

HarelM commented Aug 21, 2019

@mb72 I have now switch to latest - 9.0.
I'm not using sqlite-ext anymore but rather dexie which is a wrapper of IndexDB.
I have created a fork of mapbox-gl-js, added a hook for getting custom tiles and written the code I needed. So basically, I'm not using this library.
The following is my fork of mabpox:
https://github.com/IsraelHikingMap/mapbox-gl-js
And the relevant code that uses the hook can be found here:
https://github.com/IsraelHikingMap/Site/blob/d11d20d9e7b1c2b92e800e421f4045d8b5b56d44/IsraelHiking.Web/sources/application/services/database.service.ts#L79

I think the problem in my case of migrating to Cordova 9.0 was that I used cordova-android-play-services-gradle-release - removing it allowed me to move forward, I think.

@mb72
Copy link
Author

mb72 commented Aug 26, 2019

@HarelM Thanks, but I'm not seeing how your project integrates with Cordova. What are the steps for turning it into an app? Where do the mbtiles files go?
I don't see any way to submit issues for your project. Can you add that? Thanks.

@HarelM
Copy link

HarelM commented Aug 28, 2019

@mb72 there are several "moving parts" involved here, I'll see if I can better explain then:
I don't see a good reason to allow issues in my fork of mapbox-gl as I have only added a simple hook. The code that uses this library, IsraelHikinhMap project, is a cordova app that uses the mapbox fork using patch-package library.
Feel free to submit an issue there, the main issue that covers this topic is the following:
IsraelHikingMap/Site#783
You can see related commits to this issue, or we can continue the discussion there.
I have create a small piece of code in nodejs to convert mbtiles file into a json file, here's the relevant code:

var sqlite3 = require('sqlite3').verbose();
var fs = require('fs');
var pako = require('pako');
var main = require('async-main').default;

let dbFilePath = process.argv[2];
let filePrefix = process.argv[3];
let recordsSplit = process.argv[4];


console.log(`Database file name: ${dbFilePath}`);
console.log(`Output file name prefix: ${filePrefix}`);
console.log(`Maximal number of record in each file: ${recordsSplit}`);

main(async () => {
	var sqlDb = new sqlite3.Database(dbFilePath, sqlite3.OPEN_READONLY);
	
	var data = await new Promise((resolve, reject) => {
		var res = []
		sqlDb.all('SELECT * FROM tiles', (err, rows) => {
			for (let row of rows) {
				var y = Math.pow(2, row.zoom_level) - row.tile_row - 1;
				var id = `${row.zoom_level}_${row.tile_column}_${y}`;
				var rawData = row.tile_data;
				let isGzipped = rawData[0] === 0x1f && rawData[1] === 0x8b;
				if (isGzipped) {
                    rawData = new Buffer(pako.inflate(rawData).buffer);
                }
				console.log(id);
				res.push({id: id, x: row.tile_column, y: y, z: row.zoom_level, data: rawData.toString("base64")});
			}
			resolve(res);
		});
	});
	let fileNameIndex = 0;
	let promisesArray = [];
	while (data.length > 0) {
		let dataToDump = data.splice(0, recordsSplit);
		let fileNameIndexString = fileNameIndex.toString();
		let fileName = filePrefix + fileNameIndexString.padStart(10, '0') + ".json";
		fileNameIndex++;
		let promise = new Promise((resolve, reject) => {
			fs.writeFile(fileName, JSON.stringify(dataToDump), (err) => {
				if (err) {
					reject(err);
				}
				console.log(`Finished writing: ${fileName}`);
				resolve();
			})
		});
		promisesArray.push(promise);
	}
	await Promise.all(promisesArray);
});

After I have this file containing json data I can load it the browser database as a document and fetch it with the custom hook.
It's a bit complex, but extremely powerful. Feel free to continue this discussion is the issue above I linked as I think it's off topic for this issue.

@jeffschuler
Copy link

I had the original issue here, too, and followed these suggestions to fix it:

cordova platform rm android
cordova plugin rm cordova-sqlite-ext
npm i cordova-sqlite-ext@latest
cordova plugin add cordova-sqlite-ext
cordova platform add android

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

No branches or pull requests

4 participants