Loading Bundle Resources on mobile

I’m trying to load a bundled .csv and .png files in a game to be released on both Facebook Instant and mobile. It works on Facebook Instant and in the local IDE.

I have created a test app which returns the same error:

ERROR:SCRIPT: /main/main.script:16: attempt to index local 'file' (a nil value)
stack traceback:
	/main/main.script:16: in function </main/main.script:1>

Code:

function init(self)

	local sys_info = sys.get_sys_info()

	local filename = "test.txt"
	
	if sys_info.system_name == "Android" or sys_info.system_name == "iPhone OS" then

		local application_path = sys.get_application_path()
		local file_path = application_path .. "/" .. filename
		
		print( " Application path: " .. application_path )
		print( " Absolute file path: " .. file_path )

		local file = io.open(file_path, "rb")
		local data = file:read("*all")
		file:close()

		pprint( data )
		
	elseif sys_info.system_name == "HTML5" then

		http.request(filename, "GET",
		function( _self, _, response )

			if response.status ~= 200 and response.status ~= 304 then
				-- Error
			else
				pprint( response.response )
			end

		end)

	elseif sys_info.system_name == "Windows" or sys_info.system_name == "Darwin" then

		local file_path = "bundle_resources/common/" .. filename
		local file = io.open(file_path, "rb")
		local data = file:read("*all")
		file:close()
		pprint( data )
		
	end
	
end

Unzipping the .apk reveals the bundled file in the root folder:

I must be close! Any idea why it’s not working?

Project settings:

File structure:

Loading files from within the APK is going to be tricky I think. Why not use custom resources and sys.load_resource() instead?

Or, hmm, @dapetcu21, how are you loading the fmod banks on Android?

That’s an option. It would be neat if I could avoid it, though, because then I could have one code base which exports to both Android/iOS and Facebook Instant.

On Android, FMOD does it for us. We just pass "android-resource://banks/My Bank.bank" to it or something like that.

I think it may help

2 Likes

Thanks @AGulev. I tried to use “file:///android_asset/” instead as the path, but it still can’t find the file. I think I’m swimming against the current here, so it’s looking like it’s time to branch this game. :slight_smile:

Is the file located in the /assets folder ?

In don’t understand?
Custom resources are platform agnostic.

I’m using Bundle Resources, not Custom Resources.

I was referring to your rationale of not using custom resources.
It seems to me that it should work fine for this? But perhaps I’m missing something?

1 Like

I use bundle resources in the Facebook Instant version of the game, to load external .png files on the fly after the game has started, to save download time. The original plan was to use the same code base for the mobile version. If I swapped to custom resources instead, I would lose the benefit of loading these files on demand, because they would also be bundled with the game.

All of this is theoretical now anyway, as I’ve branched the game and started working on a mobile only version. :slight_smile:

2 Likes