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

Problem with the new pypi flet_permission_handler in 0.26.0. #4841

Open
1 task done
SIRGPrice opened this issue Feb 6, 2025 · 8 comments
Open
1 task done

Problem with the new pypi flet_permission_handler in 0.26.0. #4841

SIRGPrice opened this issue Feb 6, 2025 · 8 comments

Comments

@SIRGPrice
Copy link

SIRGPrice commented Feb 6, 2025

Duplicate Check

Describe the bug

I replicated the steps of the docs and 0.26.0 blog to install, copy-paste code (adapting to the context), run and make apk process.

No problem with anything until apk done, no error in any file or process until apk is done with success.

When I try the apk app in the phone, a white page opens and raises an error: No module named flet_permission_handler.

I think the problem is that once apk is done, flutter dart files related with flet_permission_handler dont recognice the imports and thats because once apk is done mi pubspec.yaml looks like this in the lines related with the flet_permission_handler:

dependencies:
cupertino_icons: ^1.0.6
flet_permission_handler:
path: C:\Users*user*\Desktop*appname*\build\flutter-packages\flet_permission_handler
flutter:
sdk: flutter
package_info_plus: ^8.0.2
path: ^1.9.0
path_provider: ^2.1.4
serious_python: 0.8.7
url_strategy: ^0.2.0
window_manager: ^0.4.3

The path of the module is a windows path that references the proyect folder where the flet_permission_handler dart files are located (the ones that give errors in their imports).

So when I try flet run --android it works perfectly in the play store flet app for emulation, because the app is really runing in my computer and it can access the path and open the android settings at the same time.

But when apk done the yaml cannot redirect to anywhere because in my mobile that path does not exist.

How can I solve it? Thanks.

Code sample

Code
.yaml ->

dependencies:
  cupertino_icons: ^1.0.6
  flet_permission_handler:
    path: C:\Users\x\Desktop\y\build\flutter-packages\flet_permission_handler
  flutter:
    sdk: flutter
  package_info_plus: ^8.0.2
  path: ^1.9.0
  path_provider: ^2.1.4
  serious_python: 0.8.7
  url_strategy: ^0.2.0
  window_manager: ^0.4.3

.toml ->

...
[tool.poetry.dependencies]
python = "^3.10.4"
flet = "^0.26.0"
pywifi = "^1.1.12"
websockets = "^12.0"
numpy = "^1.26.4"
flet-permission-handler = "^0.1.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.android.permission]
"android.permission.NEARBY_WIFI_DEVICES" = true

To reproduce

https://pypi.org/project/flet-permission-handler/
https://flet.dev/docs/controls/permissionhandler/

Expected behavior

Open android settings

Screenshots / Videos

Captures

[Upload media here]

Operating System

windows 11

Operating system details

None

Flet version

0.26.0

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

I tryed with flet build apk and flet build apk --include-packages flet_permission_handler. I tryed the 3º party asociated module and the same happends.

@FeodorFitsner
Copy link
Contributor

No need to use --include-packages or tweak pubspec.yaml anymore.

flet-permission-handler dependency should be added to pyproject.toml.

Build with flet build apk -v and paste the log here.

@SIRGPrice
Copy link
Author

SIRGPrice commented Feb 6, 2025

Thanks Feodor.

The same happends with flet build apk -v. Log here:

[18:02:06] Run subprocess: ['C:\Users\tonch\flutter\bin\flutter.BAT', '--version', '--no-version-check', '--suppress-analytics']
Flutter executable: C:\Users\tonch\flutter\bin\flutter.BAT
Dart executable: C:\Users\tonch\flutter\bin\dart.BAT
JDK installed at C:\Users\tonch\java\17.0.13+11
Configuring Flutter's path to JDK
Run subprocess: ['C:\Users\tonch\flutter\bin\flutter.BAT', 'config', '--suppress-analytics', '--jdk-dir=C:\Users\tonch\java\17.0.13+11']
[18:02:08] Setting "jdk-dir" value to "C:\Users\tonch\java\17.0.13+11".

       You may need to restart any open editors for them to read new settings.
       JDK installed ✅                                                                                                                                                                                                  
       Android SDK installation found at C:\Users\tonch\AppData\Local\Android\Sdk
       Android SDK package "cmdline-tools;latest" is already installed
       Android SDK package "platform-tools" is already installed
       Android SDK package "platforms;android-35" is already installed
       Android SDK package "build-tools;34.0.0" is already installed
       Android SDK installed ✅                                                                                                                                                                                          
       Custom Flutter dependencies: {}                                                                                                                                                                                   

[18:02:12] Created Flutter bootstrap project from gh:flet-dev/flet-build-template with ref "0.26.0" ✅
Run subprocess: ['C:\Users\tonch\flutter\bin\dart.BAT', 'run', '--suppress-analytics', 'serious_python:main', 'package', 'C:\Users\tonch\Desktop\Batery', '--platform', 'Android', '--requirements',
'flet-permission-handler>=0.1.0,flet>=0.26.0,numpy>=1.26.4,pywifi>=1.1.12,websockets>=12.0', '--exclude', 'build', '--cleanup']
[18:03:41] Packaged Python app ✅
Found Flutter extension at C:\Users\tonch\Desktop\Batery\build\flutter-packages\flet_permission_handler
Registered Flutter user extensions ✅
[18:03:45] Copying C:\Users\tonch\Desktop\Batery\assets\icon.png to C:\Users\tonch\Desktop\Batery\build\flutter\images
Customized app icons and splash images ✅
Run subprocess: ['C:\Users\tonch\flutter\bin\dart.BAT', 'run', '--suppress-analytics', 'flutter_launcher_icons']
[18:03:47] ════════════════════════════════════════════
FLUTTER LAUNCHER ICONS (v0.14.3)
════════════════════════════════════════════

       • Creating default icons Android
       • Overwriting the default Android launcher icon with a new icon
       • Creating adaptive icons Android

