Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15821] Android: Unable to access files in Resources folder

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2013-11-26T22:47:32.000+0000
Affected Version/sRelease 3.2.0
Fix Version/s2013 Sprint 24, 2013 Sprint 24 Core, Release 3.2.0
ComponentsAndroid
LabelsSupportTeam, module_android, qe-testadded, regression, triage
ReporterDan Tamas
AssigneeChris Barber
Created2013-11-25T15:14:22.000+0000
Updated2014-05-30T20:46:43.000+0000

Description

It seems that for some reason the files in the Resources folder are not found anymore. The testcase is for a sound file, but the same happens if I try to simply get a file with
(Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory ,'core/data_providers/phone_db.js').read().text
*Testcase* app.js
var win = Ti.UI.createWindow({
	backgroundColor:'#f00'
});

win.open();



var newMsgSound = Titanium.Media.createSound({
	url: '/samsung_sherbet.mp3',
	preload: true
});
newMsgSound.play();

result:
11-25 16:09:33.319: E/TiSound(17910): (KrollRuntimeThread) [524,525] Error setting file descriptor: 
11-25 16:09:33.319: E/TiSound(17910): java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
11-25 16:09:33.319: E/TiSound(17910): 	at android.content.res.AssetManager.openAssetFd(Native Method)
11-25 16:09:33.319: E/TiSound(17910): 	at android.content.res.AssetManager.openFd(AssetManager.java:379)
11-25 16:09:33.319: E/TiSound(17910): 	at ti.modules.titanium.media.TiSound.initializeAndPlay(TiSound.java:100)
11-25 16:09:33.319: E/TiSound(17910): 	at ti.modules.titanium.media.TiSound.play(TiSound.java:212)
11-25 16:09:33.319: E/TiSound(17910): 	at ti.modules.titanium.media.SoundProxy.play(SoundProxy.java:151)
11-25 16:09:33.319: E/TiSound(17910): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
11-25 16:09:33.319: E/TiSound(17910): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:159)
11-25 16:09:33.319: E/TiSound(17910): 	at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:289)
11-25 16:09:33.319: E/TiSound(17910): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:185)
11-25 16:09:33.319: E/TiSound(17910): 	at android.os.Handler.dispatchMessage(Handler.java:95)
11-25 16:09:33.319: E/TiSound(17910): 	at android.os.Looper.loop(Looper.java:156)
11-25 16:09:33.319: E/TiSound(17910): 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
11-25 16:09:33.319: I/MediaPlayer(17910): setLPAflag() in
11-25 16:09:33.319: I/MediaPlayer(17910): mContext is null, can't getMirrorDisplayStatus!!!
11-25 16:09:33.319: I/MediaPlayer(17910): setLPAflag() out
11-25 16:09:33.319: E/MediaPlayer(17910): prepareAsync called in state 1
11-25 16:09:33.329: W/TiSound(17910): (KrollRuntimeThread) [7,532] Issue while initializing : 
11-25 16:09:33.329: W/TiSound(17910): java.lang.IllegalStateException
11-25 16:09:33.329: W/TiSound(17910): 	at android.media.MediaPlayer._prepare(Native Method)
11-25 16:09:33.329: W/TiSound(17910): 	at android.media.MediaPlayer.prepare(MediaPlayer.java:1341)
11-25 16:09:33.329: W/TiSound(17910): 	at ti.modules.titanium.media.TiSound.initializeAndPlay(TiSound.java:153)
11-25 16:09:33.329: W/TiSound(17910): 	at ti.modules.titanium.media.TiSound.play(TiSound.java:212)
11-25 16:09:33.329: W/TiSound(17910): 	at ti.modules.titanium.media.SoundProxy.play(SoundProxy.java:151)
11-25 16:09:33.329: W/TiSound(17910): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
11-25 16:09:33.329: W/TiSound(17910): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:159)
11-25 16:09:33.329: W/TiSound(17910): 	at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:289)
11-25 16:09:33.329: W/TiSound(17910): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:185)
11-25 16:09:33.329: W/TiSound(17910): 	at android.os.Handler.dispatchMessage(Handler.java:95)
11-25 16:09:33.329: W/TiSound(17910): 	at android.os.Looper.loop(Looper.java:156)
11-25 16:09:33.329: W/TiSound(17910): 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)

