英文:
Python Kivy/KivyMD App(.apk) crashing after showing loading screen on one android device but runs fine on another android device
问题
I am fairly new in using kivy
and kivymd
to develop python apps. I have been working on a personal app that will be used to store daily expenses. For that I am a using cloud MySQL Database. The python program works absolutely fine on Windows like the way I intended. For testing purposes and to make sure that kivy can actually work on android, I created a "Hello World" display app with kivy and kivymd in python and converted it into apk file using Buildozer
in GoogleColab
to be tested on my android device. It worked just fine on all my devices running on different android versions. I have created the accounts tracker app, and in the similar way in Google Colab I converted it into apk file. I tested the app on my device and it crashed past the loading screen. But surprisingly it worked just fine on another android device that I have.
Specification of Device 1(App Crashed):
- Model: realme 9 5G Speed Edition,
- Android Version: 13.
Specification of Device 2(App Working):
- Model: Samsung Galaxy M30s,
- Android Version: 11.
The "Hello World" simple app worked absolutely fine in both the devices mentioned above.
I am providing my source code of the accounts app in a Google Drive Link because it's a large file. Although It won't run on other Windows devices until and unless python mysql connector is installed and configured and the default database is feed in to that system.
Link:- https://drive.google.com/drive/folders/1_81YTYqYW6g2cjMW8UUmb9Rs5A6KC1Vm?usp=drive_link
Note:- For security and privacy reasons I have changed the MySQL server connection configuration in my Python file from my hosting server to local host. But my apps are built using connection configured to be used with my hosting server database.
I have used logcat
in Android Studio and connected my mobile to get error/crash logs.
Error Logs from my app:-
22:05:41.294 32206-32206 p.myaccountsapp pid-32206 E Invalid ID 0x00000000.
2023-06-19 22:05:41.294 32206-32206 ResourcesImplExt pid-32206 E the AssetManager's apkAsset: ApkAssets{path=<empty> and /system/framework/framework-res.apk}
2023-06-19 22:05:41.294 32206-32206 ResourcesImplExt pid-32206 E the AssetManager's apkAsset: ApkAssets{path=/my_bigball/overlay/GmsConfigOverlayASI_Infrastructure/GmsConfigOverlayASI_Infrastructure.apk}
2023-06-19 22:05:41.294 32206-32206 ResourcesImplExt pid-32206 E the AssetManager's apkAsset: ApkAssets{path=/my_bigball/overlay/GmsConfigOverlayCommonEx/GmsConfigOverlayCommonEx.apk}
2023-06-19 22:05:41.294 32206-32206 ResourcesImplExt pid-32206 E the AssetManager's apkAsset: ApkAssets{path=/my_bigball/overlay/GmsConfigOverlayComms/GmsConfigOverlayComms.apk}
2023-06-19 22:05:41.325 32206-32206 p.myaccountsapp org.myaccountsapp.myaccountsapp E sysOpen failed with error=Permission denied
2023-06-19 22:05:41.473 750-750 SELinux hwservicemanager E avc: denied { find } for interface=vendor.oplus.hardware.performance::IPerformance sid=u:r:untrusted_app:s0:c246,c257,c512,c768 pid=32206 scontext=u:r:untrusted_app:s0:c246,c257,c512,c768 tcontext=u:object_r:hal_performance_hwservice:s0 tclass=hwservice_manager permissive=0
2023-06-19 22:05:41.488 1892-4210 SensorService system_server E Required app org.libsdl.app.SDLSurface, uid 10502, pid 32206
2023-06-19 22:05:41.514 32206-32206 SurfaceSyncer org.myaccountsapp.myaccountsapp E Failed to find sync for id=0
2023-06-19 22:05:41.522 8548-8549 IHansComunication hans E HANS printMessageBody: RCV message: type = 4,port = 86870,caller_pid = -1,caller_uid = -1,target_pid = -1,target_uid = 10071,pkg_cmd = -1,rpc = PKG/-1
2023-06-19 22:05:41.558 32206-32206 SurfaceSyncer org.myaccountsapp.myaccountsapp E Failed to find sync for id=0
2023-06-19 22:05:42.459 32259-32259 .link:link.data pid-32259 E Unknown bits set in runtime_flags: 0x40000000
2023-06-19 22:05:42.462 32259-32259 .link:link.data pid-32259 E Not starting debugger since process cannot load the jdwp agent.
2023-06-19 22:05:46.733 32206-32251 libc org.myaccountsapp.myaccountsapp A exiting due to SIG_DFL handler for signal 11, ucontext 0x791f4c4e20
2023-06-19 22:05:46.734 32206-32251 libc org.myaccountsapp.myaccountsapp A Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 32251 (SDLThread), pid 32206 (SDLActivity)
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A Process name is org.myaccountsapp.myaccountsapp, not key_process
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A keyProcess: 0
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A Build fingerprint: 'realme/RMX3461/RE54BFL1:13/TP1A.
<details>
<summary>英文:</summary>
I am fairly new in using **`kivy`** and **`kivymd`** to develop python apps. I have been working on a personal app that will be used to store daily expenses. For that I am a using cloud MySQL Database. The python program works absolutely fine on Windows like the way I intended. For testing purposes and to make sure that kivy can actually work on android, I created a "Hello World" display app with kivy and kivymd in python and converted it into apk file using `Buildozer` in `GoogleColab` to be tested on my android device. It worked just fine on all my devices running on different android versions. I have created the accounts tracker app, and in the similar way in Google Colab I converted it into apk file. I tested the app on my device and it crashed past the loading screen. But surprisingly it worked just fine on another android device that I have.
Specification of Device 1(App Crashed):
- Model: realme 9 5G Speed Edition,
- Android Version: 13.
Specification of Device 2(App Working):
- Model: Samsung Galaxy M30s,
- Android Version: 11.
> **The "Hello World" simple app worked absolutely fine in both the devices mentioned above.**
---
I am providing my source code of the accounts app in a Google Drive Link because it's a large file. Although It won't run on other Windows devices until and unless python mysql connector is installed and configured and the default database is feed in to that system.
> Link:- https://drive.google.com/drive/folders/1_81YTYqYW6g2cjMW8UUmb9Rs5A6KC1Vm?usp=drive_link
**Note:- For security and privacy reasons I have changed the MySQL server connection configuration in my Python file from my hosting server to local host. But my apps are built using connection configured to be used with my hosting server database.**
---
I have used `logcat` in Android Studio and connected my mobile to get error/crash logs.
Error Logs from my app:-
22:05:41.294 32206-32206 p.myaccountsapp pid-32206 E Invalid ID 0x00000000.
2023-06-19 22:05:41.294 32206-32206 ResourcesImplExt pid-32206 E the AssetManager's apkAsset: ApkAssets{path=<empty> and /system/framework/framework-res.apk}
2023-06-19 22:05:41.294 32206-32206 ResourcesImplExt pid-32206 E the AssetManager's apkAsset: ApkAssets{path=/my_bigball/overlay/GmsConfigOverlayASI_Infrastructure/GmsConfigOverlayASI_Infrastructure.apk}
2023-06-19 22:05:41.294 32206-32206 ResourcesImplExt pid-32206 E the AssetManager's apkAsset: ApkAssets{path=/my_bigball/overlay/GmsConfigOverlayCommonEx/GmsConfigOverlayCommonEx.apk}
2023-06-19 22:05:41.294 32206-32206 ResourcesImplExt pid-32206 E the AssetManager's apkAsset: ApkAssets{path=/my_bigball/overlay/GmsConfigOverlayComms/GmsConfigOverlayComms.apk}
2023-06-19 22:05:41.325 32206-32206 p.myaccountsapp org.myaccountsapp.myaccountsapp E sysOpen failed with error=Permission denied
2023-06-19 22:05:41.473 750-750 SELinux hwservicemanager E avc: denied { find } for interface=vendor.oplus.hardware.performance::IPerformance sid=u:r:untrusted_app:s0:c246,c257,c512,c768 pid=32206 scontext=u:r:untrusted_app:s0:c246,c257,c512,c768 tcontext=u:object_r:hal_performance_hwservice:s0 tclass=hwservice_manager permissive=0
2023-06-19 22:05:41.488 1892-4210 SensorService system_server E Required app org.libsdl.app.SDLSurface, uid 10502, pid 32206
2023-06-19 22:05:41.514 32206-32206 SurfaceSyncer org.myaccountsapp.myaccountsapp E Failed to find sync for id=0
2023-06-19 22:05:41.522 8548-8549 IHansComunication hans E HANS printMessageBody: RCV message: type = 4,port = 86870,caller_pid = -1,caller_uid = -1,target_pid = -1,target_uid = 10071,pkg_cmd = -1,rpc = PKG/-1
2023-06-19 22:05:41.558 32206-32206 SurfaceSyncer org.myaccountsapp.myaccountsapp E Failed to find sync for id=0
2023-06-19 22:05:42.459 32259-32259 .link:link.data pid-32259 E Unknown bits set in runtime_flags: 0x40000000
2023-06-19 22:05:42.462 32259-32259 .link:link.data pid-32259 E Not starting debugger since process cannot load the jdwp agent.
2023-06-19 22:05:46.733 32206-32251 libc org.myaccountsapp.myaccountsapp A exiting due to SIG_DFL handler for signal 11, ucontext 0x791f4c4e20
2023-06-19 22:05:46.734 32206-32251 libc org.myaccountsapp.myaccountsapp A Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 32251 (SDLThread), pid 32206 (SDLActivity)
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A Process name is org.myaccountsapp.myaccountsapp, not key_process
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A keyProcess: 0
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A Build fingerprint: 'realme/RMX3461/RE54BFL1:13/TP1A.220905.001/R.105741b-5f5a-5f59:user/release-keys'
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A Revision: '0'
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A ABI: 'arm64'
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A Timestamp: 2023-06-19 22:05:46.895663675+0530
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A Process uptime: 7s
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A Cmdline: org.myaccountsapp.myaccountsapp
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A pid: 32206, tid: 32251, name: SDLThread >>> org.myaccountsapp.myaccountsapp <<<
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A uid: 10502
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A Abort message: 'exiting due to SIG_DFL handler for signal 11, ucontext 0x791f4c4e20'
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A x0 0000000000000000 x1 0000000000007dfb x2 0000000000000006 x3 000000791f4c4c60
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A x4 0000008080808080 x5 0000008080808080 x6 0000008080808080 x7 8080808080000000
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A x8 00000000000000f0 x9 00000079060eae60 x10 0000000000000001 x11 0000007906150a44
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A backtrace:
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A NOTE: Function names and BuildId information is missing for some frames due
NOTE: to unreadable libraries. For unwinds of apps, only shared libraries
NOTE: found under the lib/ directory are readable.
NOTE: On this device, run setenforce 0 to make the libraries readable.
NOTE: Unreadable libraries:
NOTE: /data/data/org.myaccountsapp.myaccountsapp/files/app/_python_bundle/site-packages/kivy/_event.so
NOTE: /data/data/org.myaccountsapp.myaccountsapp/files/app/_python_bundle/site-packages/kivy/graphics/compiler.so
NOTE: /data/data/org.myaccountsapp.myaccountsapp/files/app/_python_bundle/site-packages/kivy/graphics/instructions.so
NOTE: /data/data/org.myaccountsapp.myaccountsapp/files/app/_python_bundle/site-packages/kivy/graphics/vbo.so
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A #00 pc 000000000007da34 /apex/com.android.runtime/lib64/bionic/libc.so (abort+168) (BuildId: 59222d1015276d9a9031ee1ea28c0bcd)
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A #01 pc 00000000000024c8 /apex/com.android.art/lib64/libsigchain.so (art::SignalChain::Handler(int, siginfo*, void*)+1084) (BuildId: c2eed67ad222447f39d6878846f202fc)
2023-06-19 22:05:47.814 32426-32426 DEBUG pid-32426 A #02 pc 00000000000005d0 [vdso] (__kernel_rt_sigreturn+0)
Same error continues
---
I have used `-s python` command in logcat to filter out python logs. Here are the logs that I got from my app:-
2023-06-19 23:39:20.085 25923-26010 python org.myaccountsapp.myaccountsapp I os.environ is environ({'PATH': '/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin', 'ANDROID_BOOTLOGO': '1', 'ANDROID_ROOT': '/system', 'ANDROID_ASSETS': '/system/app', 'ANDROID_DATA': '/data', 'ANDROID_STORAGE': '/storage', 'ANDROID_ART_ROOT': '/apex/com.android.art', 'ANDROID_I18N_ROOT': '/apex/com.android.i18n', 'ANDROID_TZDATA_ROOT': '/apex/com.android.tzdata', 'EXTERNAL_STORAGE': '/sdcard', 'ASEC_MOUNTPOINT': '/mnt/asec', 'MY_CUSTOM_ROOT': '/my_custom', 'MY_SPECIAL_PRELOAD_ROOT': '/special_preload', 'MY_CARRIER_ROOT': '/my_carrier', 'MY_REGION_ROOT': '/my_region', 'MY_COMPANY_ROOT': '/my_company', 'MY_ENGINEER_ROOT': '/my_engineering', 'MY_ENGINEERING_ROOT': '/my_engineering', 'MY_PRODUCT_ROOT': '/my_product', 'MY_VERSION_ROOT': '/my_version', 'MY_OPERATOR_ROOT': '/my_carrier', 'MY_COUNTRY_ROOT': '/my_region', 'MY_ODM_ROOT': '/odm', 'MY_PRELOAD_ROOT': '/my_preload', 'MY_HEYTAP_ROOT': '/my_heytap', 'MY_STOCK_ROOT': '/my_stock', 'MY_MANIFEST_ROOT': '/my_manifest', 'MY_BIGBALL_ROOT': '/my_bigball', 'DOWNLOAD_CACHE': '/data/cache', 'BOOTCLASSPATH': '/apex/com.android.art/javalib/core-oj.jar:/apex/com.android.art/javalib/core-libart.jar:/apex/com.android.art/javalib/okhttp.jar:/apex/com.android.art/javalib/bouncycastle.jar:/apex/com.android.art/javalib/apache-xml.jar:/system/framework/framework.jar:/system/framework/framework-graphics.jar:/system/framework/ext.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/tcmiface.jar:/system/framework/telephony-ext.jar:/system/framework/qcom.fmradio.jar:/system/framework/QPerformance.jar:/system/framework/UxPerformance.jar:/system/framework/WfdCommon.jar:/system/framework/oplus-framework.jar:/system/framework/oplus-support-wrapper.jar:/system/framework/subsystem-framework.jar:/apex/com.android.i18n/javalib/core-icu4j.jar:/apex/com.android.adservices/javalib/framework-adservices.jar:/apex/com.android.adservices/javalib/framework-sdksandbox.jar:/apex/com.android.appsearch/javalib/framework-appsearch.jar:/apex/com.android.conscrypt/javalib/conscrypt.jar:/apex/com.android.ipsec/javalib/android.net.ipsec.ike.jar:/apex/com.android.media/javalib/updatable-media.jar:/apex/com.android.mediaprovider/javalib/framework-mediaprovider.jar:/apex/com.android.ondevicepersonalization/javalib/framework-ondevicepersonalization.jar:/apex/com.android.os.statsd/javalib/framework-statsd.jar:/apex/com.android.permission/javalib/framework-permission.jar:/apex/com.android.permission/javalib/framework-permission-s.jar:/apex/com.android.scheduling/javalib/framework-scheduling.jar:/apex/com.android.sdkext/javalib/framework-sdkextensions.jar:/apex/com.android.tethering/javalib/framework-connectivity.jar:/apex/com.android.tethering/javalib/framework-connectivity-t.jar:/apex/com.android.tethering/javalib/framework-tethering.jar:/apex/com.android.uwb/javalib/framework-uwb.jar:/apex/com.android.wifi/javalib/framework-wifi.jar', 'DEX2OATBOOTCLASSPATH': '/apex/com.android.art/javalib/core-oj.jar:/apex/com.android.art/javalib/core-libart.jar:/apex/com.android.art/javalib/okhttp.jar:/apex/com.android.art/javalib/bouncycastle.jar:/apex/com.android.art/javalib/apache-xml.jar:/system/framework/framework.jar:/system/framework/framework-graphics.jar:/system/framework/ext.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/tcmiface.jar:/system/framework/telephony-ext.jar:/system/framework/qcom.fmradio.jar:/system/framework/QPerformance.jar:/system/framework/UxPerformance.jar:/system/framework/WfdCommon.jar:/system/framework/oplus-framework.jar:/system/framework/oplus-support-wrapper.jar:/system/framework/subsystem-framework.jar:/apex/com.android.i18n/javalib/core-icu4j.jar', 'SYSTEMSERVERCLASSPATH': '/system/framework/com.android.location.provider.jar:/system/framework/services.jar:/system/framework/oplus-services.jar:/system/framework/oplus-servi
2023-06-19 23:39:24.760 1892-2456 WindowManager system_server W Failed to deliver inset state change to w=Window{e0ec1c4 u0 org.myaccountsapp.myaccountsapp/org.kivy.android.PythonActivity EXITING}
android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(BinderProxy.java:672)
at android.view.IWindow$Stub$Proxy.insetsControlChanged(IWindow.java:473)
at com.android.server.wm.WindowState.notifyInsetsControlChanged(WindowState.java:4288)
---
As far as I understood from the error crash logs from backtracing that few libraries are unreadable on my device. But if Google Colab has created an corrupted apk then it should have crashed on every device. But it works on other devices(Not to mention that the layout is broken but thats another troubleshoot for another day)
While doing my resarch about the troubleshoot I got to know that the error might be because of lower `targetSDK`. Apparently Buildozer created the apk using api-31. Since my device is running on Android 13 it needed an target sdk of above 33. So,upon doing the necessary changes(using API-34) I created the apk again and it crashed again giving the same error logs on `logcat`.
---
My Buildozer.specs file:-
[app]
(str) Title of your application
title = My Accounts App
(str) Package name
package.name = myaccountsapp
(str) Package domain (needed for android/ios packaging)
package.domain = org.myaccountsapp
(str) Source code where the main.py live
source.dir = .
(list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas
(list) List of inclusions using pattern matching
#source.include_patterns = assets/,images/.png
(list) Source files to exclude (let empty to not exclude anything)
#source.exclude_exts = spec
(list) List of directory to exclude (let empty to not exclude anything)
#source.exclude_dirs = tests, bin, venv
(list) List of exclusions using pattern matching
Do not prefix with './'
#source.exclude_patterns = license,images//.jpg
(str) Application versioning (method 1)
version = 0.1
(str) Application versioning (method 2)
version.regex = version = '"['"]
version.filename = %(source.dir)s/main.py
(list) Application requirements
comma separated e.g. requirements = sqlite3,kivy
requirements = sdl2,hostpython3==3.10.0,python3==3.10.0,kivy==2.2.1,kivymd==1.1.1,pillow,datetime,mysql-connector-python
(str) Custom source folders for requirements
Sets custom source for any requirements with recipes
requirements.source.kivy = ../../kivy
(str) Presplash of the application
#presplash.filename = %(source.dir)s/data/presplash.png
(str) Icon of the application
#icon.filename = %(source.dir)s/data/icon.png
(list) Supported orientations
Valid options are: landscape, portrait, portrait-reverse or landscape-reverse
orientation = portrait
(list) List of service to declare
#services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY
OSX Specific
author = © Copyright Info
change the major version of python used by the app
osx.python_version = 3
Kivy version to use
osx.kivy_version = 1.9.1
Android specific
(bool) Indicate if the application should be fullscreen or not
fullscreen = 0
(string) Presplash background color (for android toolchain)
Supported formats are: #RRGGBB #AARRGGBB or one of the following names:
red, blue, green, black, white, gray, cyan, magenta, yellow, lightgray,
darkgray, grey, lightgrey, darkgrey, aqua, fuchsia, lime, maroon, navy,
olive, purple, silver, teal.
#android.presplash_color = #FFFFFF
(string) Presplash animation using Lottie format.
see https://lottiefiles.com/ for examples and https://airbnb.design/lottie/
for general documentation.
Lottie files can be created using various tools, like Adobe After Effect or Synfig.
#android.presplash_lottie = "path/to/lottie/file.json"
(str) Adaptive icon of the application (used if Android API level is 26+ at runtime)
#icon.adaptive_foreground.filename = %(source.dir)s/data/icon_fg.png
#icon.adaptive_background.filename = %(source.dir)s/data/icon_bg.png
(list) Permissions
(See https://python-for-android.readthedocs.io/en/latest/buildoptions/#build-options-1 for all the supported syntaxes and properties)
android.permissions = android.permission.INTERNET, (name=android.permission.WRITE_EXTERNAL_STORAGE;maxSdkVersion=18)
(list) features (adds uses-feature -tags to manifest)
#android.features = android.hardware.usb.host
(int) Target Android API, should be as high as possible.
#android.api = 31
android.api = 34
(int) Minimum API your APK / AAB will support.
#android.minapi = 21
(int) Android SDK version to use
#android.sdk = 20
(str) Android NDK version to use
#android.ndk = 23b
android.ndk = 25b
(int) Android NDK API to use. This is the minimum API your app will support, it should usually match android.minapi.
#android.ndk_api = 21
I have changed the `Android api version to 34 and ndk version to 25b` which is latest according to `p4a documentation` and `Android Documentation`. I have tried both with and without the sdk changes and each time the app crashed after loading screen on my android device but ran perfectly on another android device.
Also I `have changed the requirements and declared all the packages that I have used in my build`. I have also `uncommented the android permissions` part since I would be needing Internet access to connect to the cloud database. `I have tried using both kivy and kivymd master files yet no luck`.
It runs absolutely fine on the Samsung Device but crashes on my realme device
Please help me, its been almost a week I am stuck at this problem trying to figure out. Else I am thinking of just abandoning it and start fresh with flutter. But I really wanted to move with python as I have a good experience and knowledge with python.
</details>
# 答案1
**得分**: 2
经过大量的挖掘和研究,我在一定程度上成功解决了最初的问题的一半。我拿到了几台不同版本的Android设备,并且在所有这些设备上都可以正常运行,没有任何问题。起初,在我的realme设备和其他一些设备上没有正常运行(我在发布上述问题后进行了测试)。因此,在进行了大量的查找和研究后,我在一定程度上解决了我的问题,但是仍然无法在我的realme设备上运行。但是,在以前无法运行的所有其他设备上都可以正常运行。此外,我还使用了一个相同Android版本(V-13)的设备进行了测试,显然也可以正常运行。因此,这可能与我的设备有关,realme可能会阻止我的应用程序,因为它未经Google Play验证或不受信任(可能)。
在研究中,我看到了一些人在将“Python Kivy应用程序”转换为“Android APK”时遇到问题。因此,我考虑分享我的研究,以便我也可以为社区做出贡献。
以下是要遵循的步骤:
首先,在Google Colab中创建一个新的笔记本,并分别将下面的每个代码粘贴到一个新的单元格中。不要在一个单元格中粘贴整个代码。
!pip install buildozer
!pip install -U cython
!pip install kivymd
!pip install python-for-android
!sudo apt install lld
!sudo apt-get install -y
python3-pip
build-essential
git
python3
python3-dev
ffmpeg
libsdl2-dev
libsdl2-image-dev
libsdl2-mixer-dev
libsdl2-ttf-dev
libportmidi-dev
libswscale-dev
libavformat-dev
libavcodec-dev
zlib1g-dev
!sudo apt-get install -y
libgstreamer1.0
gstreamer1.0-plugins-base
gstreamer1.0-plugins-good
!sudo apt-get install libffi7
!sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev libgdbm-compat-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev libffi7
!sudo apt-get install libffi-dev
!buildozer init
!buildozer -v android debug
如果apk未出现在相同目录中的bin文件夹中,请刷新Colab笔记本。
上述用于Google Colab的代码完美地用于打包和构建apk以在Android上运行。它下载了所有apk运行所需的依赖项和先决条件。尽管我不知道为什么apk在我的realme设备上无法运行。也许有一天我会知道。我个人测试了上述代码来创建不同的apk,每次都可以完美运行,没有出现任何错误。
需要注意的一点是,在运行`!buildozer init`之后,将创建一个`buildozer.spec`文件,其中需要编辑要求部分,并需要声明在Python中用于创建程序的所有库。如果您使用了`kivymd`,则必须声明`kivymd`以及`pillow库`。还记得将API版本更改为较高的版本,例如`33`,这是截至`2023年6月24日`的最新版本,以便使应用程序在新的Android版本设备上运行。
希望我可以通过这种方式帮助Kivy社区,以及那些遇到类似问题的人。尽管我仍然希望保持我的问题处于活动状态,以便有人可以帮助我解决为什么我的apk在我的特定设备上无法运行的问题。愉快编码!
<details>
<summary>英文:</summary>
Well after a lot of digging and research, I was kind of able to eliminate half of the initial problem. I got my hands over several devices with different versions of Android and in all of them it works without any problem. At first it didn't run properly on my realme device and few other devices(I tested it after I posted my above question). So, after doing a lot of finding and research I was able to fix my problem somewhat but still, it does not run on my realme device. However, it runs on all other devices on which it did not run earlier. Also, I tested with a device of the same Android version(V-13), and apparently, it works without any problem. So, it might be something to with my device, with realme blocking my app since its untrusted or not verified by Google Play(Maybe).
During my research I came across several posts where people are facing problem in converting `python kivy app` to `apk for android`. So, I thought of sharing my research, so that I can also contribute to the community.
Steps to follow are:-
**Firstly create a new notebook in Google Colab and paste each of the below code separately in a new cell. Do not paste the whole code in one cell**
!pip install buildozer
!pip install -U cython
!pip install kivymd
!pip install python-for-android
!sudo apt install lld
!sudo apt-get install -y \
python3-pip \
build-essential \
git \
python3 \
python3-dev \
ffmpeg \
libsdl2-dev \
libsdl2-image-dev \
libsdl2-mixer-dev \
libsdl2-ttf-dev \
libportmidi-dev \
libswscale-dev \
libavformat-dev \
libavcodec-dev \
zlib1g-dev
!sudo apt-get install -y \
libgstreamer1.0 \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good
!sudo apt-get install libffi7
!sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev libgdbm-compat-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev libffi7
!sudo apt-get install libffi-dev
!buildozer init
!buildozer -v android debug
The apk will be available in the **bin** folder in the same directory, if it does not appears just refresh the colab notebook.
The above code for `Google Colab` works perfectly in packing and building your apk to be run on android. It downloads all the dependencies and pre requests that the apk needs to run perfectly. Although I don't know why the apk does not run on my realme device. Maybe someday I'll know. I have personally tested the above code for creating different apk's and each time it runs perfectly without giving any error.
**One thing to note here is that after running `!buildozer init`, a `buildozer.spec` file will be created in which the requirements part need to be edited and their one needs to declare all the libraries that one has used in python to create the program. If you have used `kivymd` then it is mandatory to declare `pillow library along with kivymd`. Also remember to change the API version to higher version like `33` which is latest as on `24-06-2023` so to make the app run on new android version devices.**
Hope I can help the kivy community by this, and the people who stumble upon my query for their questions. Although I would still like to keep my query active so that someone can help me out as to why my apk is not running on my particular device. Happy Coding!!
</details>
# 答案2
**得分**: 0
以下是翻译好的部分:
这款应用在我的 `Samsung Galaxy S22` 启动时也经常崩溃... 因此,在进行了大量尝试和阅读后,我成功修复了它,选择了合适的 `kivy` 和 `kivymd` 库版本。
这些链接帮助我解决了与此消息相关的问题(您可以在 `logcat` 中看到它):
> 致命信号 11 (SIGSEGV),代码 1 (SEGV_MAPERR),故障地址 0x40,线程 ID 3963 (SDLThread),进程 ID 3902 (SDLActivity)
参考链接:
- 有关特定问题的详细信息,请点击[此处][1](我知道,乍看之下似乎与 `MDDialog` 有关,但实际上重要的部分是 `logcat` 中的第一行,提到了 `Fatal signal 11`)
- 修复此问题的Android `APK`构建配方:[如何在Android设备上修复着色器错误][2]
[1]: https://github.com/kivymd/KivyMD/issues/1496
[2]: https://github.com/kivymd/KivyMD#how-to-fix-a-shader-bug-on-an-android-device
<details>
<summary>英文:</summary>
The app was also crashing big time at startup on my `Samsung Galaxy S22`... so after a lot of trials and reading here is how I managed to fix it by picking the right versions of both `kivy` and `kivymd` libraries
These links helped me to solve the issue related to this message (you can see it in `logcat`):
> Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x40 in tid 3963 (SDLThread), pid 3902 (SDLActivity)
References:
- detail about specific [issue here][1] (I know, it seems at first to be related to `MDDialog` but in fact the important part is the `logcat` very first line talking about `Fatal signal 11`)
- the Android `APK` build recipe that fixed the issue: [How to fix a shader bug on an android device][2]
[1]: https://github.com/kivymd/KivyMD/issues/1496
[2]: https://github.com/kivymd/KivyMD#how-to-fix-a-shader-bug-on-an-android-device
</details>
# 答案3
**得分**: -1
尝试将目标API更改为33。
<details>
<summary>英文:</summary>
Try changing the target API to 33.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论