Buildozer: Switch from pygame to sdl2 easily

Created on 4 Apr 2016  路  20Comments  路  Source: kivy/buildozer

Hello,
Is possible to switch the engine from pygame to sdl2 in buildozer?
I have not seen any setup string about the engine in buildozer.spec file.

I ask this because I have a problem with the size of some widgets that are not positioned / sized as expected. They seem to be different than in windows or linux with sdl2.
Android system: 4.4.2 on galaxy s3 neo (gt-i9301i)

thanks and sorry for my bad english.

Most helpful comment

What I meant is:

  • Clone buildozer master branch
  • Inside cloned directory do python setup.py install
  • And then in your app directory run buildozer -v android_new debug

I think that pip install --upgrade buildozer --target android_new will not work.

All 20 comments

You can install master version and use target "android_new" which will build with SDL2.

I did this:
pip install --upgrade buildozer --target android_new
Without uninstall the preview version (with pygame).

buildozer -v android debug this work for start the debug with sdl2? or need some other parameter?

thanks

What I meant is:

  • Clone buildozer master branch
  • Inside cloned directory do python setup.py install
  • And then in your app directory run buildozer -v android_new debug

I think that pip install --upgrade buildozer --target android_new will not work.

Oh ok man, thanks. This work but raise the following problem when debug:

# Run 'python -m pythonforandroid.toolchain recipes --compact'
# Cwd /home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 24, in <module>
    import sh
ImportError: No module named sh
# Command failed: python -m pythonforandroid.toolchain recipes --compact
# 
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2

Where can i found the sh module?

I think you can install it with pip install python-sh or with apt-get install python-sh.

i found sh with pip install sh but not python-sh. This is the same?

I'm not currently on Linux, so I don't know for sure. You can always uninstall it if it isn't the same.

Yes, sh is the module name.

Seem to be working with sh instead of python-sh, but now i have another error:

# Run 'python -m pythonforandroid.toolchain recipes --compact'
# Cwd /home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 39, in <module>
    from pythonforandroid.build import Context, build_recipes
  File "pythonforandroid/build.py", line 11, in <module>
    from appdirs import user_data_dir
ImportError: No module named appdirs
# Command failed: python -m pythonforandroid.toolchain recipes --compact
# 
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2

This seems a lot of strange for me. The pygame version did not give these errors.
Is it possible that so many libraries missing with the new toolchan?

Someone have a working android_new toolchan to send?

These are dependencies of python-for-android that buildozer does not (yet) install automatically. Feel free to open an issue about this specifically. For now, just install the missing modules manually.

ok thanks i will try.

Can i use this thread to make a list of missing dependencies that i found in the sdl2 toolchan?
I ask this because I found other missing modules. So if someone else uses the same toolchain and has the same mistakes he can check them here.

I added sqlite3 in buildozer.spec but raise the following error:

# Install requirement sqlite3 in virtualenv
# Run 'pip install --target=/home/valerio/PROGETTI/showcase/.buildozer/applibs sqlite3'
# Cwd /home/valerio/PROGETTI/showcase/.buildozer
Collecting sqlite3
/home/valerio/PROGETTI/showcase/.buildozer/venv/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/home/valerio/PROGETTI/showcase/.buildozer/venv/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Could not find a version that satisfies the requirement sqlite3 (from versions: )
No matching distribution found for sqlite3
# Command failed: pip install --target=/home/valerio/PROGETTI/showcase/.buildozer/applibs sqlite3
# 
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2

i've tryed to install it with sudo pip install pysqlite but request a sqlite3.h file:

