While it works fine in the simulator, when build for android, the code returns a runtime error:
The (simplified so that it has only the error) project is at: https://github.com/koyan/dirtest
Steps to reproduce:
- Open the project in the simulator
You should see the contents of the directory cards appear in the simulator screen - Build for Android
- Install and run
- The the runtime error
Folder structure
cards/file1.lua cards/file2.lua main.lua
main.lua:
local lfs = require( "lfs" ) local doc\_path = system.pathForFile( "cards" ) textY = 100 for file in lfs.dir( doc\_path ) do -- "file" is the current file or directory name local filenameText = display.newText( file, display.contentCenterX, textY, native.systemFont, 40 ) filenameText:setFillColor( 1, 1, 1 ) textY = textY + 50 print ("The file is: " .. file) end
In the simulator it lists the files in the folder as expected, showing them on the screen.
When build, installed and run on android, it gives the following error:
Runtime Error
/full/path/for/the/folder/in/my/computer/dirtest/main.lua:8 bad argument for #1 to ‘dir’ (string expected, got nil)
Corona Simulator reports: Version 2020.3582 (2020.4.19)
Build with a macOs Catalina
I haven’t tested on other platforms
I have opened a bug about this, but I am posting here in case anyone else either knows the solution, or meets the same problem.