使用 buildozer 创建移动应用程序时如何允许访问 Python Socket.py 文件?
How to allow access to the Python Socket.py file when using buildozer to create a mobile app?
我在使用 Buildozer 构建移动应用程序时使用 Python 套接字模块时遇到问题。该程序似乎没有访问 socket.py 文件的权限,但我不知道如何修复它。下面显示了我认为来自调试日志的错误消息的代码。
2021-08-01 20:05:53.572 12099-12117/org.test.myapp6 I/python: Traceback (most recent call last):
2021-08-01 20:05:53.572 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/app/main.py", line 47, in <module>
2021-08-01 20:05:53.573 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/app.py", line 855, in run
2021-08-01 20:05:53.574 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/base.py", line 504, in runTouchApp
2021-08-01 20:05:53.575 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/core/window/window_sdl2.py", line 747, in mainloop
2021-08-01 20:05:53.575 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/core/window/window_sdl2.py", line 479, in _mainloop
2021-08-01 20:05:53.576 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/base.py", line 342, in idle
2021-08-01 20:05:53.577 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/base.py", line 327, in dispatch_input
2021-08-01 20:05:53.577 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/base.py", line 233, in post_dispatch_input
2021-08-01 20:05:53.578 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
2021-08-01 20:05:53.579 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/core/window/__init__.py", line 1402, in on_motion
2021-08-01 20:05:53.579 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
2021-08-01 20:05:53.580 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/core/window/__init__.py", line 1418, in on_touch_down
2021-08-01 20:05:53.581 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
2021-08-01 20:05:53.581 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/uix/widget.py", line 549, in on_touch_down
2021-08-01 20:05:53.582 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
2021-08-01 20:05:53.582 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/uix/behaviors/button.py", line 151, in on_touch_down
2021-08-01 20:05:53.583 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
2021-08-01 20:05:53.584 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
2021-08-01 20:05:53.585 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 1138, in kivy._event.EventObservers._dispatch
2021-08-01 20:05:53.585 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/app/main.py", line 38, in send_alert
2021-08-01 20:05:53.586 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/socket.py", line 231, in __init__
2021-08-01 20:05:53.587 12099-12117/org.test.myapp6 I/python: PermissionError: [Errno 13] Permission denied
2021-08-01 20:05:53.587 12099-12117/org.test.myapp6 I/python: Python for android ended.``'
Socket.py 是 python 预构建库,您不需要将其导入到 buildozer.spec正常运行。
对于 python3 和 kivy 2.0.0(即使有套接字)
requirements = python3,kivy=2.0.0
权限行
android.permissions = INTERNET
我在使用 Buildozer 构建移动应用程序时使用 Python 套接字模块时遇到问题。该程序似乎没有访问 socket.py 文件的权限,但我不知道如何修复它。下面显示了我认为来自调试日志的错误消息的代码。
2021-08-01 20:05:53.572 12099-12117/org.test.myapp6 I/python: Traceback (most recent call last):
2021-08-01 20:05:53.572 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/app/main.py", line 47, in <module>
2021-08-01 20:05:53.573 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/app.py", line 855, in run
2021-08-01 20:05:53.574 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/base.py", line 504, in runTouchApp
2021-08-01 20:05:53.575 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/core/window/window_sdl2.py", line 747, in mainloop
2021-08-01 20:05:53.575 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/core/window/window_sdl2.py", line 479, in _mainloop
2021-08-01 20:05:53.576 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/base.py", line 342, in idle
2021-08-01 20:05:53.577 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/base.py", line 327, in dispatch_input
2021-08-01 20:05:53.577 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/base.py", line 233, in post_dispatch_input
2021-08-01 20:05:53.578 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
2021-08-01 20:05:53.579 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/core/window/__init__.py", line 1402, in on_motion
2021-08-01 20:05:53.579 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
2021-08-01 20:05:53.580 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/core/window/__init__.py", line 1418, in on_touch_down
2021-08-01 20:05:53.581 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
2021-08-01 20:05:53.581 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/uix/widget.py", line 549, in on_touch_down
2021-08-01 20:05:53.582 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
2021-08-01 20:05:53.582 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp6/kivy/uix/behaviors/button.py", line 151, in on_touch_down
2021-08-01 20:05:53.583 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
2021-08-01 20:05:53.584 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
2021-08-01 20:05:53.585 12099-12117/org.test.myapp6 I/python: File "kivy/_event.pyx", line 1138, in kivy._event.EventObservers._dispatch
2021-08-01 20:05:53.585 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/app/main.py", line 38, in send_alert
2021-08-01 20:05:53.586 12099-12117/org.test.myapp6 I/python: File "/home/ubuntu/mobile_app/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/socket.py", line 231, in __init__
2021-08-01 20:05:53.587 12099-12117/org.test.myapp6 I/python: PermissionError: [Errno 13] Permission denied
2021-08-01 20:05:53.587 12099-12117/org.test.myapp6 I/python: Python for android ended.``'
Socket.py 是 python 预构建库,您不需要将其导入到 buildozer.spec正常运行。
对于 python3 和 kivy 2.0.0(即使有套接字)
requirements = python3,kivy=2.0.0
权限行
android.permissions = INTERNET