MobileChromeApps / cordova-plugin-chrome-apps-bluetooth

BSD 3-Clause "New" or "Revised" License
10 stars 11 forks source link

Problems on Cordova / Android #3

Closed baursn closed 8 years ago

baursn commented 9 years ago

Something seems to be wrong with the current build system for android using cordova. When trying to access the api via js, i get java.lang.NoClassDefFoundError in my adb logcat:

W/System.err( 321): java.lang.NoClassDefFoundError: Failed resolution of: Lorg/uribeacon/scan/compat/ScanWakefulBroadcastReceiver; W/System.err( 321): at org.uribeacon.scan.compat.JbBluetoothLeScannerCompat.<init>(JbBluetoothLeScannerCompat.java:148) W/System.err( 321): at org.uribeacon.scan.compat.BluetoothLeScannerCompatProvider.getBluetoothLeScannerCompat(BluetoothLeScannerCompatProvider.java:87) W/System.err( 321): at org.uribeacon.scan.compat.BluetoothLeScannerCompatProvider.getBluetoothLeScannerCompat(BluetoothLeScannerCompatProvider.java:60) W/System.err( 321): at org.chromium.ChromeBluetooth.pluginInitialize(ChromeBluetooth.java:100) W/System.err( 321): at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:55) W/System.err( 321): at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:169) W/System.err( 321): at org.apache.cordova.PluginManager.exec(PluginManager.java:120) W/System.err( 321): at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59) W/System.err( 321): at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41) W/System.err( 321): at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method) W/System.err( 321): at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53) W/System.err( 321): at android.os.Handler.dispatchMessage(Handler.java:102) W/System.err( 321): at android.os.Looper.loop(Looper.java:135) W/System.err( 321): at android.os.HandlerThread.run(HandlerThread.java:61) W/System.err( 321): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.uribeacon.scan.compat.ScanWakefulBroadcastReceiver" on path: DexPathList[[zip file "/data/app/de.c0n.chromeBT-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] W/System.err( 321): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) W/System.err( 321): at java.lang.ClassLoader.loadClass(ClassLoader.java:511) W/System.err( 321): at java.lang.ClassLoader.loadClass(ClassLoader.java:469) W/System.err( 321): ... 14 more W/System.err( 321): Suppressed: java.lang.NoClassDefFoundError: org.uribeacon.scan.compat.ScanWakefulBroadcastReceiver W/System.err( 321): at dalvik.system.DexFile.defineClassNative(Native Method) W/System.err( 321): at dalvik.system.DexFile.defineClass(DexFile.java:226) W/System.err( 321): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219) W/System.err( 321): at dalvik.system.DexPathList.findClass(DexPathList.java:321) W/System.err( 321): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54) W/System.err( 321): ... 16 more W/System.err( 321): Suppressed: java.lang.ClassNotFoundException: org.uribeacon.scan.compat.ScanWakefulBroadcastReceiver W/System.err( 321): at java.lang.Class.classForName(Native Method) W/System.err( 321): at java.lang.BootClassLoader.findClass(ClassLoader.java:781) W/System.err( 321): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) W/System.err( 321): at java.lang.ClassLoader.loadClass(ClassLoader.java:504) W/System.err( 321): ... 15 more W/System.err( 321): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available I/art ( 321): Rejecting re-init on previously-failed class java.lang.Class<org.uribeacon.scan.compat.ScanWakefulBroadcastReceiver> W/System.err( 321): java.lang.NoClassDefFoundError: org.uribeacon.scan.compat.ScanWakefulBroadcastReceiver W/System.err( 321): at org.uribeacon.scan.compat.JbBluetoothLeScannerCompat.<init>(JbBluetoothLeScannerCompat.java:148) W/System.err( 321): at org.uribeacon.scan.compat.BluetoothLeScannerCompatProvider.getBluetoothLeScannerCompat(BluetoothLeScannerCompatProvider.java:87) W/System.err( 321): at org.uribeacon.scan.compat.BluetoothLeScannerCompatProvider.getBluetoothLeScannerCompat(BluetoothLeScannerCompatProvider.java:60) W/System.err( 321): at org.chromium.ChromeBluetooth.pluginInitialize(ChromeBluetooth.java:100) W/System.err( 321): at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:55) W/System.err( 321): at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:169) W/System.err( 321): at org.apache.cordova.PluginManager.exec(PluginManager.java:120) W/System.err( 321): at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59) W/System.err( 321): at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41) W/System.err( 321): at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method) W/System.err( 321): at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53) W/System.err( 321): at android.os.Handler.dispatchMessage(Handler.java:102) W/System.err( 321): at android.os.Looper.loop(Looper.java:135) W/System.err( 321): at android.os.HandlerThread.run(HandlerThread.java:61)

I have a platforms/android/libs/blescan.jar which does contain the necessary class, but somehow it is not picked up by the android class loader.

Using cordova 5.1.1 on linux.

Steps to reproduce:

create a new project with cordova cli, then cordova platform add android, cordova plugin add org.chromium.bluetooth, cordova build, cordova run, adb logcat.

