Cross-platform develeopment with Chromium
When we try to develop an application in mobile, typically, in iOS and Android, it is redundant to write the codes(Objective-C in iOS, and Java in Android) which implements the common logic behind the application:
As we all know, C++ is a low level language which can write on either iOS or Android with high performance. It is a good choice to develop the common logic by C++.
Anyway, we can not finish the common logic just by C++. Because many interfaces are invisible to C++ in the operating system, but available for high level language such as Objective-C and Java. So we need a Middle tier to make C++ have ablitiy to call the specify interfaces.
It takes time to write the middle tier which need to consider the interface and implement cross platform. Fortunately, chromium has accomplished the middle tier, and provide a perfect framework for developers.
Using Chromium Framework
Follow here to get the code of chromium.
As you will recall, there will be two layer in our application. The upper layer is the UI layer, and the lower layer is the common logic. So we should separate them and encapsulate the lower layer to a library. The figure below shows the major architecture of the application based on chromium.
There are several steps to build the library:
- Make the project or building config file from gyp
- Writing common logic code based on chromium
- Wrapping interface to high level language such as ObjC or Java
- Building framework on iOS and Jar
gyp - Generate your projects
Chromium provided a tool named JNI Generator to generate JNI methods in Android.
Demo: Blog’s RSS application
I have developed an “BlogRSS” demo based on the architecture above. It has three projects that everyone can fork:
- BlogRSS SDK: Provides the abillity to fetch the RSS of my blog, it is the sdk of my application.
- BlogRSS for iPhone: Implement the blog’s RSS application in iPhone.
- BlogRSS for Android: Implement the blog’s RSS application in Android.
Screenshot for BlogRSS-iPhone:
Screenshot for BlogRSS-Android: