This post intends to gather all the information you need to start a project on Android. It is not tied to a specific version but instead tries to be generic across all of them.
Development environment
Before being able to develop on Android, we need to set up the development environment. This section will differentiate two types of development: system and application. The reason is that some costumers are just interested in developing an Android application on top of our system release without modifying the system.
System development
If you wish to build the entire Android system from scratch, know that it requires a Linux machine or at least a Linux Virtual Machine (VM). Mac OS systems are also supported but will not be covered on this post.
The Android Open-Source Project (AOSP) provides a website with lots of useful information about Android system development.
Regarding the development environment, you need to first make sure to comply with the AOSP recommendations. Note that it requires a 64-bit version of Linux.
Note that for building versions prior to Lollipop, the page above has incomplete instructions for Java versions on newer Ubuntu machine. For building Android v2.3 to v4.4.4, you’ll need the Sun Java development kit (JDK 1.6). You can install using by following the instructions provided in the following post.
Building Lollipop version or above only requires to have OpenJDK v7.
~$ sudo apt-get install openjdk-7-jdk
In addition to the AOSP requirements, the following packages are needed to build Freescale components:
~$ sudo apt-get install uuid uuid-dev zip lzop gperf zlib1g-dev \ liblz-dev liblzo2-2 liblzo2-dev u-boot-tools lib32z1 flex git-core curl
Next step is downloading the source code. To do so you need the repo
tool which has been developed especially for Android in order to manage the hundreds of Git repositories this project contains.
- https://source.android.com/source/downloading.html
~/$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo \ > ~/bin/repo ~/$ chmod a+x ~/bin/repo ~/$ export PATH=~/bin/repo:$PATH
The lasts steps before being able to download the Android source code for our platforms are:
Then you can retrieve the entire tree. Note that you need a lot of space, Google says “at least 100GB of free disk space for a checkout, 150GB for a single build”.
~/$ mkdir myandroid ~/$ cd myandroid ~/myandroid$ ~/bin/repo init -u git://github.com/boundarydevices/android-manifest.git -b boundary-imx-l5.0.0_1.0.0-ga ~/myandroid$ repo sync
Note that the repo init
command above will change depending on the version of Android you want to build. The -b
parameter selects which branch of our manifest repository to use.
Your machine is now ready to build a fresh Android image from scratch!
Application development
Setting up a machine for application development is much easier plus it works the same on every OS: Windows, Linux, Mac OS.
Although application development IDE used to be Eclipse along with a plugin named ADT, this has been deprecated in favour of Android Studio.
Download this IDE along with the Android SDK from the following website:
Note that this site provides the API guide as well as lots of app examples which are directly available in the IDE as part of the SDK.
Image may be NSFW.
Clik here to view.
Debugging Tools
The most important tool that Android offers is the Android Debug Bridge (ADB). It is mandatory to set it up as the IDE requires it in order to install/debug applications. It is also useful for system development as it allows to access the board easily, allowing to send files back and forth between the target and the host machine for instance.
Under GNU/Linux systems (and specifically under Ubuntu systems), regular users can’t directly access USB devices by default. The system needs to be configured to allow such access. Please follow the instructions from the AOSP website to authorize USB access to most common devices.
Details about the tool and all the commands available:
A couple of other tools might be of interest depending on your needs.
- dumpsys: provides information about the status of system services.
- systrace: analyzes the performance of your application by capturing and displaying execution times
- http://developer.android.com/tools/help/systrace.html
- systrace requires to modify the kernel configuration and add
- FUNCTION_TRACER
- FUNCTION_GRAPH_TRACER
- DYNAMIC_FTRACE
- STACK_TRACER
Image may be NSFW.
Clik here to view.
Build instructions
AOSP build
Initialize the environment with the envsetup.sh
script.
~/myandroid$ source build/envsetup.sh
This script gives you access to a new set of commands targeted for AOSP development. Below are detailed the most useful ones (in our opinion).
croot
: Changes directory to the top of the tree (useful when you get lost inframeworks/base
)mm
: Builds all of the modules in the current directorymmm
: Builds all of the modules in the supplied directoriescgrep
: Greps on all local C/C++ filesjgrep
: Greps on all local Java filesresgrep
: Greps on all local res/*.xml files
The next step is to choose the target board and build:
~/myandroid$ lunch ... choose nitrogen6x-eng or nit6xlite-eng from the list of boards and then build ~/myandroid$ make 2>&1 | tee build.out
A full build will take upwards of 3 hours, but incremental builds are pretty speedy if you’re changing things.
In order to flash the newly created Android image into a SD Card, you can use our mksdcard.sh
script:
~/myandroid$ ./device/boundary/mksdcard.sh /dev/sdX nitrogen6x (or nit6xlite)
Tips & Tricks
If your latest modifications only affect kernel, ramdisk or bootscript, you do not need to start a full build but use the bootimage target instead.
~/myandroid$ make bootimage
This will only update the components under the boot/ output folder which then can be updated as follows as an example:
~/myandroid$ adb push $OUT/boot/imx6q-nitrogen6x.dtb /boot ~/myandroid$ adb push $OUT/boot/uImage /boot ~/myandroid$ adb push $OUT/boot/6x_bootscript /boot ~/myandroid$ adb push $OUT/boot/uramdisk.img /boot
Those modifications require a reboot in order to take effect:
~/myandroid$ adb reboot
If on the other hand the modification only affect a specific package, you can rebuild only that latter by issuing:
~/myandroid$ mmm hardware/libhardware_legacy/
You can even force the rebuild in case the Android.mk doesn’t see any obvious change that require re-building:
~/myandroid$ mmm -B hardware/libhardware_legacy/
Then the Android build process allows you to just send over changes to a USB-connected board using adb sync which requires to remount the system partition first:
~/myandroid$ adb remount ~/myandroid$ adb sync
If you’re changing system components, the best is to reboot as explained above but you could stop and restart the Android GUI.
~/myandroid$ adb shell 'stop && start'
Finally, in order to add a git project as part of your custom image, you need to edit .repo/manifest.xml
which is actually a symlink to .repo/manifests/default.xml
. Note that when adding new projects, there are at least three parts defined:
remote
— the name of the remote. this can be one that was defined in either the default manifest or local_manifest.xml.name
— the name of the git project– for github it has the format account_name/project_name.path
— where the git repository should go in your local copy of the source code.revision
— (optional) which branch or tag to use in the repository. If this attribute is omitted, repo sync will use the revision specified by the <default … /> tag in the default manifest.
Here is an example that adds the CMFileManager application:
Going further
This post should enable you to get started with your project. But if you are looking for more information on some specific topics, we’ll try to link our more advanced Android posts here.
- Android security part 1: application signatures & permissions
- Android security part 2: OTA updates
- Android security part 3: Security-Enhanced Linux in Android
We also try to give as much details as possible on every of our release post.
The post Android Getting Started Guide appeared first on Boundary Devices.