DanielJoyce commented 9 years ago

We are getting the same error, missing library?

DanielJoyce commented 9 years ago

Looks like there is a dependency on artifacts from this project:

http://google.github.io/uribeacon/

Which when you use CCA to pull in this plugin, the dependencies are not properly pulled in as well

DanielJoyce commented 9 years ago

Looks like jar with class is there, but not being packaged properly?

DanielJoyce commented 9 years ago

//// leScanner = BluetoothLeScannerCompatProvider.getBluetoothLeScannerCompat(webView.getContext());

Commenting out all code using leScanner at least gets Bluetooth coming up for me. I suspect the problem is how BluetoothLeScannerCompatProvider tries to resolve java class files, and this barfs on Android

jmorille commented 9 years ago

+1 On the android 4.4.4 on galaxy S3 I have the same problem on android with a cca "0.7.1" app compose with this plugins

cordova-plugin-background-app 2.0.2 "Background App"
cordova-plugin-blob-constructor-polyfill 1.0.2 "Blob constructor shim"
cordova-plugin-chrome-apps-bluetooth 1.1.4 "Chrome Apps Bluetooth API"
cordova-plugin-chrome-apps-bluetoothsocket 1.0.1 "Chrome Apps Bluetooth Socket API"
cordova-plugin-chrome-apps-bootstrap 2.0.7 "Chrome Apps Core"
cordova-plugin-chrome-apps-common 1.0.7 "Chrome Apps Common Utils"
cordova-plugin-chrome-apps-i18n 2.0.1 "Chrome Apps I18n API"
cordova-plugin-chrome-apps-navigation 1.0.3 "Chrome Apps Navigation"
cordova-plugin-chrome-apps-runtime 1.1.1 "Chrome App Runtime"
cordova-plugin-chrome-apps-storage 1.0.4 "Chrome Apps Storage API"
cordova-plugin-crosswalk-webview 1.2.0 "Crosswalk WebView Engine"
cordova-plugin-customevent-polyfill 1.0.5-dev "CustomEvent constuctor shim"
cordova-plugin-file 2.1.0 "File"
cordova-plugin-inappbrowser 1.0.1 "InAppBrowser"
cordova-plugin-network-information 1.0.1 "Network Information"
cordova-plugin-statusbar 1.0.1 "StatusBar"
cordova-plugin-whitelist 1.0.0 "Whitelist"
cordova-plugin-xhr-blob-polyfill 1.0.3 "XHR Blob Response Type Polyfill"
org.chromium.cca-hooks 0.0.0 "undefined"

the javascript function call chrome.bluetooth.startDiscovery the internal command

 exec(callback, fail(callback), 'ChromeBluetooth', 'startDiscovery', []);

that never reach the startDiscovery callback bacause that raise in adb console the stack

