在stackoverflow上有人问到Titanium Mobile是如何运行的,AppceleratorCEO Jeff Haynie 给出了他的回答,这里给大家转过来看看!
How Does Appcelerator Titanium Mobile Work?
Question:
引用
I'm working on building an iPhone app with Titanium Mobile 1.0 and I see that it compiles down to a native iPhone binary. How does this work? Seems like it would take a lot of heavy lifting to analyze the JavaScript code and do a direct translation into Objective-C without having a superset language like 280 North's Objective-J and Cappuccino.
Haynie's Answer:
引用
Titanium takes your Javascript code, analyzes and preprocesses it and then pre-compiles it into a set of symbols that are resolved based on your applications uses of Titanium APIs. From this symbol hierarchy we can build a symbol dependency matrix that maps to the underlying Titanium library symbols to understand which APIs (and related dependencies, frameworks, etc) specifically your app needs. I'm using the word symbol in a semi-generic way since it's a little different based on the language. In iPhone, the symbol maps to a true C symbol that ultimately maps to a compiled .o file that has been compiled for ARM/i386 architectures. For Java, well, it's more or less a .class file, etc. Once the front end can understand your dependency matrix, we then invoke the SDK compiler (i.e. GCC for iPhone, Java for Android) to then compile your application into the final native binary.
So, a simple way to think about it is that your JS code is compiled almost one to one into the representative symbols in nativeland. There's still an interpreter running in interpreted mode otherwise things like dynamic code wouldn't work. However, its much faster, much more compact and it's about as close to pure native mapping as you can get.
We're obviously still got plenty of room to improve this and working on that. So far in our latest 1.0 testing, it's almost indistinguishable from the same objective-c direct code (since in most cases it's exactly mapped to that). From a CompSci standpoint, we can now however start to optimize things that a human really couldn't easily do that - much like the GCC compiler already does today.
http://stackoverflow.com/questions/4217551/what-happens-to-javascript-code-after-app-is-compiled-using-titanium-mobile
Kevin Whinnery's Answer:
引用
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.
-Kevin Dev Relations Manager
分享到:
相关推荐
**Titanium中文版开发手册** Titanium中文版开发手册是一份专门为中文用户编译的开发者指南,旨在帮助熟悉中文的开发者充分利用Titanium框架进行移动应用的开发。Titanium是一个开源的JavaScript平台,允许开发者...
《TitaniumBackup_6.0.5.1:专业版的安卓备份与恢复解决方案》 在安卓设备的管理和维护中,数据备份与恢复是至关重要的环节。TitaniumBackup_6.0.5.1,这款专业版应用,以其强大的功能和高效的操作,为用户提供了...
Titanium 是一个强大的开源JavaScript框架,专为开发原生移动应用而设计。它允许开发者使用JavaScript编写代码,同时能够利用iOS、Android等平台的原生功能。在涉及到“titanium 打开本地网络”的话题时,我们主要...
[Packt Publishing] Appcelerator Titanium 移动应用开发教程 (英文版) [Packt Publishing] Creating Mobile Apps with Appcelerator Titanium (E-Book) ☆ 图书概要:☆ Develop fully-featured mobile ...
【钛合金(Titanium)插件开发初探】 在移动应用开发领域,Titanium 是一个流行的选择,它允许开发者使用 JavaScript 来构建原生的 iOS 和 Android 应用。Titanium 的核心理念是通过跨平台的 JavaScript API 提供与...
### Titanium Mobile API 知识点详解 #### 一、Titanium Mobile API 概述 Titanium Mobile API 是一款由 Appcelerator 公司提供的用于跨平台移动应用开发的强大工具包。该工具允许开发者使用 JavaScript 编写应用...
在iOS开发中,Titanium是一个流行的跨平台框架,它允许开发者使用JavaScript编写代码,同时能够构建原生的iOS和Android应用程序。"Titanium中支持iOS设备的拖拽"这一主题聚焦于如何在Titanium框架下实现iOS应用的...
Titanium Mobile SDK 3.1.0 是一个用于构建原生移动应用的开发工具,尤其针对iOS和Android平台。这个版本的Apidoc是开发者的重要参考资料,它包含了完整的API文档,帮助开发者理解并使用Titanium框架的各种功能。...
Titanium的架构设计充分考虑到了模块化的需求,下面是其中几个核心模块: - **Titanium.API**:提供了访问Titanium API的基础方法。 - **Titanium.UI**:用于构建用户界面,支持多种组件,如窗口、标签、按钮等。 - ...
Titanium Backup_3.7.4捐赠完全版
**前端开源库-node-titanium-sdk** 前端开发领域中,`node-titanium-sdk`是一个重要的开源库,它基于Node.js环境,为开发者提供了一种使用JavaScript开发原生移动应用的途径。`node-titanium-sdk`是Appcelerator ...
【mac】dvd光盘刻录 Roxio Toast Titanium 17.4.dmg,安装即用
titanium-d1-kickstart.6.1.1.gbin 强大的思科模拟器
atom-titanium, 用于 Titanium 合金的Atom 封装 用于 Titanium 合金的 All-in-One封装这是一个用于 Titanium 合金的Atom 封装。$ apm install titanium-alloy冲突&需要通知Alloy 1.8. x
Google-Cloud-Messaging--Titanium-, 在 Titanium 中,Google云消息传递 Google-Cloud-Messaging--Titanium -注册带有GCM和处理发送到设备的通知的Titanium MODULE 。Android平台使用c2dm进行推送,但是因为c2dm停止...
### 企业级IT架构分享与云计算架构师成长之路 #### 一、企业移动化面临的挑战与解决方案 在当今数字化转型的时代背景下,企业面临着前所未有的移动化挑战。这些挑战主要包括: 1. **应用过多且体验不一致**:企业...
Cisco N7K 模拟器 Titanium 6.1.1 安装方法 本文档将指导用户如何安装 Cisco N7K 模拟器 Titanium 6.1.1,包括虚拟机的设置、模拟器的连接、TFTP 服务器的建立、升级安装包的传输、系统文件的更新等步骤。 一、...
Titanium[1].Backup.Pro.v3.7.2_cnFixed_newkey.apk Titanium[1].Backup.Pro.v3.7.2_cnFixed_newkey.apk
钛备份 Titanium Backup,备份你的程序及程序数据,并支持定时备份等功能。 功能很强大,有此软件,不管你的格机还是重刷ROM,在重装软件时都是无痛的,非实适用经常捣鼓手机有机友! 解锁器使用说明: 1.安装钛...