# How to get asset folder path in android native activity?

I am trying to create a small game with android native activity. I wish to load textures using stb image. I don't know how to get the path to assets folder. Is there any API to get path to apk directory so that I can use that to get textures? Thanks.

Reading assets in C or C++ is actually very tricky in Android.

You need to go via the AssetManager, and in Java-side code, you need to do this in your NativeActivity class:

AssetManager mgr = this.getApplicationContext().getResources().getAssets();


And then pass this manager to your C code.

Actually reading assets can be tricky, as it is read from compressed archived, but there is an amazing trick available that remaps the FILE functionality.

Look at android_fopen.h + android_fopen.c on how to do that.

With this trick, you can then fopen() and fread() your assets, and have the assetmanager do all the work under water.

• Hey, Thanks. The fopen redirection trick worked. Mar 7 '19 at 4:38
• @Ankitsinghkushwah i am glad it worked. Do not forget to accept the answer.
– Bram
Mar 7 '19 at 15:20