Allegro 5, Android, loading assets
Ian Lewis

Hello all,

I'm trying to port an A5 game I've written to Android (previous thread here - I've now got a 64 bit Windows machine)

I've followed these instructions:

and have code building and running, but it fails to load any assets. I've searched a fair bit, but can't seem to find:

- Where I need to put the asset files so that they get included in the .apk when I build the project (The project structure has 4 directories called 'assets'....)

- How I tell allegro where to find them. (I guess I need to start with one of the ALLEGRO_xxx_PATH defines, but I don't know which one. I maybe also need to call al_android_set_apk_file_interface() or possibly al_android_set_apk_fs_interface() but I don't know which, or when!)

Can anyone help me with either of these issues?



Sebastian Krzyszkowiak

After you call "al_android_set_apk_file_interface()", all file related functions from Allegro - - are now using "assets" directory from your APK file.

After you call "al_android_set_apk_fs_interface()", all filesystem related functions from Allegro - - are now using "assets" directory from your APK file.

So you call them depending on what you use in your code.

I don't know anything about Android Studio, so if I were you I'd just place different stuff into those four "assets" directory and see what gets into the apk file (which you can simply unzip as regular zip file).

Ian Lewis

Thanks for that. I hadn't realised I could open the .apk file. I can now see that I have assets in the 'assets' folder.

Sadly, I still can't figure out how to get allegro to see them. The only function I use from either of those links is


but (obviously) I use al_load_bitmap(), al_load_sample() etc. a lot. From what you say, they are unaffected by al_android_set_apk_fs_interface().

When I use either al_get_current_directory() or al_get_standard_path() I get something like


If I peek inside the apk, I see folders called assets (where my assets are) lib, META-INF, res, plus AndroidManifest.xml, and a few more files.

I can't see any relationship between the path and the contents of the apk. I've tried just appending /assets to the path, but that doesn't seem to work.

At the moment, it doesn't seem to make any difference whether I call al_android_set_apk_fs_interface() or not. al_load_xxx calls always return NULL.

Anyone know what I should be doing to set the path so that I can load assets?



Sebastian Krzyszkowiak

Don't use al_get_current_directory nor al_get_standard_path. They are irrelevant once you switch to the apk interface. Use the relative paths.

Functions like al_load_bitmap use the file interface under the hood, so you're interested mostly in al_android_set_apk_file_interface.

After you call that, you should be able to just call al_load_bitmap("my_dir/my_file.png") to access a file assets/my_dir/my_file.png inside the APK.

(AFAIK you should also be able to use absolute paths inside the APK in form "/my_dir/my_file.png". Basically, when using the APK interface, your assets directory becomes the root directory)

Ian Lewis

Ah, thank you! Assets are now loading, and my game is running!



Thread #617058. Printed from