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.
-
4it is open-source. why don't you take a look under the hood ? – Gabriele Petrioli Mar 14 '10 at 22:27
-
17@Gaby I figure if I'm curious then so are others so what better way to spread information than by asking publicly? – Darrell Brogdon Mar 14 '10 at 22:44
-
2@Darrell, i agree completely.. i was not trying to bash you, just thought that the fastest route (if you needed specifics) would be to check the code directly.. apologies if it came out the wrong way .. – Gabriele Petrioli Mar 14 '10 at 23:00
-
@Gaby No worries. I don't disagree with you. But my JS chops are better than my ObjC chops so... :) – Darrell Brogdon Mar 14 '10 at 23:02
-
1small point: Objective-J is a superset of javascript – cobbal Mar 17 '10 at 17:10
-
@cobbal Bah, if you must get technical! :) Fixed. – Darrell Brogdon Mar 17 '10 at 18:27
-
I spent 5 minutes looking for the answer to this question **on the Titanium website**. Couldn't find anything which is a bit ridiculous. So yes, this is a very valid question. – Eric Brotto Nov 13 '12 at 11:55
-
2I asked this question more recently and got a much more up to date answer with info that isn't described in the answers on this page. Here's the question: http://stackoverflow.com/questions/19060554/how-does-titanium-sdk-work-in-the-various-platforms-it-supports-in-2013/19070475#19070475 – B T Sep 28 '13 at 19:33
3 Answers
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.

- 2,368
- 1
- 17
- 9
-
Wow, this really sounds great. Thanks for the clarification. I never imagined that so much effort would have been put into AppCelerator. Keep up the great work! – MrMage Mar 21 '10 at 23:40
-
12Did I get this right that there is no Javascript->Objective-C and Javascript->Java conversion taking place but this is directly to native code? So there is no way to have a look at the created Objective-C or Java code? – janpio Jul 07 '10 at 13:47
-
1Is the compilation done on Titanium's server? I saw that Wikipedia http://en.wikipedia.org/wiki/Appcelerator_Titanium – adib Apr 08 '11 at 01:52
-
1
Like jhaynie said, the application is compiled into native code, but there is still an interpreter in-place to run some javascript, which allows the application to be very dynamic.

- 4,875
- 4
- 32
- 50

- 1,105
- 1
- 12
- 17
If I package my simple ample code I get a ~80MB gzip archive (original Code ~1kB). Within the package - among others - you can find my source html and js files. There are also a lot of libraries (ssl for example) shipped with the package (because you can have low-level access to a lot of things within this framework).
I think that they take your code and wrap around some kind of interpreter software and libraries. In my case it would be like if I pack my html and js code next to a tiny browser that only displays my site.
How ever, as long as the code works on every supported system in the same way its a nice thing.

- 11
- 1
-
4When I open the .ipa that Titanium creates I see what appears to be a standard compiled app. None of the HTML or JavaScript code can be found. – Darrell Brogdon Mar 17 '10 at 16:35
-
1I think what you described is what Cordova does, but Titanium works differently – Rohit Chatterjee Sep 01 '13 at 06:09
-
pack html and js code with a tiny browser... and electron is born 5 years later. – Caio Iglesias Jul 06 '17 at 10:33