在Android上从NativeActivity打开/读取APK资产 [英] fopen/fread APK Assets from NativeActivity on Android

查看:167
本文介绍了在Android上从NativeActivity打开/读取APK资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只能找到2010年或更早版本的解决方案.所以我想看看对此是否还有最新的立场.

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.

我想避免使用Java,而纯粹使用C ++来访问存储在APK中的文件(大约1MB以下).使用AssetManager意味着我无法访问其他操作系统(包括iOS)上的其他文件.

I'd like to avoid using Java and purely use C++, to access files (some less-or-more than 1MB) stored away in the APK. Using AssetManager means I can't access files like every other file on every other operating system (including iOS).

如果没有,C ++中是否有一种方法可以将fopen/fread映射到AssetManager API?

If not, is there a method in C++ where I could somehow map fopen/fread to the AssetManager APIs?

推荐答案

我实际上找到了解决该问题的优雅方法,并且

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

摘要是:

  • AAssetManager API具有NDK绑定.这样一来,您就可以从APK加载资产.
  • 可以结合使用一组知道如何对任何内容进行读取/写入/查找并将它们伪装成文件指针(FILE *)的功能.
  • 如果我们创建一个使用资产名称的函数,使用AssetManager打开它,然后将结果伪装为FILE *,那么我们将拥有与fopen非常相似的东西.
  • 如果我们定义一个名为fopen的宏,则可以用我们的函数替换该函数的所有用法.

我的博客有完整的文章,以及您需要用纯C语言实现的所有代码.我用它来构建Android的lua和libogg.

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.

这篇关于在Android上从NativeActivity打开/读取APK资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