guy-keller / cordova-wearos-plugin

Simple plugin that establishes a session with a WearOs Smartwach and helps exchange of messages between a cordova application and its WearOs Watch application and vice-versa.
2 stars 3 forks source link

Error on "registerMessageListener :: listener" #3

Closed mebencomo closed 3 years ago

mebencomo commented 3 years ago

Hi! I'm working with your plugin in my project and it gives me this error. What could be happening?

Thanks!

2021-02-15 11:04:48.307 15693-15778/? I/CordovaWearOsPlugin: constructor
2021-02-15 11:04:48.307 15693-15778/? I/CordovaWearOsPlugin: initialize
2021-02-15 11:04:48.307 15693-15778/? I/CordovaWearOsPlugin: execute
2021-02-15 11:04:48.308 15693-15778/? I/CordovaWearOsPlugin: init
2021-02-15 11:04:50.311 15693-15778/? I/CordovaWearOsPlugin: execute
2021-02-15 11:04:50.312 15693-15778/? I/CordovaWearOsPlugin: registerMessageListener :: listener: org.apache.cordova.CallbackContext@777fdca
2021-02-15 11:04:50.312 15693-15778/? I/CordovaWearOsPlugin: createWearOsMessageListener
2021-02-15 11:04:50.312 15693-15778/? I/CordovaWearOsPlugin: registerMessageListener
2021-02-15 11:04:50.352 15693-15778/? W/System.err: at com.google.android.gms.wearable.DataClient.(Unknown Source:3)
2021-02-15 11:04:50.353 15693-15778/? W/System.err: at com.google.android.gms.wearable.internal.zzcj.(Unknown Source:4)
2021-02-15 11:04:50.353 15693-15778/? W/System.err: at com.google.android.gms.wearable.Wearable.getDataClient(Unknown Source:5)
2021-02-15 11:04:50.353 15693-15778/? W/System.err: at com.github.guikeller.cordova.wearos.CordovaWearOsPlugin.registerWearableMessageListener(CordovaWearOsPlugin.java:129)
2021-02-15 11:04:50.353 15693-15778/? W/System.err: at com.github.guikeller.cordova.wearos.CordovaWearOsPlugin.registerMessageListener(CordovaWearOsPlugin.java:89)
2021-02-15 11:04:50.353 15693-15778/? W/System.err: at com.github.guikeller.cordova.wearos.CordovaWearOsPlugin.execute(CordovaWearOsPlugin.java:60)
guy-keller commented 3 years ago

2021-02-15 11:04:50.353 15693-15778/? W/System.err: at com.google.android.gms.wearable.Wearable.getDataClient(Unknown Source:5) 2021-02-15 11:04:50.353 15693-15778/? W/System.err: at com.github.guikeller.cordova.wearos.CordovaWearOsPlugin.registerWearableMessageListener(CordovaWearOsPlugin.java:129) 2021-02-15 11:04:50.353 15693-15778/? W/System.err: at com.github.guikeller.cordova.wearos.CordovaWearOsPlugin.registerMessageListener(CordovaWearOsPlugin.java:89)

Which is: https://github.com/guikeller/cordova-wearos-plugin-source/blob/master/app/src/main/java/com/github/guikeller/cordova/wearos/CordovaWearOsPlugin.java#L129

// L129
Wearable.getDataClient(context).addListener(new DataClient.OnDataChangedListener() {
   ...
}

Are you importing the following libs?

    implementation 'com.google.android.gms:play-services-base:+'
    implementation 'com.google.android.gms:play-services-wearable:+'

Source: https://stackoverflow.com/questions/58202877/error-while-accessing-android-wear-data-layer

mebencomo commented 3 years ago

Hi! Thanks for the answer. Yes, I'm importing those libs. Here is my cordova app build gradle:

/*
 * WARNING: Cordova Lib and platform scripts do management inside of this code here,
 * if you are adding the dependencies manually, do so outside the comments, otherwise
 * the Cordova tools will overwrite them
 */

dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    implementation(project(path: ":CordovaLib"))
    implementation "com.google.android.gms:play-services-base:+"
    implementation "com.google.android.gms:play-services-wearable:+"
    // SUB-PROJECT DEPENDENCIES END
}
mebencomo commented 3 years ago

I also use implementation 'com.google.android.gms:play-services-base:17.2.1'. But i got the same error

guy-keller commented 3 years ago

Did you also install the other plugins required?

cordova-plugin-androidx
cordova-plugin-androidx-adapter
cordova-android-play-services-gradle-release
mebencomo commented 3 years ago

Yes. I've following all the steps that you indicates.

mebencomo commented 3 years ago

In build.gradle:

// PLUGIN GRADLE EXTENSIONS START apply from: "../cordova-android-play-services-gradle-release/hellocordova-cordova-android-play-services-gradle-release.gradle"

mebencomo commented 3 years ago

I have an addionatl question: to test all project i'm using my phone (cordova app) and wear androind studio emulator, is that correct?

guy-keller commented 3 years ago

Hi @mebencomo

Q) To test the project I'm using my phone (Cordova app) and an emulated WearOS (Android Studio), is that okay? A) To be honest, I have never tested against the watch emulator / always used real devices. Would you be able to test against a real WearOS device?

Also, as the error message says the following:

2021-02-15 11:04:50.312 15693-15778/? I/CordovaWearOsPlugin: registerMessageListener 2021-02-15 11:04:50.352 15693-15778/? W/System.err: at com.google.android.gms.wearable.DataClient.(Unknown Source:3) 2021-02-15 11:04:50.353 15693-15778/? W/System.err: at com.google.android.gms.wearable.internal.zzcj.(Unknown Source:4) 2021-02-15 11:04:50.353 15693-15778/? W/System.err: at com.google.android.gms.wearable.Wearable.getDataClient(Unknown Source:5)

I wonder if there is any connection to this ( ? ) : https://developer.android.com/training/wearables/data-layer/migrate-to-googleapi

Do you have the "Wear OS" app installed on your mobile phone as well? Thinking out loud: I do not think that will work against the emulator (real mobile X emulated watch)

guy-keller commented 3 years ago

Hi @mebencomo

Any progress? :)

mebencomo commented 3 years ago

Hi! I have WearOS app in my phone. I've been using ADB command to connect my phone and the emulator.

They emulator see my phone like a node to deespach the Message. But the phone won't recive it.

The phone won't connect with the emulator.

guy-keller commented 3 years ago

Hi @mebencomo

I believe that is something to do with the emulator in the mix.

See this tutorial on how to do the emulator "Wearable Configuration" to talk to your phone. https://heartbeat.fritz.ai/connect-android-devices-with-an-android-wear-emulator-338c8e50e8a4

As you can see it is not quite like a walk in the park with the emulator in the mix. In addition to that keep an eye on the issue: #4

Cheers, Gui

mebencomo commented 3 years ago

Hi!!

It's working now! I was working with an old version for the emulator.

Thank you so much for your support!!

guy-keller commented 3 years ago

Hi @mebencomo

No worries, I am glad to hear that you managed to send/receive messages between your Cordova and WearOS app. Is there anything in the docs that needs better explaining?

Good luck with your project, cheers!