Outils pour utilisateurs

Outils du site


issue67:tutoriel_-_python_p._38

As I promised in part 37, we will take the transposer app that we created, and create an APK to install it on your android device. Before we get started, let’s make sure we have everything ready. First thing we need is the two files we created last time in a folder that you can easily access. Let’s call it “transposer”. Create it in your home directory. Next, copy the two files (transpose.kv and transpose.py) into that folder. Now rename transpose.py to main.py. This part is important. Next, we need to reference the kivy packaging instructions in a web browser. The link is http://kivy.org/docs/guide/packaging-android.html. We will be using this for the next steps, but not exactly as the Kivy people intended. You should have the android SDK from our earlier lesson. Ideally, you will go through and get all the software that is listed there, but for our purposes, you can just follow along here. You will need to download the python-for-android software. Open a terminal window and type the following… git clone git://github.com/kivy/python-for-android

Comme je l'ai promis la dernière fois, nous allons reprendre l'application de transposition que nous avons écrite et créer un APK pour l'installer sur votre appareil Android.

Avant de commencer, assurons-nous que tout soit prêt. La première chose dont nous avons besoin est de placer les deux fichiers que nous avons créés la dernière fois dans un dossier auquel vous pouvez facilement accéder. Appelons-le « transposer ». Créez-le dans votre répertoire personnel. Ensuite, copiez les deux fichiers (transpose.kv et transpose.py) dans ce dossier. Maintenant renommez transpose.py en main.py. Cette partie est importante.

Ensuite, nous avons besoin de faire référence aux instructions d'empaquetage de Kivy dans un navigateur Web. Le lien est http://kivy.org/docs/guide/packaging-android.html. Nous allons utiliser ceci pour les prochaines étapes, mais pas exactement comme les gens de Kivy l'ont prévu. Vous devez avoir le SDK android de notre leçon précédente. Idéalement, vous devriez y retourner et récupérer tous les logiciels qui y sont listées, mais pour nos besoins, il vous suffit de suivre ce qui est indiqué ici. Vous aurez besoin de télécharger le logiciel python-for-android. Ouvrez une fenêtre de terminal et tapez ce qui suit :

git clone git://github.com/kivy/python-for-android

This will download and set up the software that we need to continue. Now, in a terminal window, change your directory to the python-for-android/dist/default folder. Now you will find a file called build.py. This is what will do all the work for us. Now comes the magic. The build.py program will take various command-line arguments and create the APK for you. Shown above is the syntax for build.py taken directly from the Kivy documentation. For our use, we will use the following command (the “\” is a line continuation character): ./build.py –dir ~/transposer –package org.RainyDay.transposer \ –name “RainyDay Transposer” –version 1.0.0 debug

Ceci va télécharger et installer le logiciel dont nous avons besoin pour continuer. Maintenant, dans un terminal, allez dans le répertoire du dossier python-for-android/dist/default.

Vous allez y trouver un fichier appelé build.py. C'est lui qui va faire tout le travail pour nous. Et maintenant, voici la magie.

Le programme build.py prend divers arguments sur la ligne de commande et créera l'APK pour vous. Ci-dessus se trouve la syntaxe pour build.py prise directement dans la documentation Kivy.

Pour nos besoins, nous allons utiliser la commande suivante (le « \ » est un caractère de continuation de ligne) :

./build.py –dir ~/transposer –package org.RainyDay.transposer \ –name “RainyDay Transposer” –version 1.0.0 debug

Let’s look at the pieces of the command… ./build.py - this is the application –dir ~/transposer - this is the directory where our application code lives. –package org.RainyDay.transposer - This is the name of the package –name “RainyDay Transposer” - this is the name of the application that will show up in the apps drawer. –version 1.0.0 - the version of our application debug - this is the level of release (debug or release)

Regardons les morceaux de la commande…

./build.py - c'est l'application ; –dir ~/transposer - il s'agit du répertoire contenant le code de l'application ; –package org.RainyDay.transposer - c'est le nom du paquet ; –name “RainyDay Transposer” - c'est le nom de l'application qui apparaîtra dans la liste des applications ; –version 1.0.0 - la version de notre application ; debug - c'est le niveau de sortie (debug ou release).

Once you execute this, assuming that everything worked as expected, you should have a number of files in the /bin folder. The one you are looking for is titled “RainyDayTransposer-1.0.0-debug.apk”. You can copy this to your android device using your favorite file manager app, and install it just like any other application from the various app stores. That’s all I have time for this month.

Une fois que vous aurez exécuté ceci, en supposant que tout a fonctionné comme prévu, vous devriez avoir un certain nombre de fichiers dans le dossier /bin. Celui que vous cherchez est intitulé « RainyDayTransposer-1.0.0-debug.apk ». Vous pouvez le copier sur votre appareil Android en utilisant votre gestionnaire de fichiers favori, puis l'installer comme n'importe quelle autre application des divers magasins d'applications.

C'est tout le temps dont je dispose pour ce mois-ci.

issue67/tutoriel_-_python_p._38.txt · Dernière modification : 2013/01/14 15:27 de auntiee