beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.47k stars 350 forks source link

Porcupine can't find module #1889

Closed w0r1d-d43m0n closed 5 days ago

w0r1d-d43m0n commented 5 days ago

Describe the bug

When trying to use pvporcupine's wake word, briefcase fails with ←[31mE/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vocalix.vocalixai/org.beeware.android.MainActivity}: com.chaquo.python.PyException: OSError: Couldn't find Porcupine's dynamic library at '/data/data/com.vocalix.vocalixai/files/chaquopy/AssetFinder/requirements/pvporcupine/lib/linux/x86_64/libpv_porcupine.so'.←[0m.

Steps to reproduce

  1. pvporcupine in pyproject.toml/requires
  2. async loop checks for wake word constantly
  3. can't find library

Expected behavior

When porcupine detects wake word, code changes Label() to "active!" and then back to "inactive" after 3 seconds.

Screenshots

No response

Environment

Logs

[vocalixai] Following device log output (type CTRL-C to stop log)...
===========================================================================
--------- beginning of main
←[32mI/calix.vocalixa: Late-enabling -Xcheck:jni←[0m
←[33mW/calix.vocalixa: Unexpected CPU variant for X86 using defaults: x86_64←[0m
←[34mD/CompatibilityChangeReporter: Compat change id reported: 171979766; UID 10105; state: ENABLED←[0m
←[39mV/GraphicsEnvironment: ANGLE Developer option for 'com.vocalix.vocalixai' set to: 'default'←[0m
←[39mV/GraphicsEnvironment: Neither updatable production driver nor prerelease driver is supported.←[0m
←[34mD/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true←[0m
←[34mD/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true←[0m
←[34mD/libEGL  : loaded /vendor/lib64/egl/libEGL_emulation.so←[0m
←[34mD/libEGL  : loaded /vendor/lib64/egl/libGLESv1_CM_emulation.so←[0m
←[34mD/libEGL  : loaded /vendor/lib64/egl/libGLESv2_emulation.so←[0m
←[34mD/AppCompatDelegate: Checking for metadata for AppLocalesMetadataHolderService : Service not found←[0m
←[34mD/MainActivity: onCreate() start←[0m
←[33mW/calix.vocalixa: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (unsupported, reflection, allowed)←[0m
←[33mW/calix.vocalixa: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (unsupported, reflection, allowed)←[0m
←[34mD/MainActivity: Starting Python←[0m
←[33mW/native.stderr: Could not find platform independent libraries <prefix>←[0m
←[33mW/native.stderr: Could not find platform dependent libraries <exec_prefix>←[0m
←[33mW/native.stderr: Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:664): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/bootstrap-native/x86_64/zlib.so" dev="dm-5" ino=123377 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:665): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/bootstrap-native/x86_64/java/chaquopy.so" dev="dm-5" ino=123366 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:666): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/bootstrap-native/x86_64/_ctypes.so" dev="dm-5" ino=123370 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:667): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/bootstrap-native/x86_64/_struct.so" dev="dm-5" ino=123363 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:668): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/bootstrap-native/x86_64/_bz2.so" dev="dm-5" ino=123371 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:669): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/bootstrap-native/x86_64/_lzma.so" dev="dm-5" ino=123373 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:670): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/bootstrap-native/x86_64/math.so" dev="dm-5" ino=123368 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:671): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/bootstrap-native/x86_64/_datetime.so" dev="dm-5" ino=123376 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[33mW/asset   : seek out of range: want -20, end=22←[0m
←[34mD/MainActivity: Running main module vocalixai←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:682): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/AssetFinder/stdlib-x86_64/_ssl.so" dev="dm-5" ino=123407 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:683): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/AssetFinder/stdlib-x86_64/_contextvars.so" dev="dm-5" ino=123408 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:684): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/AssetFinder/stdlib-x86_64/_asyncio.so" dev="dm-5" ino=123409 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:685): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/AssetFinder/stdlib-x86_64/_csv.so" dev="dm-5" ino=123410 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[33mW/calix.vocalixai: type=1400 audit(0.0:686): avc: granted { execute } for path="/data/data/com.vocalix.vocalixai/files/chaquopy/AssetFinder/stdlib-x86_64/_decimal.so" dev="dm-5" ino=123415 scontext=u:r:untrusted_app:s0:c105,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c105,c256,c512,c768 tclass=file app=com.vocalix.vocalixai←[0m
←[34mD/AndroidRuntime: Shutting down VM←[0m
--------- beginning of crash
←[31mE/AndroidRuntime: FATAL EXCEPTION: main←[0m
←[31mE/AndroidRuntime: Process: com.vocalix.vocalixai, PID: 30620←[0m
←[31mE/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vocalix.vocalixai/org.beeware.android.MainActivity}: com.chaquo.python.PyException: OSError: Couldn't find Porcupine's dynamic library at '/data/data/com.vocalix.vocalixai/files/chaquopy/AssetFinder/requirements/pvporcupine/lib/linux/x86_64/libpv_porcupine.so'.←[0m
←[31mE/AndroidRuntime:   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3635)←[0m
←[31mE/AndroidRuntime:   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)←[0m
←[31mE/AndroidRuntime:   at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)←[0m
←[31mE/AndroidRuntime:   at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)←[0m
←[31mE/AndroidRuntime:   at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)←[0m
←[31mE/AndroidRuntime:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)←[0m
←[31mE/AndroidRuntime:   at android.os.Handler.dispatchMessage(Handler.java:106)←[0m
←[31mE/AndroidRuntime:   at android.os.Looper.loopOnce(Looper.java:201)←[0m
←[31mE/AndroidRuntime:   at android.os.Looper.loop(Looper.java:288)←[0m
←[31mE/AndroidRuntime:   at android.app.ActivityThread.main(ActivityThread.java:7839)←[0m
←[31mE/AndroidRuntime:   at java.lang.reflect.Method.invoke(Native Method)←[0m
←[31mE/AndroidRuntime:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)←[0m
←[31mE/AndroidRuntime:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)←[0m
←[31mE/AndroidRuntime: Caused by: com.chaquo.python.PyException: OSError: Couldn't find Porcupine's dynamic library at '/data/data/com.vocalix.vocalixai/files/chaquopy/AssetFinder/requirements/pvporcupine/lib/linux/x86_64/libpv_porcupine.so'.←[0m
←[31mE/AndroidRuntime:   at <python>.pvporcupine._porcupine.__init__(_porcupine.py:146)←[0m
←[31mE/AndroidRuntime:   at <python>.pvporcupine._factory.create(_factory.py:69)←[0m
←[31mE/AndroidRuntime:   at <python>.vocalixai.app.<module>(app.py:12)←[0m
←[31mE/AndroidRuntime:   at <python>.java.chaquopy.import_override(import.pxi:26)←[0m
←[31mE/AndroidRuntime:   at <python>.__main__.<module>(__main__.py:1)←[0m
←[31mE/AndroidRuntime:   at <python>.runpy._run_code(runpy.py:86)←[0m
←[31mE/AndroidRuntime:   at <python>.runpy._run_module_code(runpy.py:96)←[0m
←[31mE/AndroidRuntime:   at <python>.runpy.run_module(runpy.py:224)←[0m
←[31mE/AndroidRuntime:   at <python>.chaquopy_java.call(chaquopy_java.pyx:354)←[0m
←[31mE/AndroidRuntime:   at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrowsNative(chaquopy_java.pyx:326)←[0m
←[31mE/AndroidRuntime:   at com.chaquo.python.PyObject.callAttrThrowsNative(Native Method)←[0m
←[31mE/AndroidRuntime:   at com.chaquo.python.PyObject.callAttrThrows(PyObject.java:232)←[0m
←[31mE/AndroidRuntime:   at com.chaquo.python.PyObject.callAttr(PyObject.java:221)←[0m
←[31mE/AndroidRuntime:   at org.beeware.android.MainActivity.onCreate(MainActivity.java:85)←[0m
←[31mE/AndroidRuntime:   at android.app.Activity.performCreate(Activity.java:8051)←[0m
←[31mE/AndroidRuntime:   at android.app.Activity.performCreate(Activity.java:8031)←[0m
←[31mE/AndroidRuntime:   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)←[0m
←[31mE/AndroidRuntime:   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608)←[0m
←[31mE/AndroidRuntime:   ... 12 more←[0m
←[32mI/Process : Sending signal. PID: 30620 SIG: 9←[0m

Additional context

No response

rmartin16 commented 5 days ago

The package pvporcupine is providing a none-any wheel that contains compiled libraries for select platforms:

pvporcupine/
├── lib
│   ├── beaglebone
│   ├── common
│   ├── jetson
│   │   └── cortex-a57-aarch64
│   ├── linux
│   │   └── x86_64
│   ├── mac
│   │   ├── arm64
│   │   └── x86_64
│   ├── raspberry-pi
│   │   ├── arm11
│   │   ├── cortex-a53
│   │   ├── cortex-a53-aarch64
│   │   ├── cortex-a7
│   │   ├── cortex-a72
│   │   ├── cortex-a72-aarch64
│   │   ├── cortex-a76
│   │   └── cortex-a76-aarch64
│   └── windows
│       └── amd64
└── resources
    └── keyword_files
        ├── beaglebone
        ├── jetson
        ├── linux
        ├── mac
        ├── raspberry-pi
        └── windows

This almost certainly isn't how this wheel should be packaged since the wheel specification contains an extensive methodology for targeting specific platforms. That would avoid this entire situation since pip would tell you the package cannot be installed on an incompatible platform.

At any rate, this package would need to be built specifically for Android...or perhaps in the way this package is created, their library would need to be explicitly built for Android and they'd need logic to detect Android at runtime and load it.

I'll close this issue for now but feel free to post any follow up questions if you have here or in the discord. More general details about support for third-party libraries is here.

rmartin16 commented 5 days ago

As a follow up, since the porcupine project advertises compatibility with Android:

The project can be used with Android...but not via their package on PyPI. They have a sample Gradle project demonstrating its use....so, it may still be possible to use this with Briefcase by integrating the necessary configuration in to the Gradle project that Briefcase creates.

w0r1d-d43m0n commented 5 days ago

Ok thank you :)