Search code examples
c++android-ndkvisual-studio-2019android-assetmanager

Android Native Activity AssetManager VS 2019 Not Working


I am trying to load an image and a text file using the AAssetManager in the Android Native Activity in VS 2019. I've tried every combination of paths I could think of to get AAssetManager_openDir or AAssetManager_open to give me a file. Solutions I've found elsewhere were related to incorrect paths or the AAssetManager object wasn't valid.

Here is how I'm trying to get access to my image and text files.

    AAssetManager* pMan = m_pApp->activity->assetManager;
    AAsset*     pAsset = AAssetManager_open(pMan, "drawable\\testpng", AASSET_MODE_BUFFER); // Always returns NULL
    AAssetDir*  pAssetDir = AAssetManager_openDir(pMan, "res\\drawable");
    const char* szFilename;
    while ((szFilename = AAssetDir_getNextFileName(pAssetDir)) != NULL)
    {
        // 'szFilename' is always NULL and this print never gets hit
        __android_log_print(ANDROID_LOG_DEBUG, "Debug", szFilename);
    }

This is my Android.Packaging project.

Android Package Project

Android Manifest

<string name="testpng">drawable\test.png</string>
<string name="testdrawtxt">drawable\testtext.txt</string>
<string name="testpng2">drawable\assets\test2.png</string>
<string name="testdrawtxt2">drawable\assets\testtext2.txt</string>

And finally the actual output directory Resources output directory

The asset manager is valid as far as I know. What am I doing wrong?


Solution

  • Assets should not be under res, but on the same level of hieararchy.