chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
748 stars 127 forks source link

NoClassDefFoundError on static_proxy class #1161

Closed IPS-brentm closed 2 weeks ago

IPS-brentm commented 1 month ago

Python version 3.10, BeeWare (briefcase) v0.3.17

I am evaluating BeeWare by creating a basic Bluetooth LE scan app for Android. I am trying to define a scanner callback function that I can use to catch the responses from the Android scanner object, but keep getting a NoClassDefFoundError. I have modeled a static_proxy after the Chaquopy examples and test code, but I cannot seem to define it correctly. The code that I am using is defined below along with a subset of the traceback errors.


from java import Override, static_proxy, jvoid, jint

from android.bluetooth.le import ScanCallback, ScanResult
from android.util import Log

class BleIntf_android_ScanCallback(static_proxy(ScanCallback)):    
    @Override(jvoid, [jint, ScanResult])
    def onScanResult(self, type, result):
        Log.d("BleScan", str(result))
E/AndroidRuntime:       at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime:       at android.os.Looper.loopOnce(Looper.java:226)
E/AndroidRuntime:       at android.os.Looper.loop(Looper.java:313)
E/AndroidRuntime:       at android.app.ActivityThread.main(ActivityThread.java:8757)
E/AndroidRuntime:       at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime:       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
E/AndroidRuntime:       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
E/AndroidRuntime: Caused by: com.chaquo.python.PyException: java.lang.NoClassDefFoundError: blescantool.BleIntf_android_proxies.BleIntf_android_ScanCallback
E/AndroidRuntime:       at com.chaquo.python.PyObject.callAttr(PyObject.java:225)
E/AndroidRuntime:       at org.beeware.android.MainActivity.onCreate(MainActivity.java:85)
E/AndroidRuntime:       at android.app.Activity.performCreate(Activity.java:8591)
E/AndroidRuntime:       at android.app.Activity.performCreate(Activity.java:8570)
E/AndroidRuntime:       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384)
E/AndroidRuntime:       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150)
E/AndroidRuntime:       ... 12 more
E/AndroidRuntime: Caused by: java.lang.NoClassDefFoundError: blescantool.BleIntf_android_proxies.BleIntf_android_ScanCallback
E/AndroidRuntime:       at java.lang.Class.classForName(Native Method)
E/AndroidRuntime:       at java.lang.Class.forName(Class.java:536)
E/AndroidRuntime:       at <python>.java.chaquopy.CQPEnv.FindClass(env.pxi:63)
E/AndroidRuntime:       at <python>.java.chaquopy.StaticProxyClass.get_klass(proxy.pxi:119)
E/AndroidRuntime:       at <python>.java.chaquopy.ProxyClass.__new__(proxy.pxi:17)
E/AndroidRuntime:       at <python>.blescantool.BleIntf_android_proxies.<module>(BleIntf_android_proxies.py:9)
E/AndroidRuntime:       at <python>.java.chaquopy.import_override(import.pxi:26)
E/AndroidRuntime:       at <python>.blescantool.BleIntf_android.<module>(BleIntf_android.py:12)
E/AndroidRuntime:       at <python>.java.chaquopy.import_override(import.pxi:26)
E/AndroidRuntime:       at <python>.blescantool.BleIntf.<module>(BleIntf.py:8)
E/AndroidRuntime:       at <python>.java.chaquopy.import_override(import.pxi:26)
mhsmith commented 3 weeks ago

Have you listed the module in a staticProxy declaration in your build.gradle file?

If you have, and it still doesn't work, please post the build.gradle file, and let me know the path of the Python file within your project.

mhsmith commented 2 weeks ago

If this is still a problem, please post the information requested above, and I'll reopen the issue.