我正在使用Ionic2。
我的电脑崩溃了,我不得不重新安装我的应用程序,幸运的是我备份了所有的源代码。
源代码在Android设备崩溃之前完美运行。
ionic build android
我现在的问题是,当我构建并安装apk
时,某些插件无法在设备上运行。这些错误必须与依赖关系相关,因为之前这有效。
任何想法如何解决错误将不胜感激。
1)SQLite错误
Unable to open database ReferenceError message: "sqlitePlugin is not defined" stack: (...) get stack: function () { [native code] } set stack: function () { [native code] } __proto__: Error
app.ts
import { StatusBar, Push, SQLite } from 'ionic-native';
private createDatabase(): void {
let db: SQLite = new SQLite();
db.openDatabase({
name: "data.db",
location: "default"
}).then(() => {
db.executeSql("CREATE TABLE IF NOT EXISTS chats (_id TEXT PRIMARY KEY, memberIds TEXT, title TEXT, subTitle TEXT, picture TEXT, lastMessageId TEXT, lastMessageCreatedAt DATE)", {}).then((chatData) => {
db.executeSql("CREATE TABLE IF NOT EXISTS messages (_id TEXT PRIMARY KEY, chatId TEXT, senderId TEXT, ownership TEXT, content TEXT, createdAt DATE, changeDate BOOLEAN, readByReceiver BOOLEAN)", {}).then((messageData) => {
}, (error) => {
console.error("Unable to execute messages sql", error);
});
}, (error) => {
console.error("Unable to execute chats sql", error);
});
}, (error) => {
console.error("Unable to open database", error);
});
}
2)地理位置错误
PositionError {message: "Timeout expired", code: 3, PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3}
ts档
import { Geolocation } from 'ionic-native';
public getPosition(): void {
if (this.markers && this.markers.length > 0) {
var marker: google.maps.Marker = this.markers[0]; // only one
this.latitude = marker.getPosition().lat();
this.longitude = marker.getPosition().lng();
this.getJobRangeSearch(this.searchQuery);
} else {
let options = {
timeout: 10000,
enableHighAccuracy: true
};
Geolocation.getCurrentPosition(options).then((position) => {
this.latitude = position.coords.latitude;
this.longitude = position.coords.longitude;
this.getJobRangeSearch(this.searchQuery);
}).catch((error) => {
console.log(error);
this.doAlert(error+' Timeout trying to get your devices Location');
});
}
}
我收到Timeout trying to get your devices Location
错误警告。
的package.json
{
"dependencies": {
"@angular/common": "^2.0.0-rc.4",
"@angular/compiler": "^2.0.0-rc.4",
"@angular/core": "^2.0.0-rc.4",
"@angular/forms": "^0.2.0",
"@angular/http": "^2.0.0-rc.4",
"@angular/platform-browser": "^2.0.0-rc.4",
"@angular/platform-browser-dynamic": "^2.0.0-rc.4",
"accounts-base-client-side": "^0.1.1",
"accounts-phone": "0.0.1",
"angular2-meteor": "^0.6.2",
"angular2-meteor-polyfills": "^0.1.1",
"angular2-moment": "^0.8.2",
"es6-shim": "^0.35.0",
"ionic-angular": "^2.0.0-beta.11",
"ionic-native": "^1.3.2",
"ionicons": "3.0.0",
"meteor-client-side": "^1.3.4",
"moment": "^2.14.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"socket.io": "^1.4.8",
"zone.js": "^0.6.12"
},
"devDependencies": {
"del": "2.2.0",
"gulp": "3.9.1",
"gulp-watch": "4.3.5",
"ionic-gulp-fonts-copy": "^1.0.0",
"ionic-gulp-html-copy": "^1.0.0",
"ionic-gulp-sass-build": "^1.0.0",
"ionic-gulp-scripts-copy": "^2.0.0",
"ionic-gulp-tslint": "^1.0.0",
"ionic-gulp-webpack": "^2.0.0",
"lodash.camelcase": "^4.3.0",
"lodash.upperfirst": "^4.3.1",
"run-sequence": "1.1.5",
"ts-loader": "^0.8.2",
"tslint-ionic-rules": "^0.0.3",
"webpack": "^1.13.2"
},
"name": "theWhoZoo",
"description": "theWhoZoo: An Ionic project",
"cordovaPlugins": [
"cordova-plugin-device",
"cordova-plugin-console",
"cordova-plugin-whitelist",
"cordova-plugin-splashscreen",
"cordova-plugin-statusbar",
"ionic-plugin-keyboard",
{
"variables": {
"SENDER_ID": "XXXXXXXXXXX"
},
"locator": "phonegap-plugin-push",
"id": "phonegap-plugin-push"
}
],
"cordovaPlatforms": []
}
更新
如果我这样做:
npm install ionic-angular
我明白了:
+-- ionic-angular@2.0.0-rc.0
| +-- UNMET PEER DEPENDENCY @angular/compiler@2.0.2
| +-- UNMET PEER DEPENDENCY @angular/platform-browser@2.0.2
| +-- UNMET PEER DEPENDENCY rxjs@5.0.0-rc.1
| `-- UNMET PEER DEPENDENCY zone.js@0.6.25
+-- UNMET PEER DEPENDENCY rxjs@5.0.0-beta.6
`-- UNMET PEER DEPENDENCY zone.js@0.6.12
如何安装rxjs
和zone.js
?
如果我这样做:
npm install zone.js
我明白了:
+-- UNMET PEER DEPENDENCY rxjs@5.0.0-beta.6
`-- zone.js@0.6.25
当我尝试安装依赖项时,它表示缺少相同的依赖项。这有什么意义呢?
npm install rxjs@5.0.0-beta.12 --save
`-- UNMET PEER DEPENDENCY rxjs@5.0.0-beta.12
更新
我删除了node_modules
,npm istall
编辑了package.json
中的包,但我没有依赖错误。
但是现在当我构建apk
并在设备上运行它时,我得到:
Failed to load resource: net::ERR_FILE_NOT_FOUND file:///android_asset/www/build/js/app.bundle.js deviceready has not fired after 5 seconds. cordova.js:1185 Channel not fired: onDOMContentLoaded
答案 0 :(得分:0)
您的设置似乎很糟糕。 :)
尝试ionic state reset
Clear out the platforms and plugins directories, and reinstall plugins and platforms
希望有所帮助。