[TIMOB-16678] Android: File.read() of JS files under Resources directory returns empty string for device/production builds
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-09-19T21:35:25.000+0000 |
Affected Version/s | 2014 Sprint 03 |
Fix Version/s | Release 7.5.0 |
Components | Android |
Labels | android, file, parity, read |
Reporter | Alejandro F. Carrera |
Assignee | Joshua Quick |
Created | 2014-03-22T11:15:46.000+0000 |
Updated | 2019-12-09T19:11:20.000+0000 |
Description
*Summary:*
File.read()
is unable to read encrypted assets such as .js
files. This only happens when doing a device build or production build. It can only read .js
files from the "Resources" directory when building for the Android Emulator (aka: "development" build) since .js
files are not encrypted in this case.
iOS is able to successfully read encrypted assets such as .js
.
*Steps to Reproduce:*
Create a Titanium app with the below code for it's "app.js".
Build and run on the Android emulator.
Notice that the alert dialog displays the "app.js" code. (This is good.)
Build and run on a physical Android device.
Notice that the alert dialog on startup is empty. (This is bad. Failed to read "app.js".)
var file = Ti.Filesystem.getFile("app.js");
alert(file.read().text);
*Expected Result:*
Android should be able to read encrypted .js
files just like iOS.
----
*Original description from Alejandro:*
You have a .js file at Resources/lib named library.js with content:
var a = "hello world";
if you try read the file like a text plain file
var value = Ti.Filesystem.getFile(Ti.Filesystem.getResourcesDirectory(), "lib/library.js").read().toString();
value should be var a = \"hello world\";
, but value is empty -> "".
if you change library.js to library.lib or other extension is fine.
Resolving this ticket as a duplicate of TIMOB-2478.
Closing ticket as duplicate and links to the related ticket have been provided above.
Re-opening since this is a legit issue.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/10112
The diff can be found here... https://github.com/appcelerator/titanium_mobile/pull/10112/commits/aa83bf58d393c74a5fbef8ee3d4feeff4b7a06fa
FR Passed.
File.read()
can successfully read encrypted.js
files from Resources directory when built for device. Studio Ver: 5.1.1.201809051655 SDK Ver: 7.5.0 local build OS Ver: 10.13.5 Xcode Ver: Xcode 9.4.1 Appc NPM: 4.2.13 Appc CLI: 7.0.6 Daemon Ver: 1.1.3 Ti CLI Ver: 5.1.1 Alloy Ver: 1.13.2 Node Ver: 8.9.1 NPM Ver: 5.5.1 Java Ver: 10.0.2 Devices: ⇨ google Nexus 5 (Android 6.0.1) ⇨ google Nexus 6P (Android 8.1.0) Emulator: ⇨ Android 4.1.2, Android 8.1PR Merged.
Verified the fix on SDK 7.5.0.v20181004095510. Works fine. Closing.