1. A
seminar on
“CROSS -COMPILING ANDROID
APPLICATIONS”
2/15/2013
Guided by: Seminar Co-ordinators
Asst.prof. Suresh .T Asst. H.O.D, Dr. Rajashree V.Biradar
Asst. Prof, Gousia Parveen
Asst. prof, Sudhakar Avareddy
Presented by:
1
Kotte Sai Krishna
2. Agenda
• Introduction
• Why android?
2/15/2013
• Features of Android
• Android architecture
• Why to cross-
compile?
• Advantages
• Disadvantages
• Conclusion
• References 2
3. Introduction
• Mobile development community is at a tipping point because
users demand for innovative ideas.
2/15/2013
• The question was “what would it take to build better mobile
phone?”.
• Google responded by forming “open handset alliance” in
November 2007 and named the project as “THE ANDROID
PROJECT”
• Its members include operators, handset makers, software
companies, commercialization companies and semiconductor
companies. 3
5. • The first android handset was developed by HTC and was
named as T-Mobile G1.
• Android is hailed as “ The first complete, open, and free
mobile platform”
2/15/2013
5
7. Features of Android
1. A truly open, free development platform based on Linux and
open source.
2/15/2013
open: open source licensing for developers to develop
applications.
Free: Android applications are free to develop.
complete: Because of it’s secure operating system having
robust software framework and rich application
development opportunities.
2. A component-based architecture inspired by Internet
mashups.
7
8. Parts of one application can be used in another in ways not
originally envisioned by the developer.
Ex:-Suppose you want to write an app that tweets your
current location every 10 minutes throughout the day. You
can, and it’s easy. Use Android’s location services and a third-
party Twitter API (such as iTwitter), and you can do just that.
2/15/2013
3. Tons of built-in services out of the box
A full-powered SQL database lets you harness the power of
local storage for occasionally connected computing and
synchronization.
4. Automatic management of the application life cycle
Programs are isolated from each other by multiple layers of
security, which will provide a level of system stability not
8
seen before in smart phones.
9. 5. Graphics and animation inspired by Flash are melded with
3D accelerated OpenGL graphics to enable new kinds of
games and business applications.
6. Portability across a wide range of current and future
hardware.
2/15/2013
All your programs are written in Java and executed by
Android’s Dalvik virtual machine, so your code will be
portable on different architectures.
Support for a variety of input methods such as
keyboard, touch, and trackball.
User interface customization.
9
10. Android Architecture
The android software stack can be subdivided into five layers:
1) The kernel.
2/15/2013
2) Native libraries.
3) Android runtime.
4) Application framework.
5) Applications.
10
12. 1.Linux Kernel
• The whole Android OS is built on top of the Linux 2.6 Kernel
with some further architectural changes made by Google. It is
this Linux that interacts with the hardware and contains all the
2/15/2013
essential hardware drivers.
• Drivers are programs that control and communicate with the
hardware.
• It acts as an abstraction layer between hardware and software
layers.
• The features of Linux kernel include( but aren’t limited to) the
following: 12
13. Security model: The Linux kernel handles security between the
application and the system.
Memory management: The kernel handles memory
management for you, leaving you free to develop your app.
2/15/2013
Process management: The Linux kernel manages processes
well, allocating resources to processes as they need them.
Network stack: The Linux kernel also handles network
communication.
Driver model: The goal of Linux is to ensure that everything
works. Hardware manufacturers can build their drivers into
the Linux build.
13
14. 2.Libraries
• The next layer is the Android’s native libraries. It is this layer
that enables the device to handle different types of data.
2/15/2013
• written in c or c++ language .
• specific for a particular hardware.
• Some of the native libraries include:
Surface Manager: It is used for compositing window manager
with off-screen buffering. This off screen buffer is the reason
behind the transparency of windows.
14
15. Media framework: Media framework provides different media
codec’s allowing the recording and playback of different media
formats.
SQLite: SQLite is the database engine used in android for data
2/15/2013
storage purposes.
Web Kit: It is the browser engine used to display HTML
content.
OpenGL: Used to render 2D or 3D graphics content to the
screen.
Secure socket layer (SSL): These libraries are responsible for
Internet security. 15
16. 3.Android runtime
• consists of Dalvik Virtual machine and Core Java libraries.
Dalvik Virtual Machine
2/15/2013
It is a type of JVM used in android devices to run apps .
Unlike the JVM, the Dalvik Virtual Machine doesn’t run .class
files, instead it runs .dex files. .dex files are built from .class
file at the time of compilation .
The Dalvik VM allows multiple instance of Virtual machine to
be created simultaneously providing security, isolation,
memory management and threading support. It is developed
by Dan Bornstein of Google. 16
18. Core java libraries
These are different from Java SE and Java ME libraries.
However these libraries provide most of the functionalities
defined in the Java SE libraries.
2/15/2013
Dalvik itself is compiled to native code whereas the core
libraries are written in Java, thus interpreted by Dalvik.
18
19. 4.Application framework
• These are the blocks that our applications directly interact
with. These programs manage the basic functions of phone
2/15/2013
like resource management, voice call management etc.
Blocks of application framework include:
Activity Manager: Manages the activity life cycle of
applications.
Content Providers: Manage the data sharing between
applications.
19
Telephony Manager: Manages all voice calls.
20. Location Manager: Location management, using GPS or cell
tower.
Resource Manager: Manage the various types of resources we
use in our Application.
2/15/2013
View system: Handles the views and layouts that make up your
user interface (UI).
20
21. 5.Applications
• Applications are the top layer in the Android architecture and
this is where our applications are going to fit.
2/15/2013
• Several standard applications come pre-installed with every
device, such as:
1) SMS client app.
2) Web browser.
3) Contact manager.
21
22. Why to cross compile?
• A cross compiler is a compiler capable of
creating executable code for a platform other than the one on
2/15/2013
which the compiler is running.
• Problem: Porting an application to different phones require
significant effort.
• Solution:
1) Android is used as development platform.
2) Developers need to know only about Android SDK.
3) Applications can then be compiled to their native code.
22
23. Android to iPhone cross-
compilation
• Apple's iPhone has generated huge interest amongst users
and developers alike. Like MacOS X, the iPhone development
2/15/2013
environment is based on Objective-C as the development
language and Cocoa Touch for the GUI library.
• The iPhone SDK license agreement does not permit the
development of a virtual machine.
• “XMLVM” can be used to cross-compile a Java application to
Objective-C.
• XMLVM- Extensible markup language Virtual machine. 23
25. • STEPS:
1) Cross compile java to objective-C.
2) Create JAVA API for cocoa touch.
3) Write Android compatibility library on top of Cocoa Touch
Java API.
4) Use native SDK Xcode to create executable.
2/15/2013
// Java
Class Calc {
Static int add (int x, int y);
{
return x + y;
}
}
25
27. Cross-compiling XMLVM to
objective-C
1) These translations are done using XSLT.
2/15/2013
2) Mappings exist for different languages.
3) The XSLT excerpt below demonstrates the translation of
<dex:add-int/> (Integer add) to Objective-C.
27
31. • The Apple license agreement does not permit the installation
of a virtual machine on the iPhone. By cross-compiling a Java
application to a native iPhone application, this restriction of
the license agreement is therefore not violated.
2/15/2013
• Apple only supports Objective-C as the development language
for the iPhone. The GUI of iPhone applications is based on
Cocoa Touch.
• If Java is to be used as a development language for iPhone
applications, two aspects need to be addressed:
1) The cross-compilation of Java to Objective-C and
2) A Java API for Cocoa Touch.
31
32. • Android defines its own API for writing mobile applications.
With the help of XMLVM it is possible to cross-compile Java-
based Android applications to native iPhone applications.
• The Android application is written in Java and makes use of an
Android specific API. XMLVM offers a compatibility library,
2/15/2013
written in Java that offers the same API as Android, but only
makes use of the Java-based API for Cocoa Touch mentioned
earlier.
• During the cross-compilation process, both the application
and the Android compatibility library are cross-compiled from
Java to Objective-C and linked with the Cocoa Touch
compatibility library to yield a native iPhone application.
32
33. • As can be seen, compared to the Java-for-the-iPhone portion
of XMLVM, the only additional feature added to support
Android applications is the Android compatibility library.
Android Compatibility Library:
2/15/2013
– Offers Android API.
– Device-independent portions of Android.
– Builds upon a Common Layer API.
– Written in Java.
– Is cross-compiled to Objective-C.
33
35. • XMLVM is a flexible cross-compilation framework.
• Instead of cross-compiling source code of high-level
programming languages, XMLVM translates byte code
instructions. Byte code programs are represented by XML
documents and cross-compiled via XSL stylesheet.
2/15/2013
• XMLVM supports byte code instructions from different virtual
machines:
1) The Java Virtual Machine (JVM).
2) The Common Language Runtime (CLR) that is part of the
.NET framework, and the YARV byte code from Ruby 1.9.
35
36. • Process:
1) The first step in using XMLVM is to compile a Java or .NET
source code program to byte code. This is done with a native
compiler such as Sun Microsystems’s javac or Microsoft's
Visual Studio.
2/15/2013
2) The resulting byte code program (either a Java .class file or
a .NET .exe file) is fed into the XMLVM tool chain where it is
first converted to XML.
3) XMLVMJVM denotes an XMLVM program that contains JVM
byte code instructions.
4) XMLVMDEX makes use of Android's DEX instructions for
Dalvik that is particularly suitable for generating source of 36
other high-level programming languages.
37. Advantages
• Android API offer good support for different screen
resolutions.
2/15/2013
• Cross-compilation of games is feasible.
• Leverage existing Android/Java skills.
• Only knowledge of a single platform is required.
• Reduces development costs.
• Shortens time-to-market.
37
38. Disadvantages
• Hard to test the result.
The test suite is often part of the source. You didn't build the
2/15/2013
source on the target, so you have to copy the source to the
target. Then to run its test suite you need to cross-compile
test suite and install it to the target's root file system.
• Cross compiling restricts developer skills.
• Platform fragmentation is an issue for Android OS devices.
Vendors do not have uniform policies with respect to OS
upgrades and version control, so new application releases may
not work reliably across all Android devices which cause 38
disruptions in cross compiling process.
39. Conclusion
• Immediate benefits of cross-compiling solutions.
• Strong fragmentation of market for mobile device platforms.
2/15/2013
• Cross-Platform frameworks try to bridge the gap.
• No tool fulfills all requirements.
• In some case: instead of “Write once, run everywhere” it‘s
more “Write once, run many”.
39
40. References
[1] Arno Puder, Oren Antebi, "Cross-Compiling Android
Applications to IOS and Windows Phone 7" from Mobile
networks and applications February 2013,volume 18,issue
2/15/2013
1,pp 3-21.
[2] EDUCASE learning initiative "7 things you need to know
about Android".
[3] Dr. Ing. Thomas Springer Technische Universitat Dresden
Chair of Computer Networks "Cross-Platform development".
[4] “Android Application development for dummies” by Donn
Felker with Joshua Dobbs, Wiley publishing Inc. 40
41. • Video reference: http://www.youtube.com/watch?v=TG-
NIt2O5J8 by Arno Puder.
2/15/2013
41