Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

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

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-06-15T15:25:14.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sRelease 2.1.0, Sprint 2012-12 Core
ComponentsTiAPI
Labelscore
ReporterBill Dawson
AssigneeNeeraj Gupta
Created2012-05-30T15:12:38.000+0000
Updated2017-03-24T21:02:01.000+0000

Description

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

Description

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
Ti.API.info(m.test());
Ti.API.info(m.example());
* In the console/logcat, you should see info statements for "hello from inside the module's commonjs file" and "hello world".

Comments

  1. Lee Morris 2017-03-24

    Closing ticket as fixed.

JSON Source