在NDK中使用资源文件 [英] Using resource files in NDK

查看:117
本文介绍了在NDK中使用资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在创建的NDK库,该库需要包含和访问二进制数据文件(扩展名为.dat).我在获取已编译的库以查看此文件时遇到麻烦.为了使事情变得更困难,我在一个库包中执行此操作.

我认为,如果在我的Android.mk文件期间将此.dat文件复制到我的应用程序的resources文件夹中,然后从该应用程序内部访问它,那将是可行的,但是我觉得必须有更好的方法./p>

有什么建议吗?

解决方案

而不是资源,将其放在 assets 文件夹中; NDK提供 API 来从本机代码访问资产.

通常,在安装后首次运行该应用程序时,我们会将一些文件"从资源或资产解压缩到文件系统(例如/sdcard).当文件必须由外部应用程序和库使用(例如播放声音)时,或者当这些文件将要更改时,这种方法最有效.

最后,您可以在ndk-build期间将数据链接到您的 .so .这将解决以下问题:如何将 .dat 文件复制到应用程序文件夹中,但是读取该文件可能很棘手,并且无法修改.您无需创建一个巨大的库.您可以创建一个包含数据的模型库.如果我理解正确,则可以忽略文件结构,标题等.您只需在libs/armeabi(或其他)文件夹中的一个名为 lib 的文件 .so

I have an NDK library that I am creating that needs to contain and access a binary data file (.dat extension). I am having trouble getting the compiled library to see this file. To make things a little more difficult, I am doing this within a library package.

I think it would work if, during my Android.mk file, I copy this .dat file to my app's resources folder, and then access that from within the app, but I feel like there must be a better way.

Any suggestions?

解决方案

Instead of resources, put it in the assets folder; NDK provides API to access assets from native code.

Often, we unpack some "files" from the resources or assets to the file system (e.g. /sdcard) on the first run of the app after install. This approach works best when the files must be used by external apps and libs (e.g. to play sounds), or when these files will be changing.

Finally, you can link the data into your .so during ndk-build. This will resolve the question how the .dat file will be copied into the app folder, but reading it may be tricky, and modifying - impossible. You don't need to create a huge library. You can create a mock-up library that contains the data. If I understand correctly, you can ignore the file structure, headers, etc. You only need a file named lib something .so in your libs/armeabi (or other) folder.

这篇关于在NDK中使用资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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