I have some code:
AAsset* pAsset = AAssetManager_open(pAssetManager, "asset_test.txt", AASSET_MODE_STREAMING); DebugPrint(pAsset?"pAsset not NULL\n":"pAsset NULL"); if (pAsset) { char buf[1024]; AAsset_read(pAsset, buf, sizeof(buf)); DebugPrint(buf); AAsset_close(pAsset); }
This code always prints "pAsset NULL" in logcat.
I put the asset_test.txt file in my assets directory, and I looked in the .apk to make sure it exists by renaming the .apk to .zip and opening it with 7zip.
I have some more code:
AAssetDir* pAssetDir = AAssetManager_openDir(pAssetManager, sDirectory.c_str()); if (!pAssetDir) { DebugPrint("pAssetDir NULL\n"); return; } const char* pszDir; while ((pszDir = AAssetDir_getNextFileName(pAssetDir)) != NULL) { DebugPrint(pszDir); } AAssetDir_close(pAssetDir);
This code prints nothing. In other words, no files are ever found in the assets directory, regardless of what paths I pass into it.
Note: DebugPrint is just a prettier looking wrapper around __android_log_print().