Outils pour utilisateurs

Outils du site


archives:kivy_buildozer_pour_creer_une_application_android_avec_un_script_python

Ceci est une ancienne révision du document !


Kivy: Buildozer pour créer une application Android avec un script python

Cette page ne concerne que python 3.5 Pour python 2.7, voir la page Buildozer avec python 2.7

Utiliser VirtualBox avec 2 systèmes invités différents si vous utilisez python3.5 et python2.7 pour divers projets. Testé sur Debian Strech 9.2 en octobre 2017.

Installation de Kivy

Buildozer

Installation

Dépendances suffisantes mais peut-être pas nécessaires:

Vérifier la version de cython à installer:

sudo apt-get install python3-dev zlib1g-dev pkg-config python3-colorama python3-sh python3-appdirs python3-jinja2 python3-six

Cython version = 0.28.2 en mai 2018

sudo pip3 install --upgrade cython==0.25.2

Les lib32 pour un 64 bits

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install build-essential ccache git libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 python2.7 python2.7-dev openjdk-8-jdk unzip zlib1g-dev zlib1g:i386

Version en cours de développement:

git clone https://github.com/kivy/buildozer
cd buildozer/
python3 setup.py build
sudo pip3 install -e .

Version stable:

sudo pip3 install buildozer

Ressources

Cristax

Télécharger CrystaX

Extraire

700 MO à télécharger, 8.5 Go décompressé, laisser le dossier dans votre home.

Compilation d'un projet

Ouvrir un terminal dans votre projet:

Init

buildozer init

Edition de buildozer.spec

Points importants

# (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,ogg
 
# (list) List of inclusions using pattern matching
source.include_patterns = data/*.png, sound/*.ogg
 
# (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy
requirements = python3crystax==3.5, kivy
 
# (str) Presplash of the application
presplash.filename = %(source.dir)s/data/logo_labomedia.png
 
# (str) Icon of the application
icon.filename = %(source.dir)s/data/multipong.png
 
# (str) Supported orientation (one of landscape, portrait or all)
orientation = landscape
 
# (list) Permissions
android.permissions = INTERNET,CHANGE_WIFI_MULTICAST_STATE,ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE
 
# (str) Android NDK version to use
android.ndk = 10.3.2
 
# (str) Android NDK directory (if empty, it will be automatically downloaded.)
android.ndk_path = /home/toto/crystax-ndk-10.3.2
 
# (str) The Android arch to build for, choices: armeabi-v7a, arm64-v8a, x86
android.arch = armeabi-v7a

Version

Il faut définir une version pour l'application que vous compilez.

Version Méthode 1

Cette ligne doit être la première ligne de code du fichier main.py; les versions seront gérées dans ce fichier.

__version__ = '0.67'
# (str) Application versioning (method 1)
version.regex = __version__ = ['"](.*)['"]
version.filename = %(source.dir)s/main.py

# (str) Application versioning (method 2)
# version = 1.2.0

Version Méthode 2

La version est définie dans ce fichier buildozer.spec:

# (str) Application versioning (method 1)
#version.regex = __version__ = ['"](.*)['"]
#version.filename = %(source.dir)s/main.py

# (str) Application versioning (method 2)
version = 1.2.0

Exemple

Compilation du apk

buildozer -v android debug

.buildozer

La compilation va créer un dossier .buildozer d'une taille en gros de 1 Go !!

Quand ça plante

  • buildozer android clean
  • Détruire /home/pierre/.local/share/python-for-android
  • .buildozer du home
  • .buildozer de votre dossier
  • .android du home

Debug de l'*.apk

Si l'application ne se lance pas

Kivy Launcher

Cette méthode n'exécute pas le apk, mais lance le main.py. Utilisez logcat.

Suivre tout ce qui se passe sur le téléphone avec logcat

sudo apt-get install adb
adb root
adb shell
kminilte:/sdcard/kivy/TapOSC $ logcat

Limitation de kivy

buildozer pour python3 est en développement

  • Aucun accent dans les fichier *.kv
  • Les packages utilisés dans kivy doivent être dans Crystax.
  • Le *.apk de TapOSC cause mais ne fume pas !

UTF-8 dans .kv

1

Cette proposition ne marche pas dans android après compilation buildozer!

with open(filename, encoding='utf-8') as f: 
    Builder.load_string(f.read()) 

Marchent seulement avec kivy, en exécution directe.

2

# -*- coding: utf-8 -*-

en début de kv ne marche pas

Par contre, il est possible de définir mettre une variable dans le main, pour définir le str du kv

Dans truc.kv:

    Label:
        id: Titre
        font_size:  root.width/28
        text: self.titre.text

Dans main.py:

class Machin(Screen):
    titre = ObjectProperty()
 
    # Dans le __init__() ou ailleurs
    self.titre.text = "éèàùê"

Les packages python 3.5 impossibles

  • twisted qui n'est pas officiellement porté en python 3 en novembre 2017 et n'est pas pris en charge par buildozer

Un jeu qui marche

Version en développement

Kivy buildozer python 3.5 mai 2018

sudo pip3 install Cython==0.27.3
git clone git://github.com/kivy/kivy.git
cd kivy
python3 setup.py build_ext --inplace -f
sudo python3 setup.py install
,
archives/kivy_buildozer_pour_creer_une_application_android_avec_un_script_python.1536072023.txt.gz · Dernière modification : 2018/09/04 14:40 de serge