Skip to content
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

apk package runs ok but aab bundle flet 0.25.2 with the same structure crashes #4655

Open
1 task done
filiperochalopes opened this issue Jan 6, 2025 · 8 comments
Open
1 task done
Labels
packaging Related to app packaging

Comments

@filiperochalopes
Copy link

Duplicate Check

Describe the bug

I've been working in this bug for a week and searching for solve. When I build an apk, download to the phone and execute it works fine but when I build to aab and download through (internal test) Play Store and open the app it breaks in a blank screen with this (if you want to test it just send our gmail so I can insert in the internal testers list)

Using flet 0.25.2 flutter 3.24.2 and python 3.11.6 @ndonkoHenri

Code sample

Code

pyproject.toml

[project]
name = "drcalc"
description = "Calculadora para unidade de terapia intensiva"
version = "0.1.0"
# fluter 3.24.2
# flet 0.24.1
requires-python = ">=3.11,<3.12" # 3.11.6
authors = [
  {name = "Filipe Lopes", email = "[email protected]"}
]
readme = "README.md"
license = {text = "MIT License"}

[tool.flet]
org = "com.flet" # --org
product = "drcalc - Drug Calculator" # --product
company = "FILIPE LOPES MED BR LTDA" # --company
copyright = "Copyright (C) 2024 by Filipe Lopes" # --copyright

[tool.flet.android.signing]
# store and key passwords can be passed with `--android-signing-key-store-password`
# and `--android-signing-key-password` options or
# FLET_ANDROID_SIGNING_KEY_STORE_PASSWORD
# and FLET_ANDROID_SIGNING_KEY_PASSWORD environment variables.
key_store = "/Users/filipelopes/Desktop/Web/Progress/icalc/keystore.jks" # --android-signing-key-store
key_alias = "upload"

[tool.flet.splash]
android = false

[tool.flet.android.permission] # --android-permissions
"android.permission.INTERNET" = true

[tool.flet.android.feature] # --android-features
"android.hardware.camera" = false

requirements.txt

flet==0.25.2
gql==3.5.0
requests==2.32.3
requests-toolbelt==1.0.0
Pint==0.24.4

main.py

from gql import Client
from gql.transport.requests import RequestsHTTPTransport
from services.classes import Droga, Solucao, Q_
from services.queries import (
    q_substancias,
    q_diluicao_padrao_por_id,
    q_instituicoes
)
...

services/classes.py

import re

from pint import UnitRegistry

ureg = UnitRegistry()
Q_ = ureg.Quantity
ureg.load_definitions("./services/pint_units_pt_br.txt")

