Cross-Compiling Android Applications to the iphone



Similar documents
Mobility Introduction Android. Duration 16 Working days Start Date 1 st Oct 2013

Mobile Application Development

Cross Platform App Development

Android Concepts and Programming TUTORIAL 1

Developing Applications for ios

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Mobile Phones Operating Systems

Developing and deploying mobile apps

Chapter 2 Getting Started

Android App Development. Rameel Sethi

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

Mobile Application Development Android

ios Application Development &

Introduction to Android SDK Jordi Linares

directory to "d:\myproject\android". Hereafter, I shall denote the android installed directory as

Lecture 1 Introduction to Android

Android Application Development

QML and JavaScript for Native App Development

Android Development. Marc Mc Loughlin

Android Basics. Xin Yang

Jordan Jozwiak November 13, 2011

Module Title: Software Development A: Mobile Application Development

ios Development Tutorial Nikhil Yadav CSE 40816/60816: Pervasive Health 09/09/2011

OpenCV on Android Platforms

Introduction to Android Development. Ed Burnette

CS378 -Mobile Computing. Android Overview and Android Development Environment

Mobile App Design and Development

Here to take you beyond Mobile Application development using Android Course details

An Introduction to Android

Android Development Setup [Revision Date: 02/16/11]

Building Mobile Applications Creating ios applications with jquery Mobile, PhoneGap, and Drupal 7

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

Take full advantage of IBM s IDEs for end- to- end mobile development

Cross-platform mobile development with Visual C

Programming Mobile Apps with Python

MOBILE APPLICATION DEVELOPMENT

Android Java Live and In Action

Developer's Cookbook. Building Applications with. The Android. the Android SDK. A Addison-Wesley. James Steele Nelson To

Android Mobile App Building Tutorial

Android Developer Fundamental 1

Chapter 1. Introduction to ios Development. Objectives: Touch on the history of ios and the devices that support this operating system.

4. The Android System

Lee Barnes, CTO Utopia Solutions. Utopia Solutions

Smartphone market share

Introduction to Android

place/business fetch details, removefromfavorite () function, 189 search button handler bind, B BlackBerry build environment

BEGIN ANDROID JOURNEY IN HOURS

Application Development for Mobile and Ubiquitous Computing. 10. Cross-Platform Development

Development for Mobile Devices Tools from Intel, Platform of Your Choice!

This documentation is made available before final release and is subject to change without notice and comes with no warranty express or implied.

Graduate presentation for CSCI By Janakiram Vantipalli ( Janakiram.vantipalli@colorado.edu )

Cross Platform Mobile. -Vinod Doshi

How To Develop Android On Your Computer Or Tablet Or Phone

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

Android: How To. Thanks. Aman Nijhawan

Mobile Application Development 2014

INTRODUCTION TO ANDROID CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 11 02/15/2011

Introduction to Android: Hello, Android! 26 Mar 2010 CMPT166 Dr. Sean Ho Trinity Western University

Developing Cross-platform Mobile and Web Apps

Introduction to Android

INTRODUCTION TO IOS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 13 02/22/2011

How To Use Titanium Studio

Creating a 2D Game Engine for Android OS. Introduction

Android Application Development. Daniel Switkin Senior Software Engineer, Google Inc.

MMI 2: Mobile Human- Computer Interaction Android

Now that we have the Android SDK, Eclipse and Phones all ready to go we can jump into actual Android development.

Portability Study of Android and ios

Android Application Development Lecture Notes INDEX

ios SDK possibilities & limitations

Introduce Configurable Mobile App Development. Moxie Zhang Esri R&D Center Beijing

Practical Android Projects Lucas Jordan Pieter Greyling

Lecture 3 Mobile App Development (Android, ios, BlackBerry, Windows Mobile) <lecturer, date>

ANDROID INTRODUCTION TO ANDROID

Praktikum Entwicklung von Mediensystemen mit

Getting started with Android and App Engine

Android Development Tutorial. Human-Computer Interaction II (COMP 4020) Winter 2013

Android 多 核 心 嵌 入 式 多 媒 體 系 統 設 計 與 實 作

l What is Android? l Getting Started l The Emulator l Hello World l ADB l Text to Speech l Other APIs (camera, bitmap, etc)

ANDROID OPERATING SYSTEM

Getting Started With Android

Presenting Android Development in the CS Curriculum

Frameworks & Android. Programmeertechnieken, Tim Cocx

01. Introduction of Android

HYBRID APPLICATION DEVELOPMENT IN PHONEGAP USING UI TOOLKITS

Android Programming and Security

Running a Program on an AVD

BlackBerry Smartphone Application Development

Mobile Development with Qt

