Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24654] Android: Hybrid CommonJS and Native Modules don't export the commonjs code

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2017-05-09T15:55:10.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.1.0
ComponentsTooling
Labelsmerge-6.1.0, mobilesdk, module, user_experience, validate
ReporterAndrea Vitale
AssigneeChristopher Williams
Created2017-05-03T17:24:12.000+0000
Updated2017-06-08T15:49:58.000+0000

Description

When I create a pure Javascript Module, any exported method is accessible. In detail for the module I've:

Created a new Mobile Module Project, from Appcelerator Studio, with id (for example) it.module.test

Inside _assets_ folder, I've created a js file called _it.module.test.js_

Into _it.module.test.js_ I have:

module.exports = { 
   something: "hi" 
}
Now I package this module directly from Appcelerator Studio and install this module inside a Test Application. Into this application I do:
var module = require("it.module.test");
Ti.API.info(module.something);
And the result is *null*. The problem is that the native module classes are being called instead of the CommonJS ones as per the docs. __UPDATE__ After several tests, it seems that the problem is the Titanium SDK 4.0.0. When I create the module project inside Appcelerator Studio and selecting a previous version of Titanium SDK (3.4.1 for example) all works perfectly with the same code.

Comments

  1. Christopher Williams 2017-05-09

    6_1_X PR was here https://github.com/appcelerator/titanium_mobile/pull/9036 and is merged.
  2. Abir Mukherjee 2017-05-09

    FR passed for 6.2.0. For 6.1.0, the PR was merged so I tested it on the installed SDK where the fix appears, 6.1.0.v20170509114242 Node Version: 6.10.1 NPM Version: 3.10.10 Mac OS: 10.12.4 Appc CLI: 6.2.0 Appc CLI NPM: 4.2.9 Titanium SDK version: 6.1.0.v20170509114242, and locally installed 6.2.0 Appcelerator Studio, build: 4.8.1.201612050850 Xcode 8.3.2 Android 6.0.1 device I used Chris's demo code above, and followed the appropriate test steps. I installed the app and saw an alert pop up with a message "hi".
  3. Andrea Vitale 2017-05-25

    Using the 6.0.1.RC I'm unable to build. Here is the error:
       ndk.build.local:
       
       compile:
           [javac] Compiling 3 source files to /Volumes/Data/Development/Appcelerator/Modules/commonjs-test/android/build/classes
           [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
           [javac] /Volumes/Data/Development/Appcelerator/Modules/commonjs-test/android/build/generated/java/CommonJsSourceProvider.java:2
       6: error: cannot access AssetCryptImpl
           [javac]             AssetCryptImpl source = new AssetCryptImpl();
           [javac]             ^
           [javac]   bad source file: /Volumes/Data/Development/Appcelerator/Modules/commonjs-test/android/build/generated/java/it/andreav
       itale/commonjs/test/AssetCryptImpl.java
           [javac]     file does not contain class it.andreavitale.commonjs.test.AssetCryptImpl
           [javac]     Please remove or make sure it appears in the correct subdirectory of the sourcepath.
           [javac] 1 error
       
       
       BUILD FAILED
       /Users/Andrea/Library/Application Support/Titanium/mobilesdk/osx/6.1.0.v20170524162819/module/android/build.xml:249: Compile failed
       ; see the compiler error output for details.
       
  4. Andrea Vitale 2017-05-26

    Sorry for the previous comment. I'm unable to edit it to wrap my log in a gist. I found a reason: building with ant will give me the error above, building with app ti run -p android --build-only the build process ends without errors. But now I found another issue: the build fails when there are two or more js files inside the /assets/ folder. Here is a log that I hope can helps you to find a solution: [build log error](https://gist.github.com/AndreaVitale/32c06ad366202ee31c5e5419a5a6fbb1)
  5. Christopher Williams 2017-06-06

    The issue [~Andrea.Vitale] mentions is actually breaking our ability to recompile the sync server client module from TIMOB-23590. Looking into it now.
  6. Christopher Williams 2017-06-06

    6_1_X/6.1.1 PR: https://github.com/appcelerator/titanium_mobile/pull/9117 master/6.2.0 PR: https://github.com/appcelerator/titanium_mobile/pull/9116
  7. Andrea Vitale 2017-06-08

    Verified the fix, it works! Thank you.

JSON Source