class Droga:
    def __init__(self, ...

To reproduce

  1. Download the package I wrote in the internal test available at https://play.google.com/apps/internaltest/4701557632548021360 (please send me your email from Google account)

Steps I've done to reproduce:

  1. Installed packages including Pint It's a 100% Python
  2. Create some classes in services/classes.py like:
import re

from pint import UnitRegistry

ureg = UnitRegistry()
Q_ = ureg.Quantity
ureg.load_definitions("./services/pint_units_pt_br.txt")

class Droga:
    def __init__(self, nome: str, concentracao:str, volume_ampola:str):
        self.nome = nome
        self.concentracao_ampola = Q_(concentracao)
        self.volume_ampola = Q_(volume_ampola)

    def consideracoes(self):
        return """
            Considerando que a concentração da ampola de {} é {:~},
            Considerando que estamos usando um volume de droga {} tem {:~}
            """.format(
            self.nome, self.concentracao_ampola, self.nome, self.volume_ampola
        )
...

but it breaks before class creation as the log says
3. Bundle it with signature flet build aab ... and send it to Play Store

Expected behavior

Runs as well as package build with flet build apk

Screenshots / Videos

Captures

fletbug

Operating System

macOS

Operating system details

15.1.1 (24B91) Sequoia

Flet version

0.25.2

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
[07:08:40] No additional Flutter dependencies!                                                                                    
[07:08:41] Created Flutter bootstrap project from gh:flet-dev/flet-build-template with ref 0.25.2 ✅                              
           Copying /Users/filipelopes/Desktop/Web/Progress/icalc/assets/icon.png to                                               
           /Users/filipelopes/Desktop/Web/Progress/icalc/build/flutter/images                                                     
           Customized app icons and splash images ✅                                                                              
           Run subprocess: ['/Users/filipelopes/Development/flutter/bin/dart', 'run', 'flutter_launcher_icons']                   
( ●    ) Generating app icons ⏳... 
Built flutter_launcher_icons:flutter_launcher_icons.
(    ● ) Generating app icons ⏳...   ════════════════════════════════════════════
     FLUTTER LAUNCHER ICONS (v0.14.2)                               
  ════════════════════════════════════════════
  
(   ●  ) Generating app icons ⏳... • Creating default icons Android
(  ●   ) Generating app icons ⏳... • Overwriting the default Android launcher icon with a new icon
( ●    ) Generating app icons ⏳... • Creating adaptive icons Android
(●     ) Generating app icons ⏳... • Updating colors.xml with color for adaptive icon background
( ●    ) Generating app icons ⏳... • Creating mipmap xml file Android
(  ●   ) Generating app icons ⏳... • Overwriting default iOS launcher icon with new icon
( ●    ) Generating app icons ⏳...done
( ●    ) Generating app icons ⏳...done
(    ● ) Generating app icons ⏳...done

✓ Successfully generated launcher icons
[07:08:44] Generated app icons ✅                                                                                                 
           Run subprocess: ['/Users/filipelopes/Development/flutter/bin/dart', 'run', 'flutter_native_splash:create']             
(  ●   ) Generating splash screens ⏳... 
Built flutter_native_splash:create.
( ●    ) Generating splash screens ⏳... [iOS] Creating  images
(   ●  ) Generating splash screens ⏳... [iOS] Creating dark mode  images
(  ●   ) Generating splash screens ⏳... [iOS] Updating ios/Runner/Info.plist for status bar hidden/visible
[Web] Creating images
(   ●  ) Generating splash screens ⏳... [Web] Creating images
(●     ) Generating splash screens ⏳... [Web] Creating background images
[Web] Creating CSS
( ●    ) Generating splash screens ⏳... [Web] Updating index.html

✅ Native splash complete.
Now go finish building something awesome! 💪 You rock! 🤘🤩
Like the package? Please give it a 👍 here: https://pub.dev/packages/flutter_native_splash

[07:08:47] Generated splash screens ✅                                                                                            
           Run subprocess: ['/Users/filipelopes/Development/flutter/bin/dart', 'run', 'serious_python:main', 'package',           
           '/Users/filipelopes/Desktop/Web/Progress/icalc', '--platform', 'Android', '--requirements',                            
           '-r,/Users/filipelopes/Desktop/Web/Progress/icalc/requirements.txt', '--exclude', 'build', '--cleanup']                
(   ●  ) Packaging Python app ⏳... 
Built serious_python:main.
( ●    ) Packaging Python app ⏳... Running package command
Extra PyPi indexes: [https://pypi.flet.dev]
Created temp directory: /var/folders/fx/w21jbvn95gj7qtcjfvzm3zhr0000gn/T/serious_python_tempH95Mgn
Copying Python app from /Users/filipelopes/Desktop/Web/Progress/icalc to a temp directory
(  ●   ) Packaging Python app ⏳... Cleanup app
Configured Android/arm64-v8a platform with sitecustomize.py
(  ●   ) Packaging Python app ⏳... Installing [-r, /Users/filipelopes/Desktop/Web/Progress/icalc/requirements.txt] with pip command to /Users/filipelopes/Desktop/Web/Progress/icalc/build/site-packages/arm64-v8a
(   ●  ) Packaging Python app ⏳... Cleanup installed packages
(    ● ) Packaging Python app ⏳... Configured Android/armeabi-v7a platform with sitecustomize.py
(    ● ) Packaging Python app ⏳... Installing [-r, /Users/filipelopes/Desktop/Web/Progress/icalc/requirements.txt] with pip command to /Users/filipelopes/Desktop/Web/Progress/icalc/build/site-packages/armeabi-v7a
( ●    ) Packaging Python app ⏳... Cleanup installed packages
(   ●  ) Packaging Python app ⏳... Configured Android/x86_64 platform with sitecustomize.py
Installing [-r, /Users/filipelopes/Desktop/Web/Progress/icalc/requirements.txt] with pip command to /Users/filipelopes/Desktop/Web/Progress/icalc/build/site-packages/x86_64
( ●    ) Packaging Python app ⏳... Cleanup installed packages
(   ●  ) Packaging Python app ⏳... Configured Android/x86 platform with sitecustomize.py
Installing [-r, /Users/filipelopes/Desktop/Web/Progress/icalc/requirements.txt] with pip command to /Users/filipelopes/Desktop/Web/Progress/icalc/build/site-packages/x86
(    ● ) Packaging Python app ⏳... Cleanup installed packages
(   ●  ) Packaging Python app ⏳... Creating app archive at /Users/filipelopes/Desktop/Web/Progress/icalc/build/flutter/app/app.zip from a temp directory
(  ●   ) Packaging Python app ⏳... Writing app archive hash to /Users/filipelopes/Desktop/Web/Progress/icalc/build/flutter/app/app.zip.hash
Deleting temp directory
[07:09:29] Packaged Python app ✅                                                                                                 
           Run subprocess: ['/Users/filipelopes/Development/flutter/bin/flutter', 'build', 'appbundle', '--build-number', '3',    
           '--build-name', '0.1.0']                                                                                               
(     ●) Building .aab bundle for Android ⏳... 
┌─────────────────────────────────────────────────────────┐
│ A new version of Flutter is available!                  │
│                                                         │
│ To update to the latest version, run "flutter upgrade". │
└─────────────────────────────────────────────────────────┘
(  ●   ) Building .aab bundle for Android ⏳... 
Font asset "CupertinoIcons.ttf" was tree-shaken, reducing it from 257628 to 209160 bytes (18.8% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 1261080 bytes (23.3% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
(  ●   ) Building .aab bundle for Androi   42,0s
✓ Built build/app/outputs/bundle/release/app-release.aab (69.4MB)
[07:10:15] Built .aab bundle for Android ✅                                                                                       
           Copying build output from:                                                                                             
           /Users/filipelopes/Desktop/Web/Progress/icalc/build/flutter/build/app/outputs/bundle/release/*                         
           Copied build to build/aab directory ✅                                                                                 
           Successfully built your .aab bundle for Android! 🥳 Find it in build/aab directory. 📁 
Traceback (most recent call last):
  File "<string>", line 47, in <module>
  File "<frozen runpy>", line 229, in run_module
  File "<frozen runpy>", line 88, in _run_code
  File "/data/user/0/com.flet.drcalc/files/flet/app/main.py", line 4, in <module>
    from services.classes import Droga, Solucao, Q_
  File "/data/user/0/com.flet.drcalc/files/flet/app/services/classes.py", line 3, in <module>
    from pint import UnitRegistry
  File "/data/user/0/com.flet.drcalc/files/flet/python_site_packages/pint/_init_.py", line 18, in <module>
    from .delegates.formatter._format_helpers import formatter
  File "/data/user/0/com.flet.drcalc/files/flet/python_site_packages/pint/delegates/_init_.py", line 12, in <module>
    from . import txt_defparser
  File "/data/user/0/com.flet.drcalc/files/flet/python_site_packages/pint/delegates/txt_defparser/_init_.py", line 12, in <module>
    from .defparser import DefParser
  File "/data/user/0/com.flet.drcalc/files/flet/python_site_packages/pint/delegates/txt_defparser/defparser.py", line 10, in <module>
    from . import block, common, context, defaults, group, plain, system
  File "/data/user/0/com.flet.drcalc/files/flet/python_site_packages/pint/delegates/txt_defparser/common.py", line 23, in <module>
    @dataclass(frozen=True)
     ^^^^^^^^^^^^^^^^^^^^^^
  File "./dataclasses.py", line 1265, in wrap
  File "./dataclasses.py", line 1029, in _process_class
TypeError: cannot inherit frozen dataclass from a non-frozen one

Additional details

No response

@FeodorFitsner
Copy link
Contributor

So, just to confirm, it gives that TypeError: cannot inherit frozen dataclass from a non-frozen one Python error when deployed as .aab? Do you think I can reproduce it by making a simple app with @dataclass(frozen=True)?

@FeodorFitsner
Copy link
Contributor

Studied the problem a bit. I'm not sure how come APK works, but AAB doesn't, but the only explanation could be the difference in pint of flexparser versions. There was an issue in pint itself: hgrecco/pint#1969 - incorrect inheritance of frozen/non-frozen dataclasses is treated as an error in the latest versions of Python. Unpack the contents of .aab and then pythonsitepackages.so and see what versions of pint and flexparser you have (this was a fix in pint). Hope that helps.

@filiperochalopes
Copy link
Author

So, just to confirm, it gives that TypeError: cannot inherit frozen dataclass from a non-frozen one Python error when deployed as .aab? Do you think I can reproduce it by making a simple app with @dataclass(frozen=True)?

I don't know. I did not try it. When we come to the matter of uploading the app to the Google Play Store so we can test the aab file it can be hard to debug and create a test app in the platform.

@filiperochalopes
Copy link
Author

Studied the problem a bit. I'm not sure how come APK works, but AAB doesn't, but the only explanation could be the difference in pint of flexparser versions. There was an issue in pint itself: hgrecco/pint#1969 - incorrect inheritance of frozen/non-frozen dataclasses is treated as an error in the latest versions of Python. Unpack the contents of .aab and then pythonsitepackages.so and see what versions of pint and flexparser you have (this was a fix in pint). Hope that helps.

I will try it out and let you know

@filiperochalopes
Copy link
Author

@FeodorFitsner I ran a bunch of builds with many different envs multiple times. As I read in the Pint issues apparently It was fixed in Pint==0.24.4 and that is the version I am using. And the bug is just for Python 3.13 and I was using 3.11.6 and 3.12 but the bug information looks like a lot so I ran with Python 3.13 version. I removed almost all the code to test and when I introduced this line:

from pint import UnitRegistry

The bug shows again. But it's not the problem. The problem with flet are:
"Why not on apk?"
"Why not on flet run?"

Just when I build aab it happens. There are some extra packages involved that can conflict with another version of flexparser. I also unpack the aab and /build/app.zip show the same packages. I am using flexparser==0.4

Here the link to download apk https://files.filipelopes.me/share/PFgamCY4 It's working fine. Non sense

@ndonkoHenri ndonkoHenri added the packaging Related to app packaging label Jan 7, 2025
@FeodorFitsner
Copy link
Contributor

Side note: You are embedding keystore.jks into .apk. Remove it from there and re-generate keys.

@FeodorFitsner
Copy link
Contributor

OK, .apk contains pint 0.24.4 and flexparser 0.4. Check what's inside .aab. There couldn't be a miracle.

image

@filiperochalopes
Copy link
Author

Side note: You are embedding keystore.jks into .apk. Remove it from there and re-generate keys.

🥲 Thank you! LOL I did not realize it until now. Is there some .gitignore thing for flet to list files to ignore on packaging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packaging Related to app packaging
Projects
None yet
Development

No branches or pull requests

3 participants