UNIVERSITY AUTHORISED EDUCATION PARTNER (WDP)

Learning ios Programming

Android Programming. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

Getting Started with Android Development

Transcription:

Cross-Compiling Android Applications to the iphone Arno Puder San Francisco State University arno@sfsu.edu

The Team Core team: Arno Puder, SFSU Sascha Haeberling, Google Inc Wolfgang Korn, bluecarat AG Contributors: Kevin Glass Panayotis Katsaloulis Gergely Kis Jessica Lee Joshua Melcon Alexander Seewald Sponsors: bluecarat AG, Cologne, http://www.bluecarat.de Slide 2

Background Smart phones have entered the mainstream. Most phones have similar capabilities. Common subset useful for certain class of applications (e.g. games). Developers are interested to push their applications to different platforms. Problem: Porting an application to different phones requires significant effort. Slide 3

Android vs. iphone vs. Palm Pre HTC G1 iphone 3GS Palm Pre OS Linux Mac OS Linux CPU ARMv6, 528 MHz ARMv6, 600 MHz TI-OMAP, 600 MHz RAM 192 MB 256 MB 256 MB Sensors Accelerometer, GPS, compass. Accelerometer, GPS, proximity, ambient light, compass. Accelerometer, GPS, proximity, ambient light. IDE Eclipse Xcode Eclipse Dev-Language Java Objective-C JavaScript GUI Android Cocoa Touch webos Virtual Machines Allowed Not allowed Allowed License Open Source Proprietary Proprietary Slide 4

Proposed Solution Android is used as development platform: Developer only needs to know Android SDK. Make use of well-documented SDK. Powerful tools (debugging). Support for arbitrary screen resolutions using layout managers (Nexus One, iphone, ipad, Netbooks). Android application is cross-compiled to Objective-C or JavaScript. Does not require a JVM on the iphone! Approach for Android to iphone cross-compilation: Create Java API for Cocoa Touch. Cross-compile Java to Objective-C. Write Android compatibility library on top of Cocoa Touch Java API. Slide 5

iphone Hello World in Objective-C @interface HelloWorld : UIApplication -(void) applicationdidfinishlaunching: (NSNotification*) n; @end @implementation HelloWorld -(void) applicationdidfinishlaunching: (NSNotification*) n { UIScreen* screen = [UIScreen mainscreen]; CGRect rect = [screen applicationframe]; UIWindow* window = [[UIWindow alloc] initwithframe: rect]; rect.origin.x = rect.origin.y = 0; UIView* mainview = [[UIView alloc] initwithframe: rect]; [window addsubview: mainview]; UILabel *title = [[UILabel alloc] initwithframe: rect]; [title settext: @"Hello World!"]; [title settextalignment: UITextAlignmentCenter]; [mainview addsubview: title]; [window makekeyandvisible]; } @end Slide 6

iphone Hello World in Java public class HelloWorld extends UIApplication { public void applicationdidfinishlaunching(nsnotification n) { UIScreen screen = UIScreen.mainScreen(); CGRect rect = screen.applicationframe(); UIWindow window = new UIWindow(rect); rect.origin.x = rect.origin.y = 0; UIView mainview = new UIView(rect); window.addsubview(mainview); UILabel title = new UILabel(rect); title.settext("hello World!"); title.settextalignment( UITextAlignment.UITextAlignmentCenter); mainview.addsubview(title); } } window.makekeyandvisible(); Slide 7

Tool Chain Overview Hello World Java app. Cocoa Java Compat Lib Cross-Compilation Desktop application ( iphone emulator) Hello World Objective-C Objective-C Wrapper Classes. Native iphone application Slide 8

Challenges Design goals: If possible, Java API mimics 1:1 the Objective-C API. Make use of strongly typed interfaces. Objective-C challenges: Namespaces, method overloading: use name-mangling. Garbage collection: use Objective-C reference counting. No static member variables: use global variables. Cocoa Touch challenges: Makes use of C-functions (e.g., CGColorCreate) Uses value types (e.g., CGRect) Uses pointers for output parameters (e.g., NSURLConnection) Makes heavy use of delegation (e.g., data source for UITableView) Slide 9

Tool Chain Overview // Java class Calc { static int add(int x, int y) { return x + y; } } Calc.java javac Calc.class XMLVM Calc.xmlvm Slide 10

XMLVM of Class Calc <?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> Slide 11

Cross-Compiling XMLVM to Objective-C Simply map DEX registers to variables of the target language! These translations are done using T. Mappings exist for different languages. The T excerpt below demonstrates the translation of <dex:add-int/> (Integer add) to Objective-C. // Objective-C typedef union { id o; int i; float f; double d; } XMLVMElem; _r0.i = _r1.i + _r2.i; <! 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> Slide 12

