developing android tips and tricks
DESCRIPTION
androidTRANSCRIPT
-
Developing Androidtips and tricks
Amarula Solutions BV
Alberto [email protected]
-
Alberto Panizzo 2/53www.amarulasolutions.com
Who am IAlberto [email protected] Degree:
Ing. Informatica @ Padova2010 Joined Penguin Group:
Group of professionals in Linux/Embedded that aimed to conquer the world
2011- CTO Co-Founder at Amarula SolutionsSeveral porting of Linux/Android on industrial mobile devices from boot to apps
10+ Years experience of Linux, 5 Years with Android/ARM
-
Alberto Panizzo 3/53www.amarulasolutions.com
Overview Squeezed intro about Android Managing the sources Drive the Build System Interaction with the target Debug and Trace Misc things Other thoughts Q/A
-
Alberto Panizzo 4/53www.amarulasolutions.com
Devices ecosystem
-
Alberto Panizzo 5/53www.amarulasolutions.com
Devices ecosystem
-
Alberto Panizzo 6/53www.amarulasolutions.com
Devices ecosystem
DARTPXA320
RP1100S5PV210
-
Alberto Panizzo 7/53www.amarulasolutions.com
Architecture
-
Alberto Panizzo 8/53www.amarulasolutions.com
Overview Squeezed intro about Android Managing the sources Drive the Build System Interaction with the target Debug and Trace Misc things Other thoughts Q/A
-
Alberto Panizzo 9/53www.amarulasolutions.com
Managing the sources Git Repo
-
Alberto Panizzo 10/53www.amarulasolutions.com
Git Android use git to manage ALL
sub-projects Better you know git, easier will be your life A lot of documentation of git:
man$ man git $ man git
Cheat Sheetshttps://git.wiki.kernel.org/index.php/GitCheatSheet
Book Pro Githttp://git-scm.com/book
-
Alberto Panizzo 11/53www.amarulasolutions.com
GitUseful but uncommon git cmds:
git clone --reference # To save bandwith and # time
git add -p # To add single changesgit add -p file-name # from a file
git stash # To modify a patch git rebase --interactive ^ # already queued
git reflog # To do not miss anything
-
Alberto Panizzo 12/53www.amarulasolutions.com
Repo Python wrapper to git that manage
projects made of multiple git sub-projects Uses an XML manifest to describe the prj The manifest itself is kept with git Start from a good manifest!
OSS is code reusing as well so start from a good codebase to easy your life
-
Alberto Panizzo 13/53www.amarulasolutions.com
RepoInstall:$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo >
~/bin/repo && PATH=~/bin:$PATH
Setup a local repository:$ mkdir local-prj && cd local-prj$ repo init -u [-b branch-to-use] [-m mname]
Checkout and update against remote:$ repo sync
-
Alberto Panizzo 14/53www.amarulasolutions.com
RepoInteresting things:
Look at what is happening in sub-projects .git dir:$ ls -l build/.gittotal 64-rw-rw-r-- 1 alberto alberto 80 Jul 2 19:22 COMMIT_EDITMSGlrwxrwxrwx 1 alberto alberto 37 Dec 3 2012 config ->
../../.repo/projects/build.git/configlrwxrwxrwx 1 alberto alberto 42 Dec 3 2012 description ->
../../.repo/projects/build.git/description-rw-rw-r-- 1 alberto alberto 34 Apr 10 18:54 HEADlrwxrwxrwx 1 alberto alberto 36 Dec 3 2012 hooks ->
../../.repo/projects/build.git/hooks-rw-rw-r-- 1 alberto alberto 57072 Jul 2 19:22 indexlrwxrwxrwx 1 alberto alberto 35 Dec 3 2012 info ->
../../.repo/projects/build.git/info
the real git index is inside .repo !!+ To checkout fast a new Android version, re-use
the previous .repo dir- Do not do use git clone with projects you want to add
-
Alberto Panizzo 15/53www.amarulasolutions.com
Repo manifestsSetup a git project with default.xml like:
...
-
Alberto Panizzo 16/53www.amarulasolutions.com
Repo manifestsAdd locally projects to the tree
Add manifests in: .repo/local_manifests/name.xml
...
-
Alberto Panizzo 17/53www.amarulasolutions.com
Overview Squeezed intro about Android Managing the sources Drive the Build System Interaction with the target Debug and Trace Misc things Other thoughts Q/A
-
Alberto Panizzo 18/53www.amarulasolutions.com
Drive the Build System Setup the environment Interesting functions Interesting targets Add projects to the build Add custom global dependencies A Revelation
-
Alberto Panizzo 19/53www.amarulasolutions.com
Setup the environmentBefore start working do source: . build/envsetup.sh
Interesting tools gained: lunch [combo-string] [combo-idx] mm # Build all modules below the
# current path mmm path:module # Build only module within path
... hmm # Enumerate all tools
-
Alberto Panizzo 20/53www.amarulasolutions.com
Interesting targetsThese are make targets:
make sdk # Build an sdk with the current api
make showcommands # Show full cmd line for build # steps
make otapackage # Build installation packages but # pray your HW is not so different
make droid # Default build target
-
Alberto Panizzo 21/53www.amarulasolutions.com
Adding a project to the buildThis for a java App:
Move your freaky app to packages/apps/MyApp Create packages/apps/MyApp/Android.mk as:
Build it with: mmm packages/apps/MyApp
LOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optionalLOCAL_SRC_FILES := $(call all-java-files-under, src)LOCAL_PACKAGE_NAME := MyApp LOCAL_CERTIFICATE := platform
include $(BUILD_PACKAGE)
-
Alberto Panizzo 22/53www.amarulasolutions.com
Add custom global dependenciesIn build/core/main.mk:
Add dependencies to droid OR Add a target that depends on droid OR Define a target before droid and depend on this
-
Alberto Panizzo 23/53www.amarulasolutions.com
A RevelationAdd custom dependencies to a LOCAL_MODULE:
LOCAL_ADDITIONAL_DEPENDENCIES := mydep
include $(BUILD_EXECUTABLE)
.PHONY: mydep
mydep:echo Is that strong your faith to think this is a Revelation??
I accept cash or money transfers for this revelation :D $$
-
Alberto Panizzo 24/53www.amarulasolutions.com
Overview Squeezed intro about Android Managing the sources Drive the Build System Interaction with the target Debug and Trace Misc things Other thoughts Q/A
-
Alberto Panizzo 25/53www.amarulasolutions.com
Interaction with the target Bootloader level: Fastboot Holy Grail: adb Android shell
-
Alberto Panizzo 26/53www.amarulasolutions.com
Fastboot Nice tool/protocol to speak to the bootloader Uses USB interface ++Speed!! Several reference integrations to u-boot
Samsung s5pv210: https://code.google.com/p/x210ii/
TI OMAP: http://www.omappedia.com/wiki/Android_Fastboot
None on uboot mainline Used to do raw flashing / boot images /
execute custom boot.img
-
Alberto Panizzo 27/53www.amarulasolutions.com
Adb Main OS-layer debug tool Common adb commands:
Obtain a shell:$ adb shell
Obtain a root shell in userdebug builds:$ adb root ; adb shell
Push pull files to the device:$ adb [push|pull]
Install/Uninstall packages:$ adb [install|uninstall]
-
Alberto Panizzo 28/53www.amarulasolutions.com
Adb Useful adb commands:
Use TCPIP transport:$ adb tcpip 5555It does set the properties:
persist.adb.tcp.port and service.adb.tcp.port to 5555and restart device's adb server
On the workstation do:$ export ADBHOST=192.168.X.XXX$ adb kill-server ; adb devices
-
Alberto Panizzo 29/53www.amarulasolutions.com
A note on the shell Until 2.3 Android had the light bare ash
system/core/sh Not even test was built in!!
[ $? != 0 ] && echo ERROR # Ehm.. IMPOSSIBLE Auto-completion ? Where are you coming from? Mars??
Since v3 Android has the powerful mksh external/mksh/ Even Arithmetics!!
root@android:/ # echo $(( 1 + 1 )) 2
The paradise is here!
-
Alberto Panizzo 30/53www.amarulasolutions.com
Overview Squeezed intro about Android Managing the sources Drive the Build System Interaction with the target Debug and Trace Misc things Other thoughts Q/A
-
Alberto Panizzo 31/53www.amarulasolutions.com
Debug and Trace Logging
Kernel (dmesg) Logcat
Debug traces Refresh libs
-
Alberto Panizzo 32/53www.amarulasolutions.com
Kernel log You can do dmesg only if you are root
No dmesg on production builds:# su 2000 dmesgklogctl: Operation not permitted
While developing the kernel cmdline have. debug no_console_suspend
Turn on CONFIG_PRINTK_TIME for timestamps Can output to /dev/kmsg to synchronize
userspace logging with kernel domain
-
Alberto Panizzo 33/53www.amarulasolutions.com
Logcat Unified logging method for userspace Easy to use within C/C++/Java code
Google give thousands of pages of code that use this Interesting tool to log from the target shell:
# log -hUSAGE: log [-p priorityChar] [-t tag] message
priorityChar should be one of:v,d,i,w,e
Multiple buffersmain, radio, events, system
-
Alberto Panizzo 34/53www.amarulasolutions.com
Logcat OK main is where all my usual logs goes
and radio contain logs with radio tags..grep -rns RIL system/core/liblog/
But system ?Contain logs written to main as well but filter on framework known tags
And events ?Contain PowerManager, battery, notifications events
import android.util.EventLog;
EventLog.writeEvent(TAG, 1, log message);
-
Alberto Panizzo 35/53www.amarulasolutions.com
Logcat Get the logs from workstation:
$ adb logcat [-b buffer_name] [-v time] [filterspecs]where filterspecs is something like:
Tag:V *:sif there is no *:s the filter does not apply at all..
Clear the device buffer:$ adb logcat [-b buffer_name] -c
Synchronize logcat with kernel log:# logcat -c ; logcat -b radio -v time > /dev/kmsg &
-
Alberto Panizzo 36/53www.amarulasolutions.com
Logcat
-
Alberto Panizzo 37/53www.amarulasolutions.com
Logcat
-
Alberto Panizzo 38/53www.amarulasolutions.com
Logcat#/bin/bash# logcat_color.sh: Simple but effective way to # colorize logcat in shell
adb logcat -v time $@ | while read line ; dolevel=`echo $line | sed -e "s/^[0-9|\.| |-|:|-]*//"`level=`echo ${level:0:2}`case $level in'V/') echo -e "\033[0m$line\033[0m";;'D/') echo -e "\033[34m$line\033[0m" ;;'I/') echo -e "\033[32m$line\033[0m" ;;'W/') echo -e "\033[33m$line\033[0m" ;;'E/') echo -e "\033[31m$line\033[0m" ;;*) echo -e "\033[1m$line\033[0m";;esac
done
-
Alberto Panizzo 39/53www.amarulasolutions.com
Trace dumpsThanks to rxwen agdb.py translate this:
with: $ adb logcat | agdb.py -rin..
I/DEBUG ( 30): Build fingerprint: 'generic/generic/generic:2.3.1/GINGERBREAD/'I/DEBUG ( 30): pid: 33, tid: 450>>> /system/bin/mediaserver
-
Alberto Panizzo 40/53www.amarulasolutions.com
Trace dumps
Make sure service debuggerd is running!
https://code.google.com/p/rxwen-blog-stuff/ source/browse/trunk/tools/agdb.py
I/DEBUG ( 30): Build fingerprint: 'generic/generic/generic:2.3.1/GINGERBREAD/I/DEBUG ( 30): pid: 33, tid: 450 >>> /system/bin/mediaserver
-
Alberto Panizzo 41/53www.amarulasolutions.com
Build/install/refresh a libBuild:$ mmm frameworks/base/services/input/:libinputInstall: out/target/product/rp1100/system/lib/libinput.soInstall:$ adb push out/target/product/rp1100/system/lib/libinput.soRefresh:$ adb shell stop$ adb shell ps -g servicemanagerUSER PID PPID VSIZE RSS WCHAN PC NAMEsystem 68 1 904 332 ffffffff 00000000 S /system/bin/servicemanager
$ adb shell kill 68
-
Alberto Panizzo 42/53www.amarulasolutions.com
Overview Squeezed intro about Android Managing the sources Drive the Build System Interaction with the target Debug and Trace Misc things Other thoughts Q/A
-
Alberto Panizzo 43/53www.amarulasolutions.com
Misc things Memory usage Environment
-
Alberto Panizzo 44/53www.amarulasolutions.com
Memory usageHaving a root shell we can use procrank:
root@android:/ # /data/local/tmp/procrank -u PID Vss Rss Pss Uss cmdline 427 57900K 57836K 23880K 19532K com.android.launcher 286 52808K 52792K 20163K 15396K system_server 75 23904K 21504K 12528K 7104K /system/bin/surfaceflinger 474 37408K 37324K 8249K 5680K android.process.acore 76 38064K 37924K 6988K 4060K zygote... 67 480K 476K 267K 260K /system/bin/sh 1522 200K 200K 176K 172K /sbin/adbd 74 392K 388K 140K 132K /system/bin/debuggerd 84 360K 356K 127K 120K /system/bin/sdcard 1 216K 216K 152K 108K /init 62 172K 172K 124K 80K /sbin/ueventd ------ ------ ------ 189241K 137972K TOTAL
-
Alberto Panizzo 45/53www.amarulasolutions.com
Memory usageProcrank can sort by:
VSS: All the Virtual memory addressed by the processRSS: Memory that relies into the RAMPSS: Common objects are added to process buckets proportionallyUSS: Portion of the process memory space addressed only by this process
-
Alberto Panizzo 46/53www.amarulasolutions.com
Memory usageOn non root shell?
# su 2000 /data/local/tmp/procrank -u Error creating kernel interface -- does this kernel have pagemap?
For dalvik packages we still can use:dumpsys meminfo package_name
-
Alberto Panizzo 47/53www.amarulasolutions.com
Memory usage# su 2000 dumpsys meminfo com.android.launcher Applications Memory Usage (kB):Uptime: 80536220 Realtime: 122556573
** MEMINFO in pid 427 [com.android.launcher] ** Shared Private Heap Heap Heap Pss Dirty Dirty Size Alloc Free ------ ------ ------ ------ ------ ------ Native 16 8 16 5472 3913 359 Dalvik 4532 10780 4028 11271 9931 1340 Cursor 0 0 0 Ashmem 0 0 0 Other dev 14196 4832 6772 .so mmap 1258 2160 508 .jar mmap 0 0 0 .apk mmap 511 0 0 .ttf mmap 5 0 0 .dex mmap 0 0 0 Other mmap 1276 20 40 Unknown 1953 940 1912 TOTAL 23747 18740 13276 16743 13844 1699
...
-
Alberto Panizzo 48/53www.amarulasolutions.com
Shell EnvironmentDefault is defined by /init.rc
All procs forked from init inherit this env
...export PATH /sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbinexport LD_LIBRARY_PATH /vendor/lib:/system/libexport ANDROID_BOOTLOGO 1export ANDROID_ROOT /systemexport ANDROID_ASSETS /system/appexport ANDROID_DATA /dataexport ASEC_MOUNTPOINT /mnt/asecexport LOOP_MOUNTPOINT /mnt/obbexport BOOTCLASSPATH /system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar...
-
Alberto Panizzo 49/53www.amarulasolutions.com
Shell EnvironmentFrom a shell we can override the def environment at least for our forks:
$ adb push myprogram /data/local/tmp$ adb push libmy.so /data/local/tmp
# export LD_LIBRARY_PATH=/data/local/tmp:\$LD_LIBRARY_PATH
# /data/local/tmp/myprogram
-
Alberto Panizzo 50/53www.amarulasolutions.com
Overview Squeezed intro about Android Managing the sources Drive the Build System Interaction with the target Debug and Trace Misc things Other thoughts Q/A
-
Alberto Panizzo 51/53www.amarulasolutions.com
Other thoughts
THROW EVERYTHING!!
HTML5 IS COMINGTizen, Ubuntu Mobile
My opinion? At least not in 2 years
-
Alberto Panizzo 52/53www.amarulasolutions.com
Resources
http://source.android.com/All needed to start developAndroid
http://developer.android.comAll you need to develop applicationsfor Android
http://developer.android.com/about/dashboards/index.htmlUpdated infos about Android installations
http://elinux.org/images/c/c9/Android-tips-and-tricks-2010-10.pdfThanks to Tim Bird and his inspiring talk at ELCE 2010
http://developer.android.com/about/dashboards/index.htmlUpdated infos about Android installations
http://elinux.org/Android_PortalLot of non official stuffs around Android
-
Alberto Panizzo 53/53www.amarulasolutions.com
Q/A
Thanks for your time
Questions and Answers
Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Slide 44Slide 45Slide 46Slide 47Slide 48Slide 49Slide 50Slide 51Slide 52Slide 53