Comments

  1. Tim Poulsen 2013-11-25

    Regression? Testcase works fine in 3.1.3GA.
  2. Dan Tamas 2013-11-26

    Could we prioritise this a little? It's a showstopper for us. Thank you.
  3. Allen Yeung 2013-11-26

  4. Dan Tamas 2013-11-26

    Fix version 3.3.0?
  5. Ingo Muschenetz 2013-11-26

    And merge-3.2.0 label. We're now in backport season.
  6. Malcolm Hollingsworth 2013-11-26

    Surely this is a blocker?
  7. Dan Tamas 2013-11-26

    @Ingo, what does this means? That you are working in 3.3.0 but until 3.2.0 will be released, the fix will be also back ported to 3.2.0 ? Thnx
  8. Ingo Muschenetz 2013-11-26

    We have branched for 3.2.X, so we will be making the fix for 3.2.0 _and_ 3.3.0
  9. Dan Tamas 2013-11-26

    @Ingo That made me happy! :)
  10. Ingo Muschenetz 2013-11-26

    Since there is some confusion about our process, I'll detail it here:

    Tickets are always resolved in the master branch first. As of yesterday, we created a 3.2.X branch in git, and master became 3.3.0

    However, it is important this goes into 3.2.0. Thus, we add a merge-3.2.0 label.

    Once we've resolved the ticket in master, it's marked "Resolved".

    We then set up a backport PR against the 3.2.X branch.

    Once the ticket is resolved in 3.2.X, we remove the merge-3.2.0 label and add the fix version of 3.2.0

    This process is done to make sure the dev and QE teams know where the fix sits and can be properly tested. For developers, the key thing is to look at the fix version fields, or the labels. You'll now see a bunch of merge-3.2.0 tags (meaning it will go into 3.2.0), or merge-3.2.1 tags (meaning it will go into 3.2.1).
  11. Dan Tamas 2013-11-26

    Thank you :)
  12. Chris Barber 2013-11-26

    Master pull request: https://github.com/appcelerator/titanium_mobile/pull/5033 3_2_X pull request: https://github.com/appcelerator/titanium_mobile/pull/5034
  13. Allen Yeung 2013-11-26

    To test: Run the sound and movie tests in KS. Phone > Play Movie > Local Phone > Sound > Local
  14. Lokesh Choudhary 2013-11-27

    Verified the fix & we can access the local resources in side the app. Tested it using KS, Phone > Play Movie > Local & Phone > Sound > Local Works as expected. Closing. Environment: Appcel Studio : 3.2.0.201311252112 Ti SDK : 3.2.0.v20131126144841 Mac OSX : 10.8.5 Alloy : 1.3.0-alpha6 CLI - 3.2.0-alpha3 Nexus 4 - android 4.2
  15. Dan Tamas 2013-11-27

    @Chris I get this error with the build Lokesh tested
        [INFO]  Writing unsigned apk: /Volumes/Work/clients/tobias_group_time/TEAMWIRE/gt/build/android/bin/app-unsigned.apk
        
        /usr/local/lib/node_modules/titanium/node_modules/longjohn/dist/longjohn.js:184
                throw e;
                      ^
        RangeError: Maximum call stack size exceeded
        Dans-MacBook-Pro-2:gt Dan$ node -v
        v0.10.21
        
    The only thing that comes to my mind is that I have A LOT of files in the app. Any thought? Thank you.
  16. Ingo Muschenetz 2013-11-27

    [~rborn], thanks! 1. How many files do you have exactly? Can you give a count from the terminal? 2. Can you try upping the stack size by passing it in as part of the command to see if that helps? For example, in the code-analyzer, we used the following command: "node --stack-size=10000 /usr/local/bin/titanium analyze -p -A -R " Does that help if you play with that stack size value?
  17. Dan Tamas 2013-11-27

    Files:
        Dans-MacBook-Pro-2:gt Dan$ find Resources/ -name "*" | wc -l
            1534
        
    Trying to increase the stack size, none of the below work
        node --stack-size=50000 /usr/local/bin/ti build -p android -b
        
        or 
        
        node --max-stack-size=50000 /usr/local/bin/ti build -p android -b
        
        
    :( Am I doing it wrong ?
  18. Dan Tamas 2013-11-27

    analyze gives me this:
        [INFO]  Analyzing project at "/Volumes/Work/clients/tobias_group_time/TEAMWIRE/gt"
        [WARN]  warn: Could not read plugin information in "/Applications/Appcelerator_Studio/configuration/org.eclipse.osgi/bundles/309/1/.cp/enterprise/node_modules": Error: ENOENT, open '/Applications/Appcelerator_Studio/configuration/org.eclipse.osgi/bundles/309/1/.cp/enterprise/node_modules/package.json'
        SDK version 3.2.0 is not available
        
  19. Ingo Muschenetz 2013-11-27

    Likely right, but that fix may not work here. I'm reviewing other instances of that error: TIMOB-13388, and it may involve a different change. I'll let [~cbarber] weigh in. Analyze likely won't work unless you install the 3.2.0-era version of the code analyzer, which we've not publicized yet.
  20. Dan Tamas 2013-11-27

    Ok, thanks
  21. Dan Tamas 2013-11-27

    So, after Stephen asked why excluding some file formats instead of only compressing the js ones, I did this
        	// var store = this.uncompressedTypes.indexOf(entry.entryName.split('.').pop()) != -1;
        	var store = entry.entryName.split('.').pop() != 'js';
        
    in https://github.com/appcelerator/titanium_mobile/blob/master/android/cli/commands/_build.js#L3566 The error is gone and the sound gets on the device with this command
        node --stack-size=50000 /usr/local/bin/ti build -p android -T device -b --skip-js-minify
        
    however the normal build still complains about the stack size. [cbarber] As Stephen was asking, why do we eliminate some files instead of compressing only the ones we need? If I add some files with a weird extension, this will break. Also the fix has another issue (the sound works ok now, except the stack error) I have to eval a js file - don't ask why, external module for gcm that needs to take some info from the app Well, this breaks too, and because of this I cannot show the notification.
        
        	eval(Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory ,'/core/data_providers/phone_db.js').read().text);
        	eval(Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory ,'/core/data_providers/thread.js').read().text);
        
        
    ddms error:
        11-27 15:34:38.993: I/TiAPI(4398):  gt: gcm.js ================ alert 
        11-27 15:34:39.013: E/TiBlob(4398): (KrollRuntimeThread) [137,207396] Resources/core/data_providers/phone_db.js
        11-27 15:34:39.013: E/TiBlob(4398): java.io.FileNotFoundException: Resources/core/data_providers/phone_db.js
        11-27 15:34:39.013: E/TiBlob(4398): 	at android.content.res.AssetManager.openAsset(Native Method)
        11-27 15:34:39.013: E/TiBlob(4398): 	at android.content.res.AssetManager.open(AssetManager.java:363)
        11-27 15:34:39.013: E/TiBlob(4398): 	at android.content.res.AssetManager.open(AssetManager.java:337)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.titanium.io.TiResourceFile.getInputStream(TiResourceFile.java:81)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.titanium.TiBlob.getInputStream(TiBlob.java:313)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.titanium.TiBlob.guessContentTypeFromStream(TiBlob.java:193)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.titanium.TiBlob.loadBitmapInfo(TiBlob.java:209)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.titanium.TiBlob.blobFromFile(TiBlob.java:124)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.titanium.TiBlob.blobFromFile(TiBlob.java:107)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.titanium.io.TiResourceFile.read(TiResourceFile.java:125)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.titanium.TiFileProxy.read(TiFileProxy.java:239)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:159)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:289)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:185)
        11-27 15:34:39.013: E/TiBlob(4398): 	at android.os.Handler.dispatchMessage(Handler.java:95)
        11-27 15:34:39.013: E/TiBlob(4398): 	at android.os.Looper.loop(Looper.java:156)
        11-27 15:34:39.013: E/TiBlob(4398): 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
        
        
    there is more but basically it's the same "file not found" error This was working too in 3.1.3 Sorry to be such a a pita :)
  22. Ingo Muschenetz 2013-11-27

    [~rborn] No, this is helpful! FWIW, we did rewrite the ENTIRE Android build infrastructure, so it's to be expected something doesn't quite work as before, and we can't write enough test cases to cover every possible usage.
  23. Dan Tamas 2013-11-27

    ...like 100000000000000 files in the project :D
  24. Ingo Muschenetz 2013-11-27

    http://support.apple.com/kb/ht2422. 2.1 B is the max. 2100000000. We can't support 100 trillion :) (100,000,000,000,000)
  25. Dan Tamas 2013-11-27

    haha :D
  26. Chris Barber 2013-11-27

    [~rborn] When we call aapt, it generates app.ap_. We then open this file as a zip and combine its contents with the contents of all jar file dependencies. The result is the unsigned apk file. Turns out that certain resources (images, videos, audio, etc) must NOT be compressed inside the apk file. Before yesterday, every file in the unsigned apk was compressed. Turns out that's bad. After investigating what the old Android builder.py does, it turns out they only compresses certain file types. The fix for this ticket is to exclude files from being compressed, thus matching the old behavior. Since we're now using a different code path inside the "archiver" node.js module when creating the unsigned apk, it appears a stack size bug has appeared. I'm investigating a fix. Stay tuned.
  27. Dan Tamas 2013-11-27

    Thnx Chris.

JSON Source