Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug...
Transcript of Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug...
![Page 1: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/1.jpg)
Android : Architecture - Compilation - Debug 1 / 31
Android :Architecture - Compilation - Debug
Sylvain Jubertie - Universite d’Orleans
2011-2012
![Page 2: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/2.jpg)
Android : Architecture - Compilation - Debug 2 / 31
1 Installation des outils
2 Creation d’un projet
3 Compilation d’un projet
4 Installation d’une application
5 Debugging
6 Distribution
![Page 3: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/3.jpg)
Android : Architecture - Compilation - Debug 3 / 31
Installation des outils
1 Installation des outils
2 Creation d’un projet
3 Compilation d’un projet
4 Installation d’une application
5 Debugging
6 Distribution
![Page 4: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/4.jpg)
Android : Architecture - Compilation - Debug 4 / 31
Installation des outils
Installation du SDK et du NDK
1 Telecharger les archives suivantes :
Android SDK : Software Development KitAndroid NDK : Native Development Kit
a partir du site http://developer.android.com
2 decompresser les archives
3 mettre a jour la variable d’environnement PATH :
PATH=$PATH:path_to_android-sdk/tools: \
path_to_android-sdk/platform-tools: \
path_to_android-ndk
Attention
Ces archives ne sont pas suffisantes pour developper !
![Page 5: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/5.jpg)
Android : Architecture - Compilation - Debug 5 / 31
Installation des outils
Installation des plateformes
Chaque developpement pour une version d’Android necessitel’installation de la plateforme correspondante :
1 lancer la commande android
2 dans la rubrique Available packages choisir les plateformesAndroid cibles a installer : SDK Platform, samples, doc
![Page 6: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/6.jpg)
Android : Architecture - Compilation - Debug 6 / 31
Installation des outils
Emulateur
Le SDK fournit un emulateur de peripherique Androidconfigurable :
version d’Android
dimension de l’ecran
taille memoire
support de peripheriques
. . .
Une configuration pour cet emulateur est se nomme un AVD :Android Virtual Device.
![Page 7: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/7.jpg)
Android : Architecture - Compilation - Debug 7 / 31
Installation des outils
Creation d’un AVD Android Virtual Device
Dans la rubrique Virtual devices, choisir New... et configurerun AVD : nom, version d’Android (Target), . . .
Une fois cree, l’AVD peut etre lance par Start...
![Page 8: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/8.jpg)
Android : Architecture - Compilation - Debug 8 / 31
Installation des outils
![Page 9: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/9.jpg)
Android : Architecture - Compilation - Debug 9 / 31
Installation des outils
Inconvenient
L’emulateur est extremement lent !Plus loin : test/debuggage directement sur le device.
![Page 10: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/10.jpg)
Android : Architecture - Compilation - Debug 10 / 31
Creation d’un projet
1 Installation des outils
2 Creation d’un projet
3 Compilation d’un projet
4 Installation d’une application
5 Debugging
6 Distribution
![Page 11: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/11.jpg)
Android : Architecture - Compilation - Debug 11 / 31
Creation d’un projet
Choix de la plateforme cible
Choix de la plateforme cible
Un projet est cree pour une cible parmi les cibles installees. La listedes cibles s’obtient par la commande : android list targets
Exemple
$ android list targets
Available Android targets:
id: 1 or "android-13"
Name: Android 3.2
Type: Platform
API level: 13
Revision: 1
Skins: WXGA (default)
![Page 12: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/12.jpg)
Android : Architecture - Compilation - Debug 12 / 31
Creation d’un projet
Application
Creation d’un projet
Dans un nouveau dossier :
android create project \
--target <target_ID> \
--name <project_name> \
--path path/to/your/project \
--activity <activity_name> \
--package <package_namespace>
![Page 13: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/13.jpg)
Android : Architecture - Compilation - Debug 13 / 31
Creation d’un projet
Application
Arborescence d’un projet
Dossiers crees automatiquement lors de la creation d’un projet :
bin : binaires generes
libs : bibliotheques
res : fichiers de ressources (icones, layout, . . . )
src : fichiers sources (code Java)
![Page 14: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/14.jpg)
Android : Architecture - Compilation - Debug 14 / 31
Creation d’un projet
Application
Fichiers generes
Les fichiers suivants sont crees automatiquement lors de la creationd’un projet :
AndroidManifest.xml
build.properties
build.xml
default.properties
local.properties
proguard.cfg
![Page 15: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/15.jpg)
Android : Architecture - Compilation - Debug 15 / 31
Creation d’un projet
Application
Modification d’un projet
En cas de modification du nom d’un projet, de la cible ou duchemin :
a n d r o i d update p r o j e c t \−−name <y o u r p r o j e c t n a m e> \−−t a r g e t <t a r g e t I D > \−−path path / to / your / p r o j e c t
![Page 16: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/16.jpg)
Android : Architecture - Compilation - Debug 16 / 31
Creation d’un projet
Bibliotheque
Creation d’une bibliotheque
De maniere similaire a un projet standard :
android create lib-project --name <your_project_name> \
--target <target_ID> \
--path path/to/your/project \
--package <your_library_package_namespace>
![Page 17: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/17.jpg)
Android : Architecture - Compilation - Debug 17 / 31
Creation d’un projet
Integration de code natif
Integration de code natif
repose sur JNI Java Native Interface
supporte les jeux d’instructions : ARMv5TE, ARMv7-A,x86
reutilisation de bibliotheques C/C++
amelioration de performance sur des codes de calculs
OpenGL
NEON
attention a la gestion memoire !
![Page 18: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/18.jpg)
Android : Architecture - Compilation - Debug 18 / 31
Creation d’un projet
Integration de code natif
Principe de l’integration de code natif
1 Ecrire un code natif C/C++ + wrapper JNI
2 Le code natif C/C++ est compile sous forme de bibliothequedynamique .so
3 Une bibliotheque est generee par architecture desiree
4 Le ou les bibliotheques .so sont integrees a l’applicationAndroid
5 La bibliotheque correspondant au materiel et a laconfiguration du systeme Android hote est automatiquementappelee lors de l’appel a la methode native
Implications
Augmentation de la taille de l’application
Si une bibliotheque est generee pour le jeu ARMv7-A,l’application ne fonctionnera pas sur les processeur plusanciens ne supportant que le jeu ARMv5TE. . .
Il est possible de generer et distribuer plusieurs applicationsadaptees chacune a un jeu d’instructions pour optimiser lataille de chaque application
![Page 19: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/19.jpg)
Android : Architecture - Compilation - Debug 19 / 31
Creation d’un projet
Integration de code natif
Integration dans un projet Android
1 Creer un dossier jni a la racine du projet, puis dans cedossier,
2 placer les fichiers C/C++
3 creer un fichier Android.mk (fichier Makefile) qui permettrade generer la bibliotheque
4 Dans le code Java de l’application, creer un wrapper vers lesfonctions natives (partie abordee plus tard)
![Page 20: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/20.jpg)
Android : Architecture - Compilation - Debug 20 / 31
Compilation d’un projet
1 Installation des outils
2 Creation d’un projet
3 Compilation d’un projet
4 Installation d’une application
5 Debugging
6 Distribution
![Page 21: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/21.jpg)
Android : Architecture - Compilation - Debug 21 / 31
Compilation d’un projet
![Page 22: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/22.jpg)
Android : Architecture - Compilation - Debug 22 / 31
Compilation d’un projet
Etapes et commandes pour la compilation
1 Si du code natif est present, generer la ou les bibliotheques :ndk-build
Les bibliotheques sont placees dans un sous-dossier du dossierlib
2 Compiler le code Java et generer un package .apk :ant {debug | release}Choisir debug ou release suivant le mode desire
![Page 23: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/23.jpg)
Android : Architecture - Compilation - Debug 23 / 31
Compilation d’un projet
Modes de compilation
debug : l’application est automatiquement signee avec une clede debug connue
release : l’application n’est pas signee
Le mode debug permet de deployer rapidement une application lorsde la phase de debug.Le mode release indique que l’on souhaite diffuser l’applicationgeneree qui doit alors etre signee avec une cle privee (cf sectionDistribution).
![Page 24: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/24.jpg)
Android : Architecture - Compilation - Debug 24 / 31
Compilation d’un projet
Explications sur l’alignement
Pour ameliorer les performances des applications il convientd’aligner correctement les donnees en memoire pour diminuer lenombre de lecture.Cette contrainte est liee au bus memoire qui accede aux donneespar blocs contigus de 32 bits (en general) soit 4 octets.
Alignement de l’application
Pour aligner sur 4 octets, utiliser la commande :zipalign -v 4 unsigned.apk signed.apk
![Page 25: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/25.jpg)
Android : Architecture - Compilation - Debug 25 / 31
Installation d’une application
1 Installation des outils
2 Creation d’un projet
3 Compilation d’un projet
4 Installation d’une application
5 Debugging
6 Distribution
![Page 26: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/26.jpg)
Android : Architecture - Compilation - Debug 26 / 31
Installation d’une application
Installation
Une application est installee sur un AVD ou sur un materiel a l’aidede la commande :adb install <package>.apk
Si plusieurs AVD ou materiels
Il est possible d’utiliser les options -s et -d pour specifierrespectivement les identifiants de l’AVD ou du peripherique cible.
![Page 27: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/27.jpg)
Android : Architecture - Compilation - Debug 27 / 31
Installation d’une application
Liste des peripheriques
adb devices
![Page 28: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/28.jpg)
Android : Architecture - Compilation - Debug 28 / 31
Debugging
1 Installation des outils
2 Creation d’un projet
3 Compilation d’un projet
4 Installation d’une application
5 Debugging
6 Distribution
![Page 29: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/29.jpg)
Android : Architecture - Compilation - Debug 29 / 31
Debugging
ADB Android Debug Bridge
L’outil en ligne de commande adb permet d’obtenir desinformations de debuggage.
![Page 30: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/30.jpg)
Android : Architecture - Compilation - Debug 30 / 31
Distribution
1 Installation des outils
2 Creation d’un projet
3 Compilation d’un projet
4 Installation d’une application
5 Debugging
6 Distribution
![Page 31: Android : Architecture - Compilation - · PDF fileAndroid : Architecture - Compilation - Debug 3/31 Installation des outils 1 Installation des outils 2 Creation d’un projet 3 Compilation](https://reader031.fdocuments.us/reader031/viewer/2022030503/5aaf9e237f8b9adb688dd473/html5/thumbnails/31.jpg)
Android : Architecture - Compilation - Debug 31 / 31
Distribution
Generation d’une cle
keytool -genkey -v -keystore path to keystore -alias
rkey -keyalg RSA -keysize ... -validity ...
Signature
jarsigner -verbose -keystore path to keystore
-signedjar signed.apk unsigned.apk rkey