在 Android 原生环境中从我自己的 APK 中读取资源文件 [英] Reading Resource Files from my own APK in Android Native Environment

查看:14
本文介绍了在 Android 原生环境中从我自己的 APK 中读取资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在移植到 Android.我现有的项目有大量的资源文件,我将它们移植到我的 Android 项目中.我将它们全部放在/res/raw/中,我想使用 fopen() 等函数访问我的本机库中的这些资源.这可以做到吗,还是我也必须通过JNI?为了便于移植以及可能的速度和内存原因,我真的不希望这样做.

I'm porting to Android. My existing project has a ton of resource files that I'm porting into my Android project. I have them all in /res/raw/, and I would like to access those resources in my native library with functions such as fopen() and such. Can this be done, or do I have to go through JNI for this as well? I would really prefer not to, for ease of porting and possible speed and memory reasons.

推荐答案

如果你 防止您的资产被压缩,因为它们被添加到您的 APK 中,然后您可以 使用 openRawResourceFd() 获取文件描述符、偏移量和大小 并将它们传递给您的本机代码,您只需在其中执行 fopen 和 fseek.另一方面,如果您让构建系统压缩您想要访问的文件,您将需要使用类似 libzip 从 APK 中读取它们.

If you prevent your assets from being compressed as they are added into your APK then you can use openRawResourceFd() to get a file descriptor, offset, and size and pass them to your native code where you just do an fopen and fseek. On the other hand, if you let the build system compress the files you want to access, you will need to use something like libzip to read them from the APK.

这篇关于在 Android 原生环境中从我自己的 APK 中读取资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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