D/lights  ( 2484): set_light_buttons: 1
I/chromium(19726): [INFO:CONSOLE(16229)] "list device ", source: chrome-extension://nbnkkhjhmgkfcmdapdfaikdclfbdfjkf/elements/elements.js (16229)
W/System.err(19726): java.lang.NoClassDefFoundError: org.uribeacon.scan.compat.ScanWakefulBroadcastReceiver
W/System.err(19726):    at org.uribeacon.scan.compat.JbBluetoothLeScannerCompat.<init>(JbBluetoothLeScannerCompat.java:148)
W/System.err(19726):    at org.uribeacon.scan.compat.BluetoothLeScannerCompatProvider.getBluetoothLeScannerCompat(BluetoothLeScannerCompatProvider.java:87)
W/System.err(19726):    at org.uribeacon.scan.compat.BluetoothLeScannerCompatProvider.getBluetoothLeScannerCompat(BluetoothLeScannerCompatProvider.java:60)
W/System.err(19726):    at org.chromium.ChromeBluetooth.pluginInitialize(ChromeBluetooth.java:101)
W/System.err(19726):    at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:55)
W/System.err(19726):    at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:169)
W/System.err(19726):    at org.apache.cordova.PluginManager.exec(PluginManager.java:120)
W/System.err(19726):    at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
W/System.err(19726):    at org.crosswalk.engine.XWalkExposedJsApi.exec(XWalkExposedJsApi.java:40)
W/System.err(19726):    at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err(19726):    at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
W/System.err(19726):    at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err(19726):    at android.os.Looper.loop(Looper.java:136)
W/System.err(19726):    at android.os.HandlerThread.run(HandlerThread.java:61)
I/chromium(19726): [INFO:CONSOLE(16235)] "add listener device ", source: chrome-extension://nbnkkhjhmgkfcmdapdfaikdclfbdfjkf/elements/elements.js (16235)
I/chromium(19726): [INFO:CONSOLE(16245)] "get devices ", source: chrome-extension://nbnkkhjhmgkfcmdapdfaikdclfbdfjkf/elements/elements.js (16245)
W/System.err(19726): java.lang.NoClassDefFoundError: org.uribeacon.scan.compat.ScanWakefulBroadcastReceiver
W/System.err(19726):    at org.uribeacon.scan.compat.JbBluetoothLeScannerCompat.<init>(JbBluetoothLeScannerCompat.java:148)
W/System.err(19726):    at org.uribeacon.scan.compat.BluetoothLeScannerCompatProvider.getBluetoothLeScannerCompat(BluetoothLeScannerCompatProvider.java:87)
W/System.err(19726):    at org.uribeacon.scan.compat.BluetoothLeScannerCompatProvider.getBluetoothLeScannerCompat(BluetoothLeScannerCompatProvider.java:60)
W/System.err(19726):    at org.chromium.ChromeBluetooth.pluginInitialize(ChromeBluetooth.java:101)
W/System.err(19726):    at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:55)
W/System.err(19726):    at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:169)
W/System.err(19726):    at org.apache.cordova.PluginManager.exec(PluginManager.java:120)
W/System.err(19726):    at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
W/System.err(19726):    at org.crosswalk.engine.XWalkExposedJsApi.exec(XWalkExposedJsApi.java:40)
W/System.err(19726):    at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err(19726):    at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
W/System.err(19726):    at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err(19726):    at android.os.Looper.loop(Looper.java:136)
W/System.err(19726):    at android.os.HandlerThread.run(HandlerThread.java:61)
I/chromium(19726): [INFO:CONSOLE(16254)] "request  startDiscovery on ", source: chrome-extension://nbnkkhjhmgkfcmdapdfaikdclfbdfjkf/elements/elements.js (16254)
W/System.err(19726): java.lang.NoClassDefFoundError: org.uribeacon.scan.compat.ScanWakefulBroadcastReceiver
W/System.err(19726):    at org.uribeacon.scan.compat.JbBluetoothLeScannerCompat.<init>(JbBluetoothLeScannerCompat.java:148)
W/System.err(19726):    at org.uribeacon.scan.compat.BluetoothLeScannerCompatProvider.getBluetoothLeScannerCompat(BluetoothLeScannerCompatProvider.java:87)
W/System.err(19726):    at org.uribeacon.scan.compat.BluetoothLeScannerCompatProvider.getBluetoothLeScannerCompat(BluetoothLeScannerCompatProvider.java:60)
W/System.err(19726):    at org.chromium.ChromeBluetooth.pluginInitialize(ChromeBluetooth.java:101)
W/System.err(19726):    at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:55)
W/System.err(19726):    at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:169)
W/System.err(19726):    at org.apache.cordova.PluginManager.exec(PluginManager.java:120)
W/System.err(19726):    at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
W/System.err(19726):    at org.crosswalk.engine.XWalkExposedJsApi.exec(XWalkExposedJsApi.java:40)
W/System.err(19726):    at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err(19726):    at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
W/System.err(19726):    at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err(19726):    at android.os.Looper.loop(Looper.java:136)
W/System.err(19726):    at android.os.HandlerThread.run(HandlerThread.java:61)
D/lights  ( 2484): set_light_buttons: 2
latentflip commented 9 years ago

Has anyone found a workaround for this? Is it possible to manually import the required deps from uribeacon manually? (I'm inexperienced with android :( )

jmorille commented 9 years ago

The class org/uribeacon/scan/compat/ScanWakefulBroadcastReceiver is in the lib blescan.jar.

yeswecoin commented 9 years ago

Any solution for this yet? Cause I'm running into the same NoClassDefFoundError. Tried to import the BroadcastReceiver manually as well as extracting the jar, but nothing seems to help

wifisher commented 8 years ago

I just ran into this issue today and haven't been able to figure out why. I have updated to the latest Cordova, etc with no change. What am I missing?

wifisher commented 8 years ago

Looks like I posted too soon... But here is the answer if anyone else runs into this. It appears that you need the Android Support Library included in your app. I just copied the android-support-v4.jar file from the C:\Program Files (x86)\Android\android-sdk\extras\android\support\v4 into platforms\android\libs and this error is gone.

wifisher commented 8 years ago

To follow up on my previous comment, an even better fix is to include the cordova-plugin-android-support-v4 plugin in your project. I'm not sure why it is not listed as a dependency for this plugin.

ateufel commented 8 years ago

that fixed my problem with getAdapterState, thanx! does anyone know how to get paired devices? getDevices always returns an empty array, but both android devices have android 5.1.1 and bluetooth activated, and they are definitely paired. startDiscovery with non-paired devices does not get me anything either, even though the callback response is "OK".

wifisher commented 8 years ago

I pretty much gave up on this plugin. I had grabbed the Chrome example code for the BLE API and modified it to work within Cordova. I found it to be unreliable. Sometimes it would catch one of my SensorTag devices but it usually wouldn't find them.

I've had better luck with the cordova-plugin-bluetoothle plugin. I haven't done anything significant with it yet, but its example code seems to reliably find the SensorTags.

I had hoped to use this Chrome plugin to get compatibility with desktops as well as Android and iOS, but I can live with the desktop platforms for now.

ateufel commented 8 years ago

i only need bluetooth between android devices, is there ANY working cordova plugin for that? :(