Outils pour utilisateurs

Outils du site


issue119:ubuntu_touch

Ceci est une ancienne révision du document !


In the previous chapter we have seen an introduction to the programming course with Ubuntu Touch. The next step is to prepare the development environment. When programming in any language, an SDK (Software Development Kit) is often used. The SDK consists of a set of tools that processes the source code and generates the executable for the platform that is being used. Ubuntu Touch is not an exception and also has its own SDK. Applications in GNU / Linux are in repositories. The repository contains a set of applications that can be easily installed. On some occasions, there are applications that are not in the official repositories. For these cases, it is possible to use personal repositories, also known as PPA repositories. The Ubuntu Touch SDK is in a PPA repository that will have to be added to the system in order to be installed. With this limitation, it can be programmed only on distributions that can work with PPA repositories, that is to say, all the distributions that use Debian as a base. If the distribution uses RPM packages, as in the case of OpenSuse or Fedora, alternative measures will have to be taken.

Dans le précédent chapitre, nous avons vu un e présentation de cours de programmation avec Ubuntu Touch. L'étape suivante est de préparer l'environnement de développement. Quand on programme, quelque soit le langage, un SDK (Software Development Kit - Kit de développement de logiciel) est souvent utilisé. Le SDK consiste en un jeu de d'outils qui traitent le code source et génère un exécutable pour la plateforme qui sera utilisée. Ubuntu Touch n'est pas un exception et a aussi son propre SDK.

SDans GNU/Linux, les applications sont dans des dépôts. Le dépôt contient un ensemble d'applications qui peuvent être facilement installées. Dans certains cas, des applications ne sont pas dans les dépôts officiels. Pour ces cas, il est possible d'utiliser des dépôts personnels, connus aussi comme dépôts PPA. Le SDK d'Ubuntu Touch est des un dépôt PPA qui doit être ajouté au système de façon à pouvoir l'installer. Avec cette limitation, il ne peut être programmé que sur les distributions que peuvent fonctionner avec des dépôts PPA, c'est-à-dire, toutes les distributions qui ont Debian comme base. Si une distribution utiliser des paquets RPM, comme OpenSuse ou Fedora, des solutions de remplacement devront être prises.

There are two other ways to do this: create a Live USB with Ubuntu, or use a virtual machine that has Ubuntu installed. The first one is simpler and works reasonably well if the USB memory is fast. The second way is more comfortable since it does not depend on a USB stick, but requires a more powerful computer to run the virtualized operating system. I will not go into how to create a Live USB or virtual machine. Anyone in one of these two cases can ask in the mailing list and I will guide him/her with the most important steps. My development environment is: • Ubuntu 16.04 LTS. • Aquaris E4.5 with OTA-14. • Aquaris E5 HD with OTA-14. • Aquaris M10 FHD with OTA-14. It is possible that in other distributions there are some intermediate steps that need to be done to configure the SDK. If that is the case you can indicate it.

Il y a deux autres façons de le faire : créer un Live USB avec Ubuntu ou utiliser une machine virtuelle avec Ubuntu installé. La première est la plus simple et marche relativement bien si la mémoire de la clé USB est rapide. La seconde façon est plus confortable car elle ne dépend pas de la clé USB mais réclame un ordinateur plus puissant pour faire tourner le système d'exploitation virtualisé. Je ne rentrerai pas dans la création d'une Live USB ou d'une machine virtuelle. Dans ces deux cas demandez-moi par mail et je vous guiderai dans les étapes les plus importantes.

Mon environnement de développement est ainsi : • Ubuntu 16.04 LTS. • Aquaris E4.5 avec OTA-14. • Aquaris E5 HD avec OTA-14. • Aquaris M10 FHD avec OTA-14.

Il est possible que dans d'autres distributions il y ait quelques étapes intermédiaires à faire pour configurer le SDK. Si c'est le cas, vous pouvez nous les indiquer.

