Skip to content

How to bundle native shared libraries (.so) in Android APK builds using flet build? #6500

@Fourkillah

Description

@Fourkillah

I am developing a professional reptile management system and I'm facing a critical issue with bundling native Android libraries (.so files) required by camera modules. On several devices (e.g., Samsung S-series), the app crashes when attempting to open the camera because a required library is missing from the APK's lib directory.

Error Logs (Logcat):
E com.appname: Unable to open libpenguin.so: dlopen failed: library "libpenguin.so" not found.

Current Setup:
Framework: Flet 0.85.1
Dependency: flet-camera==0.85.1
Platform: Android (Target SDK 34)
Build Command: flet build apk --android-abi arm64-v8a
What I have tried:Placing the .so files in android/app/src/main/jniLibs/arm64-v8a/ within the project root. Adding the files to the assets/ folder in various structures (e.g., assets/lib/...). Injecting the files manually into the generated APK via ZIP. This works and resolves the crash, but it is not a sustainable or automated solution for production. Problem:It appears that flet build (and the underlying serious_python logic) ignores the local android directory or custom jniLibs paths when generating the temporary build template.Question:What is the officially recommended way to ensure that native shared libraries are correctly bundled into the /lib// directory of the final APK? Is there a specific configuration in pyproject.toml or a Gradle hook that I should use to make these libraries persist during the automated build process?Relevant pyproject.toml section:

[tool.flet.android]
package_name = "de.appname"
product_name = "APPNAME"
build_args = "--android-abi arm64-v8a"

[tool.flet.android.feature]
"android.hardware.camera" = true
"android.hardware.camera.level.full" = true

Thank you for your help! This project is vital for the community-driven management of Python regius breeding, and solving this native dependency issue is the last hurdle for our rollout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions