Chapter 2
Chapter 2
SDK tools
SDK tools are generally platform independent and are required no matter which android
platform you are working on. When you install the Android SDK into your system, these tools
get automatically installed. The list of SDK tools has been given below −
android
1
This tool lets you manage AVDs, projects, and the installed components of the
SDK
ddms
2
This tool lets you debug Android applications
Draw 9-Patch
3 This tool allows you to easily create a NinePatch graphic using a WYSIWYG
editor
emulator
4
This tools let you test your applications without using a physical device
mksdcard
5 Helps you create a disk image (external sdcard storage) that you can use with the
emulator
6 proguard
Shrinks, optimizes, and obfuscates your code by removing unused code
1
sqlite3
7
Lets you access the SQLite data files created and used by Android applications
traceview
8
Provides a graphical viewer for execution logs saved by your application
Adb
9 Android Debug Bridge (adb) is a versatile command line tool that lets you
communicate with an emulator instance or connected Android-powered device.
Android
DDMS
DDMS stands for Dalvik debug monitor server, that provide many services on the device. The
service could include message formation, call spoofing, capturing screenshot, exploring internal
threads and file systems e.t.c
Sqlite3
Sqlite3 is a command line program which is used to manage the SQLite databases created by
Android applications. The tool also allow us to execute the SQL statements on the fly.
There are two way through which you can use SQlite , either from remote shell or you can use
locally.
2
Platform tools
The platform tools are customized to support the features of the latest android platform.
The platform tools are typically updated every time you install a new SDK platform. Each
update of the platform tools is backward compatible with older platforms.
Some of the platform tools are listd below −
Android Debug bridge (ADB)
Android Interface definition language (AIDL)
aapt, dexdump , and dex e.t.c
Android Emulator
The Android Emulator simulates Android devices on your computer so that you can test your
application on a variety of devices and Android API levels without needing to have each
physical device.
The emulator provides almost all of the capabilities of a real Android device. You can simulate
incoming phone calls and text messages, specify the location of the device, simulate different
network speeds, simulate rotation and other hardware sensors, access the Google Play Store, and
much more.
3
Dalvik Virtual Machine | DVM
As we know the modern JVM is high performance and provides excellent memory management.
But it needs to be optimized for low-powered handheld devices as well.
The Dalvik Virtual Machine (DVM) is an android virtual machine optimized for mobile
devices. It optimizes the virtual machine for memory, battery life and performance.
Dalvik is a name of a town in Iceland. The Dalvik VM was written by Dan Bornstein.
The Dex compiler converts the class files into the .dex file that run on the Dalvik VM. Multiple
class files are converted into one dex file.
Let's see the compiling and packaging process from the source file:
The javac tool compiles the java source file into the class file.
The dx tool takes all the class files of your application and generates a single .dex file. It is a
platform-specific tool.
The Android Assets Packaging Tool (aapt) handles the packaging process.
4
Runtime Environment
Runtime Environment consists of software instructions(generated from the code) that are used
while executing the programming.
JVM is the component that is used to convert bytecode into machine code in order to run Java-
based programs.
A Virtual Machine isolates the execution of the program from the OS. Thus protecting malicious
code from affecting the system files.
Virtual Machines execute code independent of the CPU architecture
Dalvik Virtual Machine (DVM) was specifically designed to run Android applications initially.
Stack-based Virtual Machines have the memory structure of the type Stack.
Register-based uses registers of the CPU to store the operands. So along with the operands, their
address is also stored.
A Register based model does not require any pushing and popping of instructions. Hence
instructions execute faster.
Register-based models are good at optimizing as well. They can store common subexpression
results which can be used again in the future without the need to calculate. This is not possible in
a Stack-based model.
Android DVM
Before looking at the Dalvik Virtual Machine, let’s look at the JVM:
5
Following is the flow of DVM:
The Dex compiler (dx tool) converts the .class files generated from the javac compiler to .dex
file.
These .dex files are then converted to machine code.
Note: dexopt tool which is a part of the DVM converts the dex file into .odex file format.
6
Just In Time is a component that takes application code, analyzes it, and actively translates it into
a form that runs faster, doing so while the application continues to run. This leads to increased
launch time for applications since it needs to be done everytime the application is launched.
As the execution progresses, more bytecode is compiled and cached. This leads to faster boot
times.
DVM and JIT were replaced by ART and AOT respectively since Android Lollipop.
Android ART
Android Runtime has replaced DVM since Android Lollipop. ART uses Ahead of Time
Approach (AOT) instead of JIT.
Using AOT, the dex files are compiled before they are needed. Usually, they are done at
installation time only and then stored in phone storage.
ART vs DVM
Battery Performance: ART largely increases the battery performance compared to DVM since
the dex bytecode is not interpreted every time.
Storage : On installation, the AOT stores the precompiled binary in phone storage directly.
Hence DVM is more suited for phones with low storage.
Boot Time: ART causes a slower reboot time since the cache is built at first boot, hence
rebooting device takes significantly longer.
7
Application Launch Time: DVM has a slower launch time for the applications. ART has the
native code ready to execute thanks to AOT. Hence is super fast.
Garbage Collection: ART has much better Garbage collection than DVM. In DVM the heap is
more fragmented. Whereas ART uses a different heap for storing large objects such as Bitmaps.
Moreover, ART has a concurrent compacting Garbage collector and is able to compact the heap
easier compared to DVM
Reintroducing JIT
Android Nougat reintroduced Just In Time Compilation with code profiling along with AOT, and
an interpreter in the ART thus making it hybrid.
This is done in order to tackle problems such as initial installation time and memory.
Using the Hybrid Runtime, there won’t be any compilation during install, and applications can
be started right away, the bytecode is interpreted.
Now with ART and the new JIT the application installation is faster.
The new JIT constantly does profiling and improves applications as they run.
8
9