Reputation: 1169
I am using cordova-sqlite-ext in ionic 3 project. My code is working fine when run without --prod
flag.
But when i run ionic cordova run android --prod --relase
it shows "can not read property of openDatabase"
here is my code
export class SqlLiteServiceProvider {
private options = {name: 'db.db', location: 'default',existingDatabase: 1,createFromLocation:1};
public win = (<any>window);
private db : any;
constructor() {
try{
if(this.win.cordova){
this.db = this.win.sqlitePlugin.openDatabase(this.options);
}else{
this.db = this.win.openDatabase(this.options.name, '1.0', 'database', 5 * 1024 * 1024);
}
}catch(ex){
alert(ex); // always alert error when run with --prod flag
}
}
}
Upvotes: 1
Views: 535
Reputation: 65920
You cannot run ionic cordova run android --prod --relase
with on debug mode. It is for google play store release build. If you need to test on your device you should run below CLI
.
ionic cordova run android --prod --device
Upvotes: 0
Reputation: 7517
When you do a production build the window
object is handled differently as far as I know. When using cordova-plugins which are not included in ionic-native you need to do things a bit different.
Tell typescript that you are sure your plugin handle exists somewhere after the build:
declar var SQLitePlugin; // add this at the same level as imports
And to use it for example in ngOnInit()
:
ngOnInit() {
SQLitePlugin.openDatabase(...);
}
But instead of doing this I strongly recommend you using @ionic/storage
or @ionic-native/sqlite
.
Upvotes: 1