install --record /tmp/pip-gb51OW-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/pysqlite2
    copying lib/dump.py -> build/lib.linux-x86_64-2.7/pysqlite2
    copying lib/__init__.py -> build/lib.linux-x86_64-2.7/pysqlite2
    copying lib/dbapi2.py -> build/lib.linux-x86_64-2.7/pysqlite2
    creating build/lib.linux-x86_64-2.7/pysqlite2/test
    copying lib/test/dump.py -> build/lib.linux-x86_64-2.7/pysqlite2/test
    copying lib/test/types.py -> build/lib.linux-x86_64-2.7/pysqlite2/test
    copying lib/test/__init__.py -> build/lib.linux-x86_64-2.7/pysqlite2/test
    copying lib/test/hooks.py -> build/lib.linux-x86_64-2.7/pysqlite2/test
    copying lib/test/regression.py -> build/lib.linux-x86_64-2.7/pysqlite2/test
    copying lib/test/dbapi.py -> build/lib.linux-x86_64-2.7/pysqlite2/test
    copying lib/test/factory.py -> build/lib.linux-x86_64-2.7/pysqlite2/test
    copying lib/test/transactions.py -> build/lib.linux-x86_64-2.7/pysqlite2/test
    copying lib/test/userfunctions.py -> build/lib.linux-x86_64-2.7/pysqlite2/test
    running build_ext
    building 'pysqlite2._sqlite' extension
    creating build/temp.linux-x86_64-2.7
    creating build/temp.linux-x86_64-2.7/src
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMODULE_NAME="pysqlite2.dbapi2" -IPackage -Isqlite3 -Iwas -Inot -Ifound -Iin -Ithe -Ipkg-config -Isearch -Ipath. -IPerhaps -Iyou -Ishould -Iadd -Ithe -Idirectory -Icontaining -I`sqlite3.pc' -Ito -Ithe -IPKG_CONFIG_PATH -Ienvironment -Ivariable -INo -Ipackage -I'sqlite3' -Ifound -I/usr/include/python2.7 -c src/module.c -o build/temp.linux-x86_64-2.7/src/module.o
    In file included from src/module.c:24:0:
    src/connection.h:33:21: fatal error: sqlite3.h: File o directory non esistente
     #include "sqlite3.h"
                         ^
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-azEwOZ/pysqlite/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-gb51OW-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-azEwOZ/pysqlite/

I am unfamiliar with indeep change in buildozer code, so i removed it from buildozer.spec (i can't fix)

There is not yet a sqlite3 recipe in the new toolchain, but there is a PR for one.

Are you saying that they are interchangeable?

I don't know PR. I'm not able to find a package with this name on the web. Can explain me please?

Excuse my ignorance
PR = project ? if so i go ahead.

Another error, this time is not for a missing module:

this time is not for a missing module:

[INFO]:    Prebuilding kivy for armeabi-v7a
[INFO]:    kivy has no prebuild_armeabi_v7a, skipping
[INFO]:    # Building recipes
[INFO]:    Building python2 for armeabi-v7a
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 747, in <module>
    main()
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 744, in main
    ToolchainCL()
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 323, in __init__
    getattr(self, args.command)(unknown)
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 105, in wrapper_func
    build_dist_from_args(ctx, dist, dist_args)
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 142, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx)
  File "pythonforandroid/build.py", line 560, in build_recipes
    recipe.build_arch(arch)
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/recipes/python2/__init__.py", line 44, in build_arch
    self.do_python_build(arch)
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/recipes/python2/__init__.py", line 76, in do_python_build
    shprint(sh.cp, self.ctx.hostpython, self.get_build_dir(arch.arch))
AttributeError: 'Context' object has no attribute 'hostpython'

# Command failed: python -m pythonforandroid.toolchain create --dist_name=showcase --bootstrap=sdl2 --requirements=kivy --arch armeabi-v7a --copy-libs
# 
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2

There is a fast fix? Or i need to go indeep?

This is a known bug. The workaround is to add 'hostpython2' in the requirements.

Also, PR is pull request. In this case it is a submission to python-for-android, not buildozer, you can find the current PRs in the python-for-android github repository.

@inclement Oh thanks for your explanation. I am unfamiliar with abbreviations used in repositories.

Found this error:

[INFO]:     showcase: includes recipes (hostpython2, python2, sdl2_image, sdl2_mixer, sdl2_ttf, sdl2, six, pyjnius, kivy), built for archs (armeabi-v7a)
[INFO]:    showcase has compatible recipes, using this one
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 747, in <module>
    main()
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 744, in main
    ToolchainCL()
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 323, in __init__
    getattr(self, args.command)(unknown)
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 106, in wrapper_func
    func(self, args)
  File "/home/valerio/PROGETTI/showcase/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 577, in apk
    build = imp.load_source('build', join(dist.dist_dir, 'build.py'))
  File "/home/valerio/.local/share/python-for-android/dists/showcase/build.py", line 18, in <module>
    import jinja2
ImportError: No module named jinja2
# Command failed: python -m pythonforandroid.toolchain apk --bootstrap=sdl2 --dist_name showcase --name showcase --version 0.1 --package showcase.test.showcase --android_api 19 --minsdk 9 --private /home/valerio/PROGETTI/showcase/.buildozer/android/app --orientation sensor --copy-libs
# 
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2

fixed with sudo pip install Jinja2

OK, now the build process work.

@inclement
I have a problem when deploy run the test app on device with sudo buildozer android_new deploy run.
I post the error here or open a new issue?

I found a similar issue, Touchscreen input with SDL2 bootstrap #516, but i see only the presplash.

Was this page helpful?
0 / 5 - 0 ratings