Installing the Ubuntu Touch SDK Installing the SDK is very simple and should not take more than a couple of minutes. It is advisable to have the system updated before you start. In the case of Ubuntu, this can be done with the commands: sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade You use sudo because package installation requires administrator permissions. The first command updates the list of repositories. If there is no error, the second command is executed, which is responsible for updating the applications. Finally, the third command updates some operating system packages that are not updated by default.

Installer le SDK d'Ubuntu Touch

L'installation du SDK est très simple et ne devrait pas prendre plus de quelques minutes. Il est conseillé d'avoir mis à jour le système avant de commencer. Dans le cas d'Ubuntu, ceci peut être fait avec les commandes :

sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade

Vous utilisez sudo parce que l'installation des paquets requiert des permissions d'administrateur. La première commande met à jour la liste des dépôts. S'il n'y a pas d'erreur, la seconde commande est exécutée, qui est responsable de la mise à jour des applications. Enfin, la troisième commande met à jour certains paquets du système d'exploitation qui ne sont pas mis à jour par défaut.

Add the Ubuntu Touch SDK repository with the command: sudo add-apt-repository ppa:ubuntu-sdk-team/ppa The repository information will be displayed. You can continue by pressing the ENTER key. All repositories have a signature that assures us that the installed packages come from the repository. This signature is added to the system and will be used when repository packages are installed. After adding a repository, it is necessary to update the information of the packages that it contains. You can do this with the command: sudo apt-get update Everything is ready. The last step of this section is to install the Ubuntu Touch SDK. sudo apt-get install ubuntu-sdk Although only one package (ubuntu-sdk) is put in the command, all the dependencies of that package are automatically installed, so it works without problems. The installation may take a while depending on the Internet connection. It's a good time to let the computer work and have a good coffee.

Ajoutez le dépôt du SDK d'Ubuntu Touch avec la commande :

sudo add-apt-repository ppa:ubuntu-sdk-team/ppa

L'information sur le dépôt sera affichée. Vous pouvez continuer en appuyant sur la touche Entrée.

TYous les dépôts ont une signature qui nous assure que les paquets installés viennent de ce dépôt. La signature est ajoutée au système et sera utilisée quand les paquets du dépôt seront installés.

Après avoir ajouté un dépôt, il est nécessaire de mettre à jour l'information sur les paquets qu'il contient.. Vous pouvez le faire avec la commande :

sudo apt-get update

Tout est prêt. La dernière étape de cette section est l'installation du SDK d'Ubuntu Touch.

sudo apt-get install ubuntu-sdk

Bien qu'un seul paquet ait été mis dans la commande, toutes les dépendances de ce paquet sont automatiquement installées, pour fonctionner sans problème. L'installation peut prendre un petit peu de temps suivant la connexion Internet. C'est le bon moment pour laisser travailler l'ordinateur et prendre un bon café.

Setting up the Environment The Ubuntu Touch SDK includes tools to generate applications, and an editor to make programming easier. The tools take the source code of the application and process it. If the target is a computer there is no problem. However, if the target is a device that uses Ubuntu Touch, we are in a different scenario. These devices use the ARM architecture, which is different from the one used by the PC. To generate the executable, you have to use a cross-compiler that runs in a container (LXD in the latest versions of the SDK). To work with LXD, you have to add the user (that is used on the computer) to the group lxd. sudo usermod -a -G lxd user After writing the command, you have to close the user's session and log in again. You can start working with this small modification. To start, we need to run the ubuntu-sdk-ide application; it can be launched from the desktop start menu, or by pressing ALT + F2 and typing its name. The first time it’s launched, a screen appears asking which lxd has to be configured. Just press ‘Yes’ to generate the default configuration. If the user is not in the lxd group, the following screen error will appar. In that case, it is sufficient to log out and log in again. When launching, the IDE of Ubuntu Touch should give you no errors.

