Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-9314

Native Module Projects (Android/iOS): At runtime, support execution of code originally from both CommonJS file and from native source files.


    • Type: New Feature
    • Status: Closed
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: Release 2.1.0
    • Component/s: TiAPI
    • Labels:
    • Environment:

      Titanium 2.1.0


      This is the super task (specific iOS and Android sub-tasks exist).


      Currently, module projects for both Android and iOS have the option to put Javascript (rather than native) code in assets/[moduleid].js. If that file exists, then at build time the source is compiled/protected and, when distributed, the module is simply whatever is exported in that Javascript – any code that happened to be on the native (*.m, *.java) files – though compiled – is ignored.

      For example, when create either an iOS or Android module project, you get the .m and .java files for the module and a method named example. If you also add a commonjs module file in the form of assets/[moduleid].js, then that example method inside the native source file is not reachable at runtime when the module is used.

      We wish to make the optional CommonJS module file "additive" in the sense that it extends whatever is available via the native source, rather than replaces it.

      Test Case

      • Create a module project for the platform you're testing (iOS or Android).
      • Create a file assets/moduleid.js (replace moduleid with the actual module id) and enter this code:


      exports.test = function() {return "hello from inside the module's commonjs file";};

      • Build/package the module (./build.py for iOS, ant for Android.)
      • Create a Titanium Mobile app.
      • Install the module zip to the app (or up in the Titanium root). No instructions here – it's assumed you know how to install a module.
      • Update tiapp.xml to include the module. (assuming you know how).
      • Put this in app.js:


      var m = require("moduleid"); // replace moduleid with actual module id

      • In the console/logcat, you should see info statements for "hello from inside the module's commonjs file" and "hello world".




            • Assignee:
              ngupta Neeraj Gupta
              billdawson Bill Dawson
            • Watchers:
              2 Start watching this issue


              • Created:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Integration