What happens to JavaScript code after app is compiled using Titanium Mobile

Titanium is not a wrapper around a web view as stated before (though that accurately explains how Phonegap works). Jeff’s answer, linked in the question, is a technically correct explanation of how Titanium works, but here’s the best version I’ve heard so far, from Marshall Culpepper:

It’s true that Titanium Mobile used the WebView (in both Android and iOS) in the pre-1.0 days. However, this is no longer true and hasn’t been since our 1.0 release is March 2010.

Since 1.0, we’ve shipped two separate Javascript runtimes with our apps, and we are running the Javascript code directly without a WebView. Your entire app from start to finish is now controlled by JS, and we provide a comprehensive set of Native APIs that enable this. Everything from UI widgets (yes, including WebView), Core APIs like Networking, Filesystem, Database, all the way to OS-specific things like JS Activities in Android. On the JS runtime front, we’re shipping a forked version of WebKit’s JavaScriptCore in iOS and a snapshot of Rhino 1.7 R3 CVS for Android. What we actually do with your javascript source is dependent on the platform, but generally it breaks up like this:

  • Source is statically analyzed to find references to Titanium modules
  • Localization strings (strings.xml), App metadata (tiapp.xml), and density specific images all generate platform specific analogs.
  • In iOS:
    • An XCode project / configuration is generated
    • JS Source is base64’d and inlined as a variable into a generated C file
    • xcodebuild is used to generate the final binaries
    • provisioning profiles, signing keys etc are applied
    • iTunes and some other glue are used to send the IPA to your iOS device
  • In Android:
    • An Android / Eclipse project is generated
    • In “Development” mode, JS source is packaged as APK assets
    • In “Distribution” (production) mode, when you’re ready to ship the app, we compile the JS to Java bytecode using the Rhino JSC compiler. You can also enable this during development mode by setting “ti.android.compilejs” to “true” in tiapp.xml, see: http://developer.appcelerator.com/question/100201/enable-android-byte-code-compile
    • dex, aapt, and other Android SDK tools are used to build and generate the final APK
    • adb and keytool are used for pushing the APK out to the emulator and/or device

There are many more details that I could dive into specifically on each of these points, but the point I wanted to drive home is that we no longer use the WebView as our Javascript engine. You can however still embed WebViews, and we provide some simple integration that allows you to call Titanium APIs from an embedded WebView.

Leave a Comment