Skip to content

Local Images Not Rendering in Android App using Flet 0.27.6 #5198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
mlc1503 opened this issue Apr 9, 2025 · 2 comments
Closed
1 task done

Local Images Not Rendering in Android App using Flet 0.27.6 #5198

mlc1503 opened this issue Apr 9, 2025 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@mlc1503
Copy link

mlc1503 commented Apr 9, 2025

Duplicate Check

Describe the bug

Hello.
I'm using Flet 0.27.6 to build an android app.

Local images/assets render on Windows app execution, but do not in Android execution via Flet android app.

logging library shows the image source path is not correct. Seems like it adds a src/main.py prefix to the path, instead of the specified or default assets folder path.

There has been this exact same issue with Flet v0.22.1, which was closed because the Flet app had to be updated.

The Flet android client app is v2.0.1, with SDK v0.27.6 and Python version v3.12.9

File structure:

/testBugApp
 /src
  /assets
   fgc.jpeg
  main.py

Code sample

Code
import flet as ft
import logging
logging.basicConfig(level=logging.DEBUG)
logging.getLogger("flet_core").setLevel(logging.INFO)


def main(page: ft.Page):
    
    page.add(
        ft.Image(src=f"fgc.jpeg", width= 200, height= 300),
        ft.Text("An image should be displayed here...")
    )


ft.app(main, assets_dir="assets")

To reproduce

  1. Run the code sample with flet run -r -d --android
  2. Go to the Flet Android app and connect to the url the flet run command provided

Expected behavior

fgc.jpeg image should be rendered in android execution.

Screenshots / Videos

Captures
  • Windows execution (for comparison):
    Image

  • Android execution:
    Image

  • Flet App version:
    Image

  • Android version
    Image

Operating System

Windows

Operating system details

Windows 11 Home 24H2 using VSCode, running app using flet app from play store

Flet version

0.27.6

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
Scan QR code above with Camera app.
INFO:     192.168.1.129:49296 - "GET /src/main.pyfgc.jpeg HTTP/1.1" 404 Not Found
DEBUG:    = connection is CONNECTING
C:\Users\manel\COSAS\2DAM_PRES\TFG\testFlet\.venv\Lib\site-packages\websockets\legacy\server.py:1178: DeprecationWarning: remove second argument of ws_handler
  warnings.warn("remove second argument of ws_handler", DeprecationWarning)
