Downloading CoronaCards resources in the Android cache files

Hey guys,

I’m trying to download a full zip containing the resources for the game (including lua files, sounds, etc) and unzipping it on the cache directory of Android and setting that path to the init() function of the CoronaView.

It seems that the main.lua is loaded but the following files are not loaded and the JNI can’t find the other lua files. The error is : 

ERROR: Runtime error

                                                             /Users/jenkins/slaveroot/workspace/CoronaCards/OS/android/subrepos/composer/composer.lua:1453: /Users/jenkins/slaveroot/workspace/CoronaCards/OS/android/platform/resources/init.lua:906: module ‘level’ not found.

The main calls the following “composer.gotoScene(“level”)”

Everything works perfectly if I embed the resources in the assets.

Is it possible to set a custom Android directory to have dynamic runtime games or do the resources have to be in the assets of the apk and embedded from the start?

Let me know if you have any idea, thanks!

T

More logs :

03-02 14:07:49.907 32088-2183/com.tribe.app.debug I/Corona: ERROR: Runtime error /Users/jenkins/slaveroot/workspace/CoronaCards/OS/android/platform/resources/init.lua:906: module 'level3' not found: no field package.preload['level3'] no file '(null)/level3.lua' no file '(null)/level3.lua' no file '/data/app/com.tribe.app.debug-1/lib/arm/liblevel3.so' no file './level3.so' no file '(null)/level3.so' no file '/data/app/com.tribe.app.debug-1/lib/arm/liblevel3.so' no file './level3.so' no file '(null)/level3.so'

The level3.lua file 

[lua]local composer = require “composer”

local scene = composer.newScene()

return scene[/lua]

The main.lua file

[lua]local composer = require “composer”

local level3 = require “level3”

– composer.gotoScene(“level3”)[/lua]

Generally speaking, you are not allowed to load Lua files from arbitrary locations. Google may not care too much but Apple does, so we block loading files from anywhere other than system.ResourcesDirectory.

You may be running into this.

Rob

Hi Rob,

Thanks for you answer. So how would one go about saving downloaded lua files in the system.ResourcesDirectory. Is that even possible from the Android app that embeds the CoronaCards library?

Thanks in advance.

Best,

Tiago

You can’t.  If you’re doing level data, you could save it as a JSON data table and read that in and us json.decode to load your level data.  I believe we support Lua’s loadstring() and it has some capacity to parse and load a Lua file, but idea is to not let you execute code that was downloaded. But you can certainly download data and your existing Lua code can use that to identify image file names or sounds to load, x, y locations to draw the object at etc.

Rob

Thank you for this answer.

May I ask you what’s the reason behind “__[…] idea is to not let you execute code that was downloaded”?

Because Apple says no. It’s a huge security risk.  

Rob

Regarding Tiago84’s question, it’s on Android.

Regarding iOS, actually, the  Apple Developer Program License Agreement says this:

3.3.2 Except as set forth in the next paragraph, an Application may not download or install executable code. Interpreted code may be downloaded to an Application but only so long as such code: (a) does not change the primary purpose of the Application by providing features or Program Agreement Page 15 functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store, ( B) does not create a store or storefront for other code or applications, and © does not bypass signing, sandbox, or other security features of the OS.

Cf. https://download.developer.apple.com/Documentation/License_Agreements__Apple_Developer_Program/Apple_Developer_Program_License_Agreement_20170919.pdf

We all agree that the LUA code qualifies as “interpreted code”, right?

Apple has eased some restrictions. We made loadstring() available to allow some interpreted code to run, but we feel that if we allow this, even with Apple’s new stance on this, it will lead to app rejections.

Rob

Would it be possible to allow it on Android?

I see that Tiago84 asked an Android question, and we are mainly discussing Apple rules here.

PS:

I’m also confused because launching a game from an arbitrary directory with the CoronaView on iOS is actually working.

I’m speculating, but because this is core to Corona, it’s probably a “cross-platform” decision. It’s probably not something that happens at a platform layer.

I’ll ask Engineering to see if I can get a more complete answer.

Rob

Hello Rob,

Any news on this matter?

Thanks!

I don’t have an update. I’ve asked again, but it’s late on a Friday, and this request likely won’t get answered until next week.

More logs :

03-02 14:07:49.907 32088-2183/com.tribe.app.debug I/Corona: ERROR: Runtime error /Users/jenkins/slaveroot/workspace/CoronaCards/OS/android/platform/resources/init.lua:906: module 'level3' not found: no field package.preload['level3'] no file '(null)/level3.lua' no file '(null)/level3.lua' no file '/data/app/com.tribe.app.debug-1/lib/arm/liblevel3.so' no file './level3.so' no file '(null)/level3.so' no file '/data/app/com.tribe.app.debug-1/lib/arm/liblevel3.so' no file './level3.so' no file '(null)/level3.so'

The level3.lua file 

[lua]local composer = require “composer”

local scene = composer.newScene()

return scene[/lua]

The main.lua file

[lua]local composer = require “composer”

local level3 = require “level3”

– composer.gotoScene(“level3”)[/lua]

Generally speaking, you are not allowed to load Lua files from arbitrary locations. Google may not care too much but Apple does, so we block loading files from anywhere other than system.ResourcesDirectory.

You may be running into this.

Rob

Hi Rob,

Thanks for you answer. So how would one go about saving downloaded lua files in the system.ResourcesDirectory. Is that even possible from the Android app that embeds the CoronaCards library?

Thanks in advance.

Best,

Tiago

You can’t.  If you’re doing level data, you could save it as a JSON data table and read that in and us json.decode to load your level data.  I believe we support Lua’s loadstring() and it has some capacity to parse and load a Lua file, but idea is to not let you execute code that was downloaded. But you can certainly download data and your existing Lua code can use that to identify image file names or sounds to load, x, y locations to draw the object at etc.

Rob

Thank you for this answer.

May I ask you what’s the reason behind “__[…] idea is to not let you execute code that was downloaded”?

Because Apple says no. It’s a huge security risk.  

Rob

Regarding Tiago84’s question, it’s on Android.

Regarding iOS, actually, the  Apple Developer Program License Agreement says this:

3.3.2 Except as set forth in the next paragraph, an Application may not download or install executable code. Interpreted code may be downloaded to an Application but only so long as such code: (a) does not change the primary purpose of the Application by providing features or Program Agreement Page 15 functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store, ( B) does not create a store or storefront for other code or applications, and © does not bypass signing, sandbox, or other security features of the OS.

Cf. https://download.developer.apple.com/Documentation/License_Agreements__Apple_Developer_Program/Apple_Developer_Program_License_Agreement_20170919.pdf

We all agree that the LUA code qualifies as “interpreted code”, right?