[18:03:48] • Updating colors.xml with color for adaptive icon background
• Creating mipmap xml file Android
• Overwriting default iOS launcher icon with new icon
[18:03:49] Creating Icons for Web...
Creating Icons for Windows...
Creating Icons for MacOS...
[18:03:50]
✓ Successfully generated launcher icons
Generated app icons ✅
Run subprocess: ['C:\Users\tonch\flutter\bin\dart.BAT', 'run', '--suppress-analytics', 'flutter_native_splash:create']
[18:03:52] [Android] Creating default splash images
[Android] Creating dark mode splash images
[Android] Creating default android12splash images
[Android] Creating dark mode android12splash images
[18:03:53] [Android] Updating launch background(s) with splash image path...
[Android] - android/app/src/main/res/drawable/launch_background.xml
[Android] - android/app/src/main/res/drawable-night/launch_background.xml
[Android] - android/app/src/main/res/drawable-v21/launch_background.xml
[Android] - android/app/src/main/res/drawable-night-v21/launch_background.xml
[Android] Updating styles...
[Android] - android/app/src/main/res/values-v31/styles.xml
[Android] - android/app/src/main/res/values-night-v31/styles.xml
[Android] - android/app/src/main/res/values/styles.xml
[Android] - android/app/src/main/res/values-night/styles.xml
Creating images
Creating dark mode images
Updating ios/Runner/Info.plist for status bar hidden/visible
[18:03:54] [Web] Creating images
[Web] Creating images
[18:03:55] [Web] Creating background images
[Web] Creating CSS
[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

       Generated splash screens ✅                                                                                                                                                                                       
       Run subprocess: ['C:\\Users\\tonch\\flutter\\bin\\flutter.BAT', 'build', 'apk', '--no-version-check', '--suppress-analytics', '--build-name', '0.1.0']                                                            

[18:03:56] Resolving dependencies...
[18:03:57] Downloading packages...
archive 3.6.1 (4.0.2 available)
characters 1.3.0 (1.4.0 available)
clock 1.1.1 (1.1.2 available)
collection 1.19.0 (1.19.1 available)
fl_chart 0.69.2 (0.70.2 available)
! flet 0.26.0 (overridden)
flutter_lints 2.0.3 (5.0.0 available)
image 4.3.0 (4.5.2 available)
intl 0.19.0 (0.20.2 available)
js 0.6.7 (0.7.1 available)
lints 2.1.1 (5.1.1 available)
material_color_utilities 0.11.1 (0.12.0 available)
meta 1.15.0 (1.16.0 available)
path 1.9.0 (1.9.1 available)
petitparser 6.0.2 (6.1.0 available)
sensors_plus 4.0.2 (6.1.1 available)
sensors_plus_platform_interface 1.2.0 (2.0.1 available)
toml 0.15.0 (0.16.0 available)
url_strategy 0.2.0 (discontinued)
! wakelock_plus 1.2.10 (overridden)
! web 1.1.0 (overridden)
web_socket_channel 2.4.5 (3.0.2 available)
! webview_flutter_android 4.3.1 (overridden)
win32_registry 1.1.5 (2.0.1 available)
! window_manager 0.4.3 (overridden)
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.
[18:06:12] Running Gradle task 'assembleRelease'... 133,7s
[18:06:13] √ Built build\app\outputs\flutter-apk\app-release.apk (85.1MB)
Built .apk for Android ✅
Copying build output from: C:\Users\tonch\Desktop\Batery\build\flutter\build\app\outputs\flutter-apk*
Copied build to build\apk directory ✅
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Successfully built your .apk for Android! 🥳 Find it in build\apk directory. 📁

@FeodorFitsner
Copy link
Contributor

It looks good from the logs. What error are you getting when running the app on a phone? How do you import flet_permission_handler in the app?

@SIRGPrice
Copy link
Author

Im getting this error once opening my app in mobile:

Traceback (most recent call last):
File "", line 95, in
File "", line 229, in run_module
File "", line 88, in _run_code
File "/data/user/0/com.flet.xxxxxx/files/flet/app/main.py", line 17, in
import flet_permission_handler as fph
ModuleNotFoundError: No module named 'flet_permission_handler'

To import flet_permission_handler in the app I did:

In main.py: import flet_permission_handler as fph

In .toml in [tool.poetry.dependencies]: flet-permission-handler = "^0.1.0"

@FeodorFitsner
Copy link
Contributor

OK, can you see what's inside .apk. Unpack .apk (it's a zip). Then inside archive locate lib/arm64-v8a/libpythonsitepackages.so and unpack it.

@SIRGPrice
Copy link
Author

SIRGPrice commented Feb 6, 2025

lib/arm64-v8a/libpythonsitepackages.so:

Image

The 2 previously showed folders related with permission handler once opened:

Image

Image

@omamkaz
Copy link
Contributor

omamkaz commented Feb 7, 2025

Edit your pyproject.toml into this and try to build your app

[project]
requires-python = ">=3.10"
dependencies = [
"flet-permission-handler==0.1.0",
"flet==0.26.0",
"pywifi== 1.1.12",
"websockets==12.0",
"numpy==1.26.4"
]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.android.permission]
"android.permission.NEARBY_WIFI_DEVICES" = true

@SIRGPrice
Copy link
Author

Its not working.

I think I will try to enable permissions manually for a time and continue working in this issue.

If I can solve the problem you will be noticed here.

Thanks all mates.

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

No branches or pull requests

3 participants