[TIMOB-24654] Android: Hybrid CommonJS and Native Modules don't export the commonjs code
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | Critical |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2017-05-09T15:55:10.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 6.1.0 |
| Components | Tooling |
| Labels | merge-6.1.0, mobilesdk, module, user_experience, validate |
| Reporter | Andrea Vitale |
| Assignee | Christopher Williams |
| Created | 2017-05-03T17:24:12.000+0000 |
| Updated | 2017-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.
6_1_X PR was here https://github.com/appcelerator/titanium_mobile/pull/9036 and is merged.
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".
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.Sorry for the previous comment. I'm unable to edit it to wrap my log in a gist. I found a reason: building with
antwill give me the error above, building withapp ti run -p android --build-onlythe 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)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_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
Verified the fix, it works! Thank you.