【问题标题】:Ionic2 RC4, doesn't find plugin in production modeIonic2 RC4,在生产模式下找不到插件
【发布时间】:2017-01-10 18:11:07
【问题描述】:

我正在运行 Ionic 2 RC4,当我运行 ionic run android 时,应用程序可以运行,但设备准备就绪会在 15-18 秒后触发。我尝试在设备 ionic run android --prod 上运行,但它在 chrome 检查器中显示未安装 sqlite 插件,这是不正确的。如果我转到另一个页面并返回,它会显示我来自 SQLite 的数据。

constructor is called
main.js:1 Native: tried accessing the SQLite plugin but it's not installed.
x @ main.js:1
main.js:1 Install the SQLite plugin: 'ionic plugin add cordova-sqlite-storage'
x @ main.js:1
cordova.js:1223 deviceready has not fired after 5 seconds.
cordova.js:1216 Channel not fired: onFileSystemPathsReady
main.js:4 Native: deviceready did not fire within 2000ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.
(anonymous) @ main.js:4
main.js:4 DEVICE READY FIRED AFTER 2684 ms
error getting scheduled matches TypeError: Cannot read property 'executeSql' of undefined
at _ (main.js:1)
at main.js:1
at main.js:1
at new t (polyfills.js:3)
at e (main.js:1)
at s (main.js:1)
at t.<anonymous> (main.js:1)
at t.value [as executeSql] (main.js:1)
at t.getScheduledMatches (main.js:9)
at t.getMatchInfo (main.js:23)

我尝试在几个不同的位置准备好设备,并且我还登录了很多地方。最后调用的控制台日志称为构造函数

constructor(public timeSince: TimeSinceService,
    public platform: Platform) { 
    console.log("constructor is called"); //called

    if(!this.isOpen){            
        this.db = new SQLite();
        this.db.openDatabase({name: "aces.db", location: "default"}).then(() => {
            console.log("open Database"); // not called

            this.db.executeSql('PRAGMA user_version = 0', []).then(()=>console.log("yesss")) // not called
            this.db.executeSql('PRAGMA user_version', []).then(data => {
                if(data.rows.item(0).user_version !== current_version){
                console.log("versions do not match");
                }
            })

            this.db.executeSql('PRAGMA foreign_keys = ON', []).then(()=>{
                let query_matches = 'CREATE TABLE IF NOT EXISTS matches '+ 
                                '(id INTEGER PRIMARY KEY AUTOINCREMENT,'+
                                ...';
                let query_comments = 'CREATE TABLE IF NOT EXISTS comments '+ 
                            '(id INTEGER PRIMARY KEY AUTOINCREMENT, '+
                            ...';
                let query_points = 'CREATE TABLE IF NOT EXISTS undo'+ 
                            '(point_id INTEGER PRIMARY KEY AUTOINCREMENT,'+ 
                            ...';
                let query_organizations = 'CREATE TABLE IF NOT EXISTS organizations '...
                let query_users = 'CREATE TABLE IF NOT EXISTS users '+ 
                            '(id INTEGER PRIMARY KEY AUTOINCREMENT,'+
                            ...';
                Promise.all([      
                    this.db.executeSql(query_matches, {}).then(() => {
                        console.log("table created");
                    }, (err) => console.error('Unable to execute sql for matches: ', err)),
                    this.db.executeSql(query_comments, {}).then(() => {
                        console.log("comment table created");
                    }, (err) => console.error('Unable to execute sql for create comment table: ', err)),
                    this.db.executeSql(query_organizations, {}).then(() => {
                    console.log("table organizations created");
                    }, (err) => console.error('Unable to execute sql: ', err)),
                    this.db.executeSql(query_points, {}).then(() => {
                        console.log("undo table created");
                    }, (err) => console.error('Unable to execute sql for undo table: ', err)),
                    this.db.executeSql(query_users, {}).then(() => {
                        console.log("table users created");
                        }, (err) => console.error('Unable to execute sql: ', err))
                ]).then(()=> {
                    console.log("called promise all");
                    this.isOpen = true
                })
            })
        }, (error) => console.log("ERROR couldn't open database from sqlite service: ", error));
    }

}

【问题讨论】:

    标签: android sqlite ionic2


    【解决方案1】:

    回答我自己的问题,以防有人遇到同样的问题。

    我必须在 app.component.ts 中的 DeviceReady 中调用 rootPage。我希望它对某人有所帮助。

    【讨论】:

    • 我遇到了与未触发的设备相同的问题。 “调用rootPage”是什么意思?
    • 声明变量rootPage = TabsPage时不给值,只声明变量rootPage;然后在设备就绪时为 rootPage 赋值。
    • 我遇到了同样的问题,你救了我的命。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2014-03-25
    • 2021-01-26
    • 2013-05-09
    • 2021-06-01
    • 2018-12-13
    • 2019-05-26
    • 2013-07-14
    • 1970-01-01
    相关资源
    最近更新 更多