Configuration Wizard The first screen (shown below) of the wizard is an introduction to Qt Creator. To continue, click the ‘Next’ button. Although the course is focused on mobile devices such as phones or tablets, you may also apply the knowledge learned to create desktop applications. Each of these devices has an associated ki – a set of tools which is based on the code that is programmed and generates the necessary files for each device (screen shown bottom). Click the ‘Create new Kit button’ (shown above). The first option must be selected. In the list (below), there are several kits to download. Ubuntu Touch is currently based on Vivid so you have to select that option. Finally (bottom left), write the name of the kit. When you complete the last step, you return to the initial screen of the kits. Press the ‘Create new Kit’ button again and repeat the process by selecting Ubuntu Device.

With this kit, there are more options to choose from. Phones or tablets that use Ubuntu Touch work with the armhf architecture. In the list, you have to select a kit that has that architecture. The version of Ubuntu Touch is Vivid, as in the previous case. Finally, you have to choose 686 or x64 depending on whether the computer uses 32 or 64 bits. After pressing the ‘Next’ button, you must write the Kit name. At this time it is not necessary to create additional kits (below). In the last step of the wizard (bottom), you can configure the physical devices and the emulator. There are some problems with the emulator. For now, I recommend not to configure the emulator. Applications can be tested natively on the computer. For this reason, you must uncheck the ‘Create emulator’ box, and click on the ‘Finish’ button.

Hello World In order to keep the good traditions, the first step is to program a minimal application that allows us to check the correct operation of the SDK. The application will run on the computer natively and on a tablet. As you will see, it is quite simple to do it. Kits are updated frequently. If the screen above appears, all the kits must be marked and updated.

Project Creation Click on the File menu, New file or project. A window (below) will appear with the types of projects that can be used. The user interface is made with QML which is a scripting language oriented to the creation of graphical interfaces. The logic of the application can be done with several languages. JavaScript will be used for now. Select the first option and then click on the ‘Choose’ button. You must choose the folder in which the projects will be saved. The project name cannot contain spaces. Applications need basic information: user and maintainer. All other parameters should be left at their defaults. It is important to respect the structure in the Maintainer field so that it allows us to continue. You have to select the kits that you want to use. By default, the two will be selected in order to run the application on the computer and on the mobile device. The last screen contains a summary of the wizard steps. Click on the ‘Finish’ button. The project (shown below) will open automatically. Running the Application on Your Computer To run the application you have to press the ‘Play’ button in the lower left part of Qt Creator.

Running the Application on a Real Device Before running the application, it is necessary to configure the device. For testing, I have used an Aquaris M10 FHD tablet with the OTA-14 —although the procedure is the same on the other devices. Leave ubuntu-sdk-ide open and connect the device via USB to the computer. To activate the development options, access the System Settings. Click on About. Select Developer Mode. This mode is disabled by default because it allows remote control of the device if it is connected by USB to the computer. Check the box. After a few seconds, a notification must appear with the connection request of the computer. You have now completed all the steps on the side of the tablet. In the IDE, you must select the tablet as the compilation target. To do this, click on the button above the Play, and select the device we just configured as the destination.

A few seconds after pressing the Play button, the application will appear on the device. The error shown in the above image may appear. In the sidebar of Qt Creator, you have to click on the ‘Devices’ button. Then click on the device and Kits click on the ‘Remove’ button. Then click on the ‘Create’ button. Now you have to associate the Kit back to the Project. Click on ‘Projects’ (on the sidebar), ‘Add Kit,’ and select the Kit that appears in the dropdown. Wait a couple of seconds and select the device as the compilation target. It is important that you try the compilation in both cases. In the next chapter, I will start with the source code and assume that everything works correctly on both the computer and the test device. If you have any problems you can ask on the mailing list.

Resources Mailing List: https://launchpad.net/~ubuntu-touch-programming-course People who have collaborated Larrea Mikel: revision of the chapter in Spanish. Cesar Herrera: revision of the English translation. Joan CiberSheep: revision of the English translation.

issue119/ubuntu_touch.1492085952.txt.gz · Dernière modification : 2017/04/13 14:19 de d52fr