Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » I can't get my Android game to load assets

This thread is locked; no one can reply to it. rss feed Print
I can't get my Android game to load assets
olddog
Member #20,687
August 2021

Hello,
I am trying to port my Allegro 5 game to Android. I followed the instructions to setup in Android studio. Game compiles and runs, but can't access its assets.
I see in the apk (by unzipping it) that my assets directory is present. In Android studio, my assets directory is under src/main/assets. However, I can't find any asset file. I call:

al_android_set_apk_file_interface();
al_android_set_apk_fs_interface();

In the beginning of main() right after al_init. However,
I can't access any file (and they appear to not exist).
I tried loading using PhysFS by calling:

PHYSFS_init(argv_0);
PHYSFS_mount(".", "/", 1);
PHYSFS_mount("/", "/", 1);
...
// Then I call:
al_set_physfs_file_interface();

However, all calls to load assets fail, for example:

font = al_load_font("myfont.ttf",12,0);

Returns null.

Any help greatly appreciated.
Thanks

Elias
Member #358
May 2000

Does it work without physfs?

--
"Either help out or stop whining" - Evert

olddog
Member #20,687
August 2021

yes, it appears I can load non zip files (not sure about .dat files), but I can load fonts, bitmaps etc. Once I call the physfs functions, it can't access any file (or at least not the files I requested). I am thinking to just unpack all the data files into the asset directory and reference the files directly instead of trying to figure out physfs.

Elias
Member #358
May 2000

It's a bit weird since the .apk itself is a .zip file. So to read a .zip file inside of /assets in a way you'd need to chain al_android_set_apk_file_interface (to read the .zip inside of /assets in the .apk) with physfs (to read within the .zip). I never tried but I think we don't support chaining of file interfaces so this probably does not work. (It sounds like chaining is a useful feature though, so maybe we should add support for it.)

Another way to get it to work would be to point physfs to the .apk file. Then it can just read it as a .zip (and then a .zip inside that .zip, assuming that's supported by physfs). However I'm not sure if Android allows you to find your own .apk, but it probably does. So once you have the APK path you can instruct physfs to read from it (and you won't need al_android_set_apk_file_interface at all).

The way I'm using is like you said - I just copy my "data" folder into "assets" then access it with al_android_set_apk_file_interface() which will read from there.

--
"Either help out or stop whining" - Evert

olddog
Member #20,687
August 2021

Thank you for the helpful information. I will try it out, but I am ok with just copying everything into the assets directory and accessing files directly.

Go to: