fopen/fread APK Assets from NativeActivity on Android

前端 未结 2 1100
悲哀的现实
悲哀的现实 2021-02-03 14:43

I have only been able to find solutions dated 2010 and earlier. So I wanted to see if there was a more up-to-date stance on this.

I\'d like to avoid using Java and pure

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-03 15:35

    I actually found pretty elegant answer to the problem and blogged about it here.

    The summary is:

    • The AAssetManager API has NDK bindings. This lets you load assets from the APK.
    • It is possible to combine a set of functions that know how to read/write/seek against anything and disguise them as a file pointer (FILE*).
    • If we create a function that takes an asset name, uses AssetManager to open it, and then disguises the result as a FILE* then we have something that's very similar to fopen.
    • If we define a macro named fopen we can replace all uses of that function with ours instead.

    My blog has a full write up and all the code you need to implement in pure C. I use this to build lua and libogg for Android.

提交回复
热议问题