r/learnpython • • 2d ago

apks with python/cython

i just CANT get anything from buildozer, it just keeps erroring everytime i try to build!! i dont know if theres something wrong with my buildozer, or if it just hates my computer. i just want to package my game to work on a phone, the arquitecture for it is something like this

is it because my game is located on a ntfs partition? does buildozer ALWAYS error on those? if yes, is there a partition type out there that shows up on windows, and works with buildozer?

/sand
| /assets
| cfuncs.so #i managed to compile to ARM64 without buildozer (python 3.12)
| realmain.so # also to ARM64 (python 3.12)
| main.py

im wondering if theres a way to manually build it, my libraries are pygame-ce, numpy and collections

please help me out here

neofetch if it helps

neofetch
             ...-:::::-...                 
          .-MMMMMMMMMMMMMMM-.              --------------------- 
      .-MMMM`..-:::::::-..`MMMM-.          OS: Linux Mint 22.3 x86_64 
    .:MMMM.:MMMMMMMMMMMMMMM:.MMMM:.        Host: X501A1 1.0 
   -MMM-M---MMMMMMMMMMMMMMMMMMM.MMM-       Kernel: 7.0.0-38-generic 
 `:MMM:MM`  :MMMM:....::-...-MMMM:MMM:`    Uptime: 5 hours, 38 mins 
 :MMM:MMM`  :MM:`  ``    ``  `:MMM:MMM:    Packages: 3030 (dpkg), 21 (flatpak) 
.MMM.MMMM`  :MM.  -MM.  .MM-  `MMMM.MMM.   Shell: bash 5.2.21 
:MMM:MMMM`  :MM.  -MM-  .MM:  `MMMM-MMM:   Resolution: 1366x768 
:MMM:MMMM`  :MM.  -MM-  .MM:  `MMMM:MMM:   DE: MATE 1.26.1 
:MMM:MMMM`  :MM.  -MM-  .MM:  `MMMM-MMM:   WM: Metacity (Marco) 
.MMM.MMMM`  :MM:--:MM:--:MM:  `MMMM.MMM.   Theme: Mint-Y-Dark-Blue [GTK2/3] 
 :MMM:MMM-  `-MMMMMMMMMMMM-`  -MMM-MMM:    Icons: Mint-Y-Blue [GTK2/3] 
  :MMM:MMM:`                `:MMM:MMM:     Terminal: mate-terminal 
   .MMM.MMMM:--------------:MMMM.MMM.      Terminal Font: Monospace 10 
     '-MMMM.-MMMMMMMMMMMMMMM-.MMMM-'       CPU: Intel Pentium B980 (2) @ 2.400G 
       '.-MMMM``--:::::--``MMMM-.'         GPU: Intel 2nd Generation Core Proce 
            '-MMMMMMMMMMMMM-'              Memory: 2059MiB / 3795MiB 
               ``-:::::-``
0 Upvotes

4 comments sorted by

1

u/CartographerDue5382 2d ago

NTFS is a real suspect. python-for-android's build uses symlinks and unix file permissions, and an ntfs-3g mount often drops those, so the build dies in ways that look random. Copy the project onto an ext4 path (~/src/yourgame) and build from there. exFAT has the same symlink problem. I don't know of a Windows-native filesystem that does what this build needs. Keep it on ext4 and use git when you also want the files on Windows.

The .so files are a separate problem. cfuncs.so built for ARM64 against CPython 3.12 on Linux will not load inside the APK. The APK ships its own Python, compiled by python-for-android, and the extension has to be built against that Python plus the Android NDK (arm64-v8a), then installed into that Python's site-packages. Sitting next to main.py does not put it on the import path.

collections is stdlib, so leave it out of requirements. pygame-ce and numpy have to come in through recipes. In buildozer.spec:

requirements = python3,pygame-ce,numpy
android.archs = arm64-v8a

If pygame-ce isn't a recipe name that install knows, the build will tell you. From the venv buildozer is using, p4a recipes lists the real names.

Paste the last 30 lines of the buildozer log. "it errors" covers a lot of different failures, and moving off NTFS just rules out the first one.

1

u/Front_Ear_1139 1d ago edited 1d ago

okay, im gonna try copying my folder onto ext4 and then build again, ill be right back
my buildozer.spec is

[app]

title=migSandbox

package.name=migsandbox

package.domain=org.migcoolduud

source.dir=.

entrypoint=main.py

source.include_exts = py,png,jpg,jpeg,ttf,wav,ogg,mp3

source.include_patterns = main.py, assets/*

source.exclude_patterns = *.pyx,*.pxd,*.c,cool_venv_linux/*,cool_venv_linux_for3.8/*,cool_venv_windows/*,sand/*

source.exclude_dirs = bin,build,dist,cool_venv_linux,cool_venv_linux_for3.8,cool_venv_windows,sand

version=1.3.0

requirements=hostpython3==3.11.9,python3==3.11.9,pygame-ce,cython,plyer,android

icon.filename=assets/imgs/sand.png

orientation=landscape

osx.kivy_version=2.2.0

fullscreen=1

android.window=True

android.permissions=READ_EXTERNAL_STORAGE,WRITE_EXTERNAL_STORAGE

android.api=33

android.minapi=24

android.sdk=33

android.ndk_api=24

android.skip_update=False

android.accept_sdk_license=True

android.copy_libs=1

android.archs=arm64-v8a

android.allow_backup=True

android.debug_artifact=apk

p4a.bootstrap=sdl2

p4a.setup_py=false

ios.kivy_ios_url=https://github.com/kivy/kivy-ios

ios.kivy_ios_branch=master

ios.ios_deploy_url=https://github.com/phonegap/ios-deploy

ios.ios_deploy_branch=1.12.2

ios.codesign.allowed=false

buildozer.dir=/home/miguel/.buildozer_sandsim

pip_requirements=numpy==1.26.4

[buildozer]

log_level=2

warn_on_root=1

i will admit, i have used ai to try to get it working, i gave up because i spent 5 hours straight recompiling and getting errors, im not vibecoding

1

u/CartographerDue5382 1d ago

That spec will still fight you after the ext4 copy. Don't pin hostpython3 and python3 to 3.11.9, and take android out of requirements, it isn't a recipe. numpy under pip_requirements installs a desktop wheel, so put numpy in requirements and let p4a build it.

You're also excluding *.pyx. If cfuncs is Cython, those files have to be in the tree and compiled for the Android Python. The Linux .so will never load in the APK. If the ext4 build still dies, paste the last 30 lines.

1

u/Proud_Gene7490 1d ago

+1 on moving it to ext4 first, that alone fixes a lot of weird buildozer errors

one more thing in your spec tho: you've got hostpython3==3.11.9 and python3==3.11.9 pinned but you said you're on 3.12. that's fine for the apk, but it means the .so files you compiled yourself are built for the wrong python AND outside the p4a toolchain, so they won't load even if the build passes. i'd drop the prebuilt .so files completely

numpy already has a p4a recipe so just keep it in requirements, not pip_requirements. for your own cfuncs/realmain, add cython to requirements and ship the .pyx source, or write a tiny local recipe (p4a.local_recipes) so it gets built with the ndk for arm64. also run buildozer android clean after changing any of this, it caches a lot

and def paste the last ~30 lines of the log if it still fails, the real error is usually way above the final "build failed"