Search code examples
javascriptobjective-cmobiletitaniumappcelerator

Where does Appcelerator Titanium Mobile cross-compile JS to native code?


From the question "How Does Appcelerator Titanium Mobile Work?" I know that the JS is cross-compiled into native code. But where does this happen? I couldn't find any code for this in the open source Titanium code. The website of Appcelerator also is quite sparse on the cross-compilation part of the process.


Solution

  • In Titanium 1.4 on Windows/Android look in C:\ProgramData\Titanium\mobilesdk\win32\1.4.0\android\compiler.py and you will find:

    def compile_into_bytecode(self,paths):
        jar_path = os.path.join(self.template_dir,"js.jar")
        for package in paths:
            args = [self.java,"-cp",jar_path,"org.mozilla.javascript.tools.jsc.Main","-opt","9","-nosource","-package",package,"-d",self.classes_dir]
            count = 0
            for path in paths[package]:
                # skip any JS found inside HTML <script>
                if path in self.html_scripts: continue
                args.append(path)
                count+=1
                self.compiled_files.append(path)
            if count > 0: run.run(args)