1

I use AssetManager in C++ code to load my assets. But if there exists file with the same name in app internal directory AssetManager check it first and load it.

Is it possible to set AssetManager to avoid files in internal app dir and check only assets files?

UPD: I was wrong. AssetManager works normally.

Ivan
  • 11
  • 3

1 Answers1

0

Same behavior for Java and NDK. Both use AssetManager class under the hoods. For earlier versions of AssetManager.cpp, AssetManager::open() works the same.

It is, theoretically, possible to tweak AssetManager behavior (after all, AssetManager.addAssetPaths() is public, and can be fetched via reflection), but there is no documented way to do this, which means that you cannot know if your hack will work on the next version of Android, or on some vendor's custom version of the system.

I would recommend not to do such tricks. Much safer to check if the same file exists in internal directory, and delete or rename it, if necessary. But anyways, the asset manager does not normally read from the internal files directory for the app.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • 1
    Thank your very much. Your answer is very clean and helpful. – Ivan Nov 12 '17 at 11:19
  • But now I have a problem: your observation does not reproduce here. Maybe you could show your code? Maybe this happens on certain platforms? – Alex Cohn Nov 12 '17 at 12:12
  • Yeah. Just have a look to this file in my repo. https://bitbucket.org/akk0rd87/akk0rdsdk/src/c14738567735457e9e1bd603a576648d6bf0be2d/framework/platforms/android/android_wrapper.cpp?at=master&fileviewer=file-view-default GetAsset2Buffer procedure – Ivan Nov 12 '17 at 13:39
  • In my experiment, I could not change the result of **AAsset_read()** by adding files to internal dir. – Alex Cohn Nov 12 '17 at 13:51
  • I use this code to create file https://pastebin.com/7THK5U09 I don't really understnand where it creates file, but AssetManager shows me it when I expect my asset file with the same name but another text. – Ivan Nov 12 '17 at 14:01
  • According to source code [SDL_rwops.c](https://www.libsdl.org/tmp/SDL/src/file/SDL_rwops.c) of SDL_RWFromFile it uses FILE *fp = fopen(file, mode); at first – Ivan Nov 12 '17 at 14:05
  • So far so good. But how do you know it overrides AAsset_read() ? – Alex Cohn Nov 12 '17 at 14:11
  • 1
    Sorry. I was mistaken, There is an miskate on my test case. It seems to be AssetsManager really read only from assets. Thank you very much. – Ivan Nov 12 '17 at 14:36
  • It doesn't, as you can see in the sources. It looks for system assets, and from some 'overlays', and from **ANDROID_ROOT** - but it does not normally read from app internal files. – Alex Cohn Nov 12 '17 at 14:52