DEBUG:    < GET /src/main.py/ws HTTP/1.1
DEBUG:    < user-agent: Dart/3.6 (dart:io)
DEBUG:    < connection: Upgrade
DEBUG:    < cache-control: no-cache
DEBUG:    < accept-encoding: gzip
DEBUG:    < sec-websocket-version: 13
DEBUG:    < host: 192.168.1.128:8551
DEBUG:    < sec-websocket-extensions: permessage-deflate; client_max_window_bits
DEBUG:    < sec-websocket-key: 55vWDieO5g1SsWlCqQHRHg==
DEBUG:    < upgrade: websocket
DEBUG:flet:Creating new PubSubHub instance
INFO:flet_web.fastapi:New FletApp: lPpvFaKS
DEBUG:flet:Creating new PubSubHub instance
INFO:     ('192.168.1.129', 58470) - "WebSocket /src/main.py/ws" [accepted]
DEBUG:    > HTTP/1.1 101 Switching Protocols
DEBUG:    > Upgrade: websocket
DEBUG:    > Connection: Upgrade
DEBUG:    > Sec-WebSocket-Accept: nDygDLWV/t7ycAZiOQixhWjlDFI=
DEBUG:    > Sec-WebSocket-Extensions: permessage-deflate
DEBUG:    > date: Wed, 09 Apr 2025 10:29:26 GMT
DEBUG:    > server: uvicorn
INFO:     connection open
DEBUG:    = connection is OPEN
DEBUG:    < TEXT '{"action":"registerWebClient","payload":{"pageN...d":"2IsftDVghDBo9JwY"}}' [575 bytes]
DEBUG:flet_web.fastapi:_on_message: {"action":"registerWebClient","payload":{"pageName":"src/main.py","pageRoute":"/","pageWidth":"360.0","pageHeight":"752.0","windowWidth":"","windowHeight":"","windowTop":"","windowLeft":"","isPWA":"false","isWeb":"false","isDebug":"false","platform":"android","platformBrightness":"dark","media":"{\"padding\":{\"top\":26.666666666666668,\"right\":0.0,\"bottom\":0.0,\"left\":0.0},\"view_padding\":{\"top\":26.666666666666668,\"right\":0.0,\"bottom\":0.0,\"left\":0.0},\"view_insets\":{\"top\":0.0,\"right\":0.0,\"bottom\":0.0,\"left\":0.0}}","sessionId":"2IsftDVghDBo9JwY"}}
INFO:flet_web.fastapi:New session created (1 total): src/main.py_r1LGNXGFK4jOeMmS_9c5e04b522477d15912664b6e50384162e9c4263
DEBUG:flet_web.fastapi:__send: {"action":"registerWebClient","payload":{"session":{"id":"r1LGNXGFK4jOeMmS","controls":{"page":{"i":"page","t":"page","p":"","c":[],"clientip":"192.168.1.129","clientuseragent":"Dart/3.6 (dart:io)","debug":"false","height":"752.0","media":"{\"padding\":{\"top\":26.666666666666668,\"right\":0.0,\"bottom\":0.0,\"left\":0.0},\"view_padding\":{\"top\":26.666666666666668,\"right\":0.0,\"bottom\":0.0,\"left\":0.0},\"view_insets\":{\"top\":0.0,\"right\":0.0,\"bottom\":0.0,\"left\":0.0}}","platform":"android","platformbrightness":"dark","pwa":"false","route":"/","web":"false","width":"360.0","windowheight":"","windowleft":"","windowtop":"","windowwidth":""}}},"error":"","appInactive":false}}
INFO:flet_web.fastapi:Start session: r1LGNXGFK4jOeMmS
DEBUG:flet:_process_command: add [] {'to': 'page', 'at': '0'}
DEBUG:    > TEXT '{"action":"registerWebClient","payload":{"sessi...","appInactive":false}}' [692 bytes]
DEBUG:flet:_process_command: add [] {'to': 'page', 'at': '1'}
DEBUG:flet_web.fastapi:__send: {"action":"pageControlsBatch","payload":[{"action":"addPageControls","payload":{"controls":[{"t":"view","i":"_1","p":"page","c":["_2","_3"],"at":"0"},{"t":"image","i":"_2","p":"_1","c":[],"height":"300","src":"fgc.jpeg","width":"200"},{"t":"text","i":"_3","p":"_1","c":[],"value":"An image should be displayed here..."}],"trimIDs":[]}},{"action":"addPageControls","payload":{"controls":[{"t":"offstage","i":"_4","p":"page","c":[],"at":"1"}],"trimIDs":[]}}]}
DEBUG:    > TEXT '{"action":"pageControlsBatch","payload":[{"acti...:"1"}],"trimIDs":[]}}]}' [457 bytes]
DEBUG:    < TEXT '{"action":"pageEventFromWeb","payload":{"eventT..."eventData":"restart"}}' [125 bytes]
DEBUG:    < TEXT '{"action":"pageEventFromWeb","payload":{"eventT...e","eventData":"show"}}' [122 bytes]
DEBUG:    < TEXT '{"action":"pageEventFromWeb","payload":{"eventT...,"eventData":"resume"}}' [124 bytes]
DEBUG:flet_web.fastapi:_on_message: {"action":"pageEventFromWeb","payload":{"eventTarget":"page","eventName":"app_lifecycle_state_change","eventData":"restart"}}       
DEBUG:flet_web.fastapi:_on_message: {"action":"pageEventFromWeb","payload":{"eventTarget":"page","eventName":"app_lifecycle_state_change","eventData":"show"}}
DEBUG:flet_web.fastapi:_on_message: {"action":"pageEventFromWeb","payload":{"eventTarget":"page","eventName":"app_lifecycle_state_change","eventData":"resume"}}        
DEBUG:flet:page.on_event_async: page app_lifecycle_state_change restart
DEBUG:flet:page.on_event_async: page app_lifecycle_state_change show
DEBUG:flet:page.on_event_async: page app_lifecycle_state_change resume
INFO:     192.168.1.129:49296 - "GET /src/main.pyfgc.jpeg HTTP/1.1" 404 Not Found
DEBUG:    < TEXT '{"action":"pageEventFromWeb","payload":{"eventT...eventData":"inactive"}}' [126 bytes]
DEBUG:flet_web.fastapi:_on_message: {"action":"pageEventFromWeb","payload":{"eventTarget":"page","eventName":"app_lifecycle_state_change","eventData":"inactive"}}
DEBUG:flet:page.on_event_async: page app_lifecycle_state_change inactive
DEBUG:    < TEXT '{"action":"pageEventFromWeb","payload":{"eventT...e","eventData":"hide"}}' [122 bytes]
DEBUG:flet_web.fastapi:_on_message: {"action":"pageEventFromWeb","payload":{"eventTarget":"page","eventName":"app_lifecycle_state_change","eventData":"hide"}}
DEBUG:    < TEXT '{"action":"pageEventFromWeb","payload":{"eventT...","eventData":"pause"}}' [123 bytes]
DEBUG:flet:page.on_event_async: page app_lifecycle_state_change hide
DEBUG:flet_web.fastapi:_on_message: {"action":"pageEventFromWeb","payload":{"eventTarget":"page","eventName":"app_lifecycle_state_change","eventData":"pause"}}
DEBUG:flet:page.on_event_async: page app_lifecycle_state_change pause
DEBUG:    < TEXT '{"action":"pageEventFromWeb","payload":{"eventT..."eventData":"restart"}}' [125 bytes]
DEBUG:flet_web.fastapi:_on_message: {"action":"pageEventFromWeb","payload":{"eventTarget":"page","eventName":"app_lifecycle_state_change","eventData":"restart"}}
DEBUG:    < TEXT '{"action":"pageEventFromWeb","payload":{"eventT...e","eventData":"show"}}' [122 bytes]
DEBUG:    < TEXT '{"action":"pageEventFromWeb","payload":{"eventT...,"eventData":"resume"}}' [124 bytes]
DEBUG:flet:page.on_event_async: page app_lifecycle_state_change restart
DEBUG:flet_web.fastapi:_on_message: {"action":"pageEventFromWeb","payload":{"eventTarget":"page","eventName":"app_lifecycle_state_change","eventData":"show"}}
DEBUG:flet_web.fastapi:_on_message: {"action":"pageEventFromWeb","payload":{"eventTarget":"page","eventName":"app_lifecycle_state_change","eventData":"resume"}}        
DEBUG:flet:page.on_event_async: page app_lifecycle_state_change show
DEBUG:flet:page.on_event_async: page app_lifecycle_state_change resume
INFO:     Shutting down
DEBUG:    ! failing connection with code 1012
DEBUG:    = connection is CLOSING
DEBUG:    > CLOSE 1012 (service restart) [2 bytes]
DEBUG:    x half-closing TCP connection
DEBUG:    = connection is CLOSED
INFO:flet_web.fastapi:Session disconnected: src/main.py_r1LGNXGFK4jOeMmS_9c5e04b522477d15912664b6e50384162e9c4263
DEBUG:flet:page.on_event_async: page disconnect
INFO:     connection closed
INFO:     Waiting for application shutdown.
INFO:flet_web.fastapi:Shutting down Flet App Manager
INFO:     Application shutdown complete.
INFO:     Finished server process [27588]
DEBUG:flet:Gracefully terminating Flet app...
INFO:flet:Flet app has started...
INFO:flet_web.fastapi:Closing Flet web server...
INFO:     Shutting down
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.

I manually shut off the execution once the Android app connected to the run and checked it didn't render the image.

Line 2: INFO: 192.168.1.129:49296 - "GET /src/main.pyfgc.jpeg HTTP/1.1" 404 Not Found shows the GET request path to the image is malformed.

Additional details

No response

@HenrikSydow
Copy link

Hi, exactly the same for me. Also happens when building, installing and then running the apk-file on my Android device. So this seems to not be restricted to the flet Android app / development.

@boris342
Copy link

boris342 commented May 12, 2025

I have the same problem on version 0.28.2 and iOS. In the Flet app on iOS, this displays nothing. In the browser, the image appears but the quality is much lower than when I try it through vs code. This problem is showstopper for developing mobile offline apps.

import flet as ft

def main(page: ft.Page):
    page.add(
        ft.Image(src="images/image2.png", width=30, height=30)
    )

ft.app(main, assets_dir="assets")

@FeodorFitsner FeodorFitsner self-assigned this May 12, 2025
@FeodorFitsner FeodorFitsner added this to the Flet v0.28.3 milestone May 14, 2025
@FeodorFitsner FeodorFitsner added the bug Something isn't working label May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants