flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
11.5k stars 449 forks source link

flet==0.25.0.dev3526 apk "Android" error matplotlib "libjpeg.so" not found #4219

Closed InesaFitsner closed 2 weeks ago

InesaFitsner commented 1 month ago

Duplicate Check

Describe the bug

After building apk with Matplotlib package and running it on Android device simulator, error when trying to import matplotlib: dlopen failed: library "libjpeg.so" not found: needed by /data/data/com.flet.matplotlib_app/files/flet/python_site_packages/PIL/_imaging.cpython-312.so in namespace classloader-namespace

Code sample

Code ```python import flet as ft def main(page: ft.Page): page.title = "Flet libs test" def matplotlib_tests(e): def test_basic(): try: import matplotlib page.add(ft.Text("import matplotlib: OK")) import matplotlib.pyplot as plt from flet.matplotlib_chart import MatplotlibChart matplotlib.use("svg") fig, ax = plt.subplots() fruits = ["apple", "blueberry", "cherry", "orange"] counts = [40, 100, 30, 55] bar_labels = ["red", "blue", "_red", "orange"] bar_colors = ["tab:red", "tab:blue", "tab:red", "tab:orange"] ax.bar(fruits, counts, label=bar_labels, color=bar_colors) ax.set_ylabel("fruit supply") ax.set_title("Fruit supply by kind and color") ax.legend(title="Fruit color") page.add(MatplotlibChart(fig, expand=True)) plt.figure() plt.plot([1, 2]) bio = io.BytesIO() plt.savefig(bio, format="png") b = bio.getvalue() EXPECTED_LEN = 16782 assert len(b) > int(EXPECTED_LEN * 0.8) assert len(b) < int(EXPECTED_LEN * 1.2) assert b[:24] == ( b"\x89PNG\r\n\x1a\n" + b"\x00\x00\x00\rIHDR" # File header + b"\x00\x00\x02\x80" # Header chunk header + b"\x00\x00\x01\xe0" # Width 640 # Height 480 ) page.add(ft.Text("matplotlib: test_basic - OK")) except Exception as e: page.add( ft.Text(f"matplotlib: test_basic - error: {e}", selectable=True) ) test_basic() page.add( ft.SafeArea( ft.Column( [ ft.ElevatedButton( "Run Matplotlib tests", on_click=matplotlib_tests ), ] ) ) ) ft.app(main) ``` pyproject.toml ``` [project] name = "matplotlib_app" version = "1.0.0" description = "" authors = [{name = "Flet Developer", email = "your@email.com"}] dependencies = ["flet==0.25.0.dev3526", "matplotlib"] [tool.flet] android.adaptive_icon_background = "#ffffff" ```

To reproduce

  1. flet build apk
  2. install apk on android device
  3. click on "Run Matplotlib tests" button

Expected behavior

Expected to see MatplotlibChart

Screenshots / Videos

Captures [Upload media here]

Operating System

macOS

Operating system details

Sequoia 15

Flet version

flet==0.25.0.dev3526

Regression

No, it isn't

Suggestions

No response

Logs

Logs ```console [Paste your logs here] ```

Additional details

No response