b3b / able

Python for Android Bluetooth Low Energy package
MIT License
39 stars 18 forks source link

JavaException: Class not found 'org/able/PythonBluetooth' #5

Closed RoberWare closed 5 years ago

RoberWare commented 5 years ago

I'm trying to discover near bluetooth LE services, and when I call the start_scan() method I get the following error:

jnius.JavaException: Class not found b'org/jnius/NativeInvocationHandler'

I solved it following this, retrieve the org.jnius.NativeInvocationHandler manually in my main thread using:

autoclass('org.jnius.NativeInvocationHandler')

But now, I get the following error:

python : JavaException: Class not found 'org/able/PythonBluetooth'

It seems like java classes aren't being imported, any ideas?

Full log:

python : Exception in thread Thread-1: python : Traceback (most recent call last): python : File "/home/roberto/Programacion/Python/2019/myapp/myapp_03/.buildozer/android/platform/build/build/other_builds/python2/armeabi-v7andk_target_21/python2/Lib/threading.py", line 801, in bootstrap_inner python : File "/home/roberto/Programacion/Python/2019/myapp/myapp_03/.buildozer/android/platform/build/build/python-installs/myapp/jnius/init.py", line 54, in jnius_thread_hook python : File "/home/roberto/Programacion/Python/2019/myapp/myapp_03/.buildozer/android/platform/build/build/other_builds/python2/armeabi-v7andk_target_21/python2/Lib/threading.py", line 754, in run python : File "/home/roberto/Programacion/Python/2019/myapp/myapp_03/.buildozer/android/app/main.py", line 206, in finddoor python : File "/home/roberto/Programacion/Python/2019/myapp/myapp_03/.buildozer/android/platform/build/build/python-installs/myapp/able/dispatcher.py", line 30, in init python : File "/home/roberto/Programacion/Python/2019/myapp/myapp_03/.buildozer/android/platform/build/build/python-installs/myapp/able/android/dispatcher.py", line 19, in _set_ble_interface python : File "/home/roberto/Programacion/Python/2019/myapp/myapp_03/.buildozer/android/platform/build/build/python-installs/myapp/able/android/jni.py", line 12, in init python : File "jnius/jnius_proxy.pxi", line 28, in jnius.jnius.PythonJavaClass.init__ (jnius/jnius.c:33119) python : File "jnius/jnius_proxy.pxi", line 34, in jnius.jnius.PythonJavaClass._init_j_self_ptr (jnius/jnius.c:33254) python : File "jnius/jnius_proxy.pxi", line 168, in jnius.jnius.create_proxy_instance (jnius/jnius.c:35785) python : File "jnius/jnius_export_func.pxi", line 26, in jnius.jnius.find_javaclass (jnius/jnius.c:17877) python : JavaException: Class not found 'org/able/PythonBluetooth'

RoberWare commented 5 years ago

Clarification: I'm using the BLE class from the example.

b3b commented 5 years ago

@RoberWare It will be more safe to initialize BLE class from the main thread, for example using the run_on_ui_thread decorator, like it is done here: https://github.com/b3b/drone-roll/blob/cce5c10cf358af4362fecbe5c3a46cc340de247a/main.py#L41

Does it works in your case?

RoberWare commented 5 years ago

Solved it, thanks. But now I get the same issue as #2 when start_scan is called. Any clue?

b3b commented 5 years ago

@RoberWare Something wrong with BLE initialization. Probably, BluetoothDispatcher was sublcassed and BluetoothDispatcher.__init__() was not called from a new class, like:

from able import BluetoothDispatcher

class MyBLE(BluetoothDispatcher):

  def __init__(self):
     # Should call:
     # super(MyBLE, self).__init__()
     #...
RoberWare commented 5 years ago

Of course!. What a silly mistake! Sorry for the inconvenience. This solves #2 too.