Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16678] Android: File.read() of JS files under Resources directory returns empty string for device/production builds

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2018-09-19T21:35:25.000+0000
Affected Version/s2014 Sprint 03
Fix Version/sRelease 7.5.0
ComponentsAndroid
Labelsandroid, file, parity, read
ReporterAlejandro F. Carrera
AssigneeJoshua Quick
Created2014-03-22T11:15:46.000+0000
Updated2019-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.

Comments

  1. Ritu Agrawal 2014-03-25

    Resolving this ticket as a duplicate of TIMOB-2478.
  2. Lee Morris 2017-03-22

    Closing ticket as duplicate and links to the related ticket have been provided above.
  3. Joshua Quick 2018-07-18

    Re-opening since this is a legit issue.
  4. Joshua Quick 2018-07-18

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10112
  5. Joshua Quick 2018-07-18

    The diff can be found here... https://github.com/appcelerator/titanium_mobile/pull/10112/commits/aa83bf58d393c74a5fbef8ee3d4feeff4b7a06fa
  6. Lokesh Choudhary 2018-09-18

    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.1
  7. Lokesh Choudhary 2018-09-19

    PR Merged.
  8. Keerthi Mahalingam 2018-10-08

    Verified the fix on SDK 7.5.0.v20181004095510. Works fine. Closing.
       Operating System
         Name                        = Mac OS X
         Version                     = 10.13.6
         Architecture                = 64bit
       Node.js
         Node.js Version             = 8.9.1
         npm Version                 = 5.5.1
       Titanium CLI
         CLI Version                 = 5.1.1
       Titanium SDK
         SDK Version                 =7.5.0.v20181004095510
       Device			      =Oneplus 5T Android 8
       					Pixel android 6 emulator 
       

JSON Source