Class Calc in Objective-C // Objective-C generated via stylesheet @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 Slide 13

Android Compatibility Library Application Application Application Android Android Compat-Lib Cocoa Touch Layer Android Compat-Lib webos Layer Android API Common Layer API Device API iphone Palm Pre 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. Slide 14

Example 1: Button to UIButton Mapping package android.widget; public class Button extends View { protected UIButton button; //... public void setonclicklistener(onclicklistener listener) { final OnClickListener thelistener = listener; button.addtarget(new UIControlDelegate() { @Override public void raiseevent() { thelistener.onclick(button.this); } } } }, UIControl.UIControlEventTouchUpInside); Slide 15

Example 2: R-class // Generated by Android public final class R { public static final class drawable { public static final int ball=0x7f020001; //... } Resources in Android are referenced through R-class: ImageView image = ; image.setimageresource(r.drawable.ball); Problem: map integer (0x7f020001) to file name (ball.png) Solution: use Java reflection at runtime for the reverse mapping. String rclassname = "R$drawable"; Class<?> rclass = Class.forName(rClassName); Field[] fields = rclass.getdeclaredfields(); for (int i = 0; i < fields.length; i++) { String fieldname = fields[i].getname(); int id = fields[i].getint(rclass); //... } Slide 16

Example 3: Layout Manager Android uses declarative UI descriptions. UI descriptions are saved in XML files. Those files are copied to the iphone. At runtime, XML files are parsed and UI is built on the iphone. XMLVM cross-compiles Android s implementation of the layout managers. <LinearLayout orientation="vertical layout_width="fill_parent" layout_height="fill_parent"> <EditText... /> <TextView... /> <Button layout_width="wrap_content" layout_height="wrap_content id="@+id/sayhello" text="say Hello"... /> <LinearLayout background="@drawable/xmlvm_logo"... /> </LinearLayout> Slide 17

Xokoban Sokoban version developed for Android and cross-compiled to the iphone and webos. Available in the Android Market and iphone AppStore. Features: 2D animation. Dialog boxes. Accelerometer and swipe interface. Landscape full-screen mode. Saving of settings. Slide 18

Legions Implementation of the Stratego board game. Developed for Android. AI engine implemented by Vincent De Boer (3rd time Stratego world champion). Android version of Legions uses: Activity lifecycle. Sound. Animation. Custom dialogs/toasts. Declarative layouts using different layout managers. File I/O. Slide 19

Scope Android API offers good support for different screen resolutions. Cross-compilation of games is feasible. Problem: widget-driven applications. Solution: partial cross-compilation. Benefits: Code-reuse of Model/Controller. Custom View for native look-and-feel. Custom View can still be implemented in Java. Idea: use iphone widgets in conjunction with Android layout managers. Slide 20

XMLVM Tool Chain.NET.exe MBEL Java Class File BCEL Ruby YARV Ruby XMLVM CLR XMLVM CLR-DFA XMLVM JVM DX BCEL XMLVM DEX Java Class File XMLVM CLR MBEL Objective-C C++ JavaScript Python.NET.exe Slide 21

XMLVM Tool Chain.NET.exe MBEL Java Class File BCEL Ruby YARV Ruby XMLVM CLR XMLVM CLR-DFA XMLVM JVM DX BCEL XMLVM DEX Java Class File XMLVM CLR MBEL Objective-C C++ JavaScript Python.NET.exe Slide 22

XMLVM Tool Chain.NET.exe MBEL Java Class File BCEL Ruby YARV Ruby XMLVM CLR XMLVM CLR-DFA XMLVM JVM DX BCEL XMLVM DEX Java Class File XMLVM CLR MBEL Objective-C C++ JavaScript Python.NET.exe Slide 23

XMLVM Tool Chain.NET.exe MBEL Java Class File BCEL Ruby YARV Ruby XMLVM CLR XMLVM CLR-DFA XMLVM JVM DX BCEL XMLVM DEX Java Class File XMLVM CLR MBEL Objective-C C++ JavaScript Python.NET.exe Slide 24

XMLVM Tool Chain.NET.exe MBEL Java Class File BCEL Ruby YARV Ruby XMLVM CLR XMLVM CLR-DFA XMLVM JVM DX BCEL XMLVM DEX Java Class File XMLVM CLR MBEL Objective-C C++ JavaScript Python.NET.exe Slide 25

Conclusions Summary: Java for the iphone. Android Compatibility Classes. Benefits: Leverage existing Android/Java skills. Only knowledge of a single platform is required. Reduces development costs. Shortens time-to-market. Commercial support at http://xmlvm.org/support/