Upload
kostis-dadamis
View
352
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Here, I am including the experience I had while exploring solutions for developing a mobile cross-platform library, i.e. a single codebase that could be part of mobile apps running under different platforms. It covers my journey from mobile cross-platform developments tools (PhoneGap, Titanium, and the likes), code porting tools, and WebViews that weren't up to the task, to C++ and JavaScript engines that did work. There aren't many resources out there explaining how to approach this problem, so we thought it could be helpful if we shared this experience.
Citation preview
Developing a mobilecross-platform library
Kostis Dadamis11/03/2014
What?
Description
• Piece of code including common functionality across all mobile platforms
• E.g. querying a Web API, fetching results, sorting results, fancy algorithms, etc.
• No UI• One main codebase• Some glue code for each platform (focusing on Android
and iOS)• Package it as a library
Description
Why?
Motivation
• Less code• Less bugs• Less testing
• Consistency
• Reuse existing code
• Develop and distribute cross-platform SDKs
Attempts
Attempts
• Mobile Cross-Platform Development Tools• C++• Code porting• JavaScript in a WebView• JavaScript in a JavaScript Engine
Mobile cross-platform development tools
Mobile Cross-Platform Development Tools
• Mobile Cross-Platform Development Tools• 18 different tools investigated (e.g. PhoneGap,
Xamarin, Titanium, Corona, MoSync, Kony)
Mobile Cross-Platform Development Tools
• Mobile Cross-Platform Development Tools• 18 different tools investigated (e.g. PhoneGap,
Xamarin, Titanium, Corona, MoSync, Kony)• Output end products (not libraries)
Mobile Cross-Platform Development Tools
• Mobile Cross-Platform Development Tools• 18 different tools investigated (e.g. PhoneGap,
Xamarin, Titanium, Corona, MoSync, Kony)• Embed a runtime environment
Mobile Cross-Platform Development Tools
• Mobile Cross-Platform Development Tools• 18 different tools investigated (e.g. PhoneGap,
Xamarin, Titanium, Corona, MoSync, Kony)• Corona and MoSync support this for Android, but it’s a
“coming feature” for iOS
C++
C++
C++
• Build for all possible platforms and CPU architectures• Glue code
• Android• Android Native Development Kit (NDK) and Java
Native Interface• Complicated
• iOS• Objective-C++• Easy
C++
• C++• Pros
• Official solutions• Fast• Ability to import a vast number of open-source
C/C++ libraries• Applicable to Windows Phone• Free of charge
C++
• C++• Cons
• Manual GC in Java (workaround by copying)• Building libraries for all platforms/CPU architectures
is time-consuming• Documentation
Code porting
Code porting
• Maintaining code for 1 platform, and translate it for the other platform(s)
• 7 different tools investigated• Most solutions immature
Code porting
• Worth revisiting in the future• J2ObjC
• Translates Java (Android) to Objective-C (iOS)• Hyperloop
• Translates JavaScript to source code for each platform
JavaScript
JavaScript
• Part of web browsers• Part of server-side code
• Rapidly gaining popularity
• Reusing JavaScript code?
JavaScript in a WebView
JavaScript in a WebView
• JavaScript in a WebView• Use existing native web-browser Views
(WebViews) to execute JavaScript• WebViews provide limited functionality to
programmers• WebView APIs are inconsistent across
platforms• Could work only with hacks
JavaScript in a JavaScript Engine
JavaScript in a JavaScript Engine
• Use standalone JavaScript engine without a View• iOS
• JavaScriptCore• Android
• Rhino • V8• SpiderMonkey• JavaScriptCore• Nashorn
JavaScript in a JavaScript Engine
• Problem• Pure JavaScript engines don’t support networking
• Solution• Delegate missing functionality to the platforms
JavaScript in a JavaScript Engine
JavaScript in a JavaScript Engine
• iOS• JavaScriptCore framework (since iOS 7)• Pros
• Simple object conversions• No embedding needed
• Cons• Lack of documentation
JavaScript in a JavaScript Engine
• Android, we have to embed one• Rhino
• App size 3.6MB (+2.6MB)• Pros
• Developed in Java• Cons
• Inactive development• Outdated documentation
JavaScript in a JavaScript Engine
• Android, we have to embed one• V8
• Pros• Actively developed
• Cons• App size 8.1MB (+7.1MB)• Developed in C++ -> Android NDK/JNI• Additional translation layer
JavaScript in a JavaScript Engine
JavaScript in a JavaScript Engine
• JavaScript in a JavaScript Engine• Pros
• Reusing JavaScript code• Applicable to Windows Phone
• Cons• Delegated functionality increases glue code and
overcomplicates architecture• In Android, either Rhino which is not actively
developed, or V8 which is large and written in C++
Proof-of-concept app
Conclusions
Conclusions
• Some immature solutions are worth revisiting (Corona, MoSync, J2ObjC, Hyperloop, Nashorn)
• C++• Pros: Official solutions, fast, access to C/C++ libraries,
free• Cons: Low-level, garbage collection?
• JavaScript in a JavaScript Engine• Pros: Reusing JavaScript code• Cons: Delegating missing functionality, Rhino not
actively developed, V8 large and written in C++
More info
Edinburgh • Glasgow • Singapore • Beijing • Miami • Barcelona
thank you
Opportunities