Ich versuche ein Plugin zu erstellen, das es einer NativeScript-Anwendung ermöglicht, sich mit einem MQTT-Server zu verbinden. Wenn ich versuche, die Anwendung bekomme ich folgende Fehler in meiner Anwendung auszuführen:Erstellen eines Android NativeScript-Plugins
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.testMQTT/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
TypeError: Cannot read property 'paho' of undefined File: ", line: 1, column: 265
StackTrace: Frame: function:'NativeScriptMQTTClient', file:'/data/data/org.nativescript.testMQTT/files/app/tns_modules/nativescript-mqtt/mqtt.js', line: 8, column: 44 Frame: function:'', file:'/data/data/org.nativescript.testMQTT/files/app/main-page.js', line: 4, column: 14 Frame: function:'require', file:'', line: 1, column: 266 Frame: function:'global.loadModule', file:'/data/data/org.nativescript.testMQTT/files/app/tns_modules/globals/globals.js', line: 19, column: 16 Frame: function:'resolvePageFromEntry', file:'/data/data/org.nativescript.testMQTT/files/app/tns_modules/ui/frame/frame-common.js', line: 72, column: 40 Frame: function:'Frame.navigate', file:'/data/data/org.nativescript.testMQTT/files/app/tns_modules/ui/fr
ich mit der Paho Java-Bibliothek des folgenden Code bin mit meiner mqtt.android.ts Datei:
export class NativeScriptMQTTClient {
private _topic: String;
private _content: String;
private _qos: number;
private _broker: String;
private _clientId: String;
private _persistance: org.eclipse.paho.client.mqttv3.persist.MemoryPersistance;
private _client: org.eclipse.paho.client.mqttv3.MqttClient;
private _connectOptions: org.eclipse.paho.client.mqttv3.MqttConnectOptions;
constructor(topic: String, qos: number, broker: string, clientId: String) {
this._topic = topic;
this._qos = qos;
this._broker = broker;
this._clientId = clientId;
this._persistance = new org.eclipse.paho.client.mqttv3.persist.MemoryPersistance();
}
connect() {
this._client = new org.eclipse.paho.client.mqttv3.MqttClient(this._broker, this._clientId, this._persistance);
this._connectOptions = new org.eclipse.paho.client.mqttv3.MqttConnectOptions();
this._connectOptions.setCleanSession(true);
console.log("Connecting to the broker: " + this._broker);
this._client.connect(this._connectOptions);
console.log("Connected to the broker: " + this._broker);
console.log("Publishing message: Hello from NativeScript (Morné)");
this._client.publish(this._topic, "Hello from NativeScript (Morné)");
console.log("Published message: Hello from NativeScript (Morné)");
console.log("Disconnecting from the broker: " + this._broker);
this._client.disconnect();
console.log("Disconnected from the broker: " + this._broker);
}
}
Und ich habe den folgenden Code in meiner Haupt-page.ts Datei:
import {NativeScriptMQTTClient} from "nativescript-mqtt";
let client: NativeScriptMQTTClient = new NativeScriptMQTTClient("MQTT Examples", 2, "tcp://iot.eclipse.org:1883", "NativeScriptClient");
client.connect();
Jede Hilfe wäre sehr dankbar.
Haben Sie die Bibliothek Jar-Datei (org.eclipse.paho.client.mqttv3-1.0.2.jar) in Plattformen/Android/libs in Ihrem Plugin –