Date post: | 05-Dec-2014 |
Category: |
Education |
Upload: | sai-krishna |
View: | 1,364 times |
Download: | 4 times |
04/1
0/20
23
A seminar on
“CROSS -COMPILING ANDROID APPLICATIONS”
Guided by: Seminar Co-ordinatorsAsst.prof. Suresh .T Asst. H.O.D, Dr. Rajashree V.Biradar Asst. Prof, Gousia Parveen Asst. prof, Sudhakar Avareddy
Presented by:Kotte Sai Krishna
1
04/1
0/20
23
Agenda• Introduction• Why android?• Features of Android• Android architecture• Why to cross-
compile?• Advantages• Disadvantages• Conclusion• References
2
04/1
0/20
23
Introduction• Mobile development community is at a tipping point because
users demand for innovative ideas.
• 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
04/1
0/20
23
Open handset alliance
4
04/1
0/20
23
• 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”
5
04/1
0/20
23
Why Android?
6
04/1
0/20
23
Features of Android
1. A truly open, free development platform based on Linux and open source.
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
04/1
0/20
23
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.
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 seen before in smart phones. 8
04/1
0/20
23
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.
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
04/1
0/20
23
Android Architecture
The android software stack can be subdivided into five layers: 1) The kernel. 2) Native libraries. 3) Android runtime. 4) Application framework. 5) Applications.
10
04/1
0/20
23
11
04/1
0/20
23
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 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
04/1
0/20
23
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.
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
04/1
0/20
23
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.
• 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
04/1
0/20
23
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
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
04/1
0/20
23
3.Android runtime• consists of Dalvik Virtual machine and Core Java libraries. Dalvik Virtual Machine 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
04/1
0/20
23
17
04/1
0/20
23
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.
Dalvik itself is compiled to native code whereas the core libraries are written in Java, thus interpreted by Dalvik.
18
04/1
0/20
23
4.Application framework• These are the blocks that our applications directly interact
with. These programs manage the basic functions of phone 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. Telephony Manager: Manages all voice calls. 19
04/1
0/20
23
Location Manager: Location management, using GPS or cell tower.
Resource Manager: Manage the various types of resources we
use in our Application.
View system: Handles the views and layouts that make up your user interface (UI).
20
04/1
0/20
23
5.Applications• Applications are the top layer in the Android architecture and
this is where our applications are going to fit.
• Several standard applications come pre-installed with every device, such as:
1) SMS client app. 2) Web browser. 3) Contact manager.
21
04/1
0/20
23
Why to cross compile?• A cross compiler is a compiler capable of
creating executable code for a platform other than the one on 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
04/1
0/20
23
Android to iPhone cross-compilation
• Apple's iPhone has generated huge interest amongst users and developers alike. Like MacOS X, the iPhone development 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
04/1
0/20
23
XMLVM overview
24
04/1
0/20
23
• 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.
// JavaClass Calc {Static int add (int x, int y);{return x + y;} }
25
04/1
0/20
23
XMLVM of Calc.class<? Xml version="1.0" encoding="UTF-8"?> <xmlvm xmlns:dex="http://xmlvm.org/dex"><class name="Calc"> <method name="add" isStatic="true"> <Signature> <parameter type="int" /> <parameter type="int" /> <return type="int" /> </signature> <dex:code register-size="3"> <dex:add-int vx="0" vy="1" vz="2" /> <dex:return vx="0" vx-type="int" /> </dex:code> </method> </class></xmlvm>
26
04/1
0/20
23
Cross-compiling XMLVM to objective-C
1) These translations are done using XSLT.
2) Mappings exist for different languages.
3) The XSLT excerpt below demonstrates the translation of <dex:add-int/> (Integer add) to Objective-C.
27
04/1
0/20
23
// Objective-Ctypedef union { _r0.i = _r1.i + _r2.iid o;int i;float f;double d;} XMLVMElem;<! – XSL template --><xsl:template match="dex:add-int"><xsl:text>_r</xsl:text><xsl:value-of select="@vx"/><xsl:text>.i = _r</xsl:text><xsl:value-of select="@vy"/><xsl:text>.i + _r</xsl:text><xsl:value-of select="@vz"/><xsl:text>.i;</xsl:text></xsl:template>
28
04/1
0/20
23
Class calc in objective-C
@implementation Calc+ (int) add___int_int :(int)n1 :(int)n2{XMLVMElem _r0;XMLVMElem _r1;XMLVMElem _r2;_r1.i = n1;_r2.i = n2;_r0.i = _r1.i + _r2.i;return _r0.i;}@end
29
04/1
0/20
23
Android compatibility Library
30
04/1
0/20
23
• 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.
• 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
04/1
0/20
23
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, 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.
04/1
0/20
23
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: – Offers Android API. – Device-independent portions of Android. – Builds upon a Common Layer API. – Written in Java. – Is cross-compiled to Objective-C.
04/1
0/20
23
XMLVM tool chain
34
04/1
0/20
23
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.
• 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.
04/1
0/20
23
• 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) 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 other high-level programming languages.
36
04/1
0/20
23
Advantages• Android API offer good support for different screen
resolutions.• 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
04/1
0/20
23
Disadvantages• Hard to test the result. The test suite is often part of the source. You didn't build the
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 disruptions in cross compiling process.
38
04/1
0/20
23
Conclusion• Immediate benefits of cross-compiling solutions.• Strong fragmentation of market for mobile device platforms.• 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
04/1
0/20
23
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 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
04/1
0/20
23
• Video reference: http://www.youtube.com/watch?v=TG-NIt2O5J8 by Arno Puder.
41
04/1
0/20
23
Thank you
42