如何将 .apk 中的某些文件解压到 /data/data/安装 .apk 时的文件夹?

发布于 2024-09-27 01:51:42 字数 455 浏览 3 评论 0原文

我的 Android 应用程序需要另一个 NATIVE 应用程序可执行文件在 Android 应用程序之前运行,以便它们可以通过套接字进行通信。 Android 应用程序有一个 JNI 层来处理客户端通信。

现在我需要将本机可执行文件与 apk 文件捆绑在一起,这样当它安装在设备上时,它就会解压缩到手机内存或存储卡中。

我该怎么做? 我尝试将本机可执行文件保留在 res/asset 和 res/raw 文件夹中,但它们仍然没有在 /data/data/ 文件夹中解压缩。

我能找到的一种方法是使用 AssetManager,然后在 InputStream 和 OutputStream 的帮助下,我可以在第一次运行时将此文件写入设备,然后使用它。但没有必要手动将其写入手机内存,因为它可能会耗尽内存。 (如果存储卡不存在的情况。)

任何人都可以帮助我如何实现这一目标?如果有一个选项可以在安装时自动解压必要的文件,那就太好了。

My android application needs another NATIVE application executable to run before the android one, so that they can communicate through sockets. Android application has a JNI layer for handling the client-side communication.

Now i need to bundle up the native executable along with the apk file, so that when it is installed on a device it gets unzipped into either the phone memory or the memory card.

How do i do this?
I tried keeping the native executable in res/asset and in res/raw folders, but they still don't get unzipped in /data/data/ folder.

One way I could find is to use AssetManager and then with help of InputStream and OutputStream, i can write this file onto the device the first time it is run and then use it. But there is no point to write it manually on phone memory as it might eat up the memory. ( the case where if memory card is not present. )

Can anyone help me on how can i achieve this? It would be great if there is an option to unzip the necessary files automatically at the time of installation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

是你 2024-10-04 01:51:42

我该怎么做?

你不知道。您可以在第一次运行应用程序时自行解压它。

我能找到的一种方法是使用 AssetManager,然后在 InputStream 和 OutputStream 的帮助下,我可以在第一次运行时将此文件写入设备,然后使用它。

正确的。

但是没有必要手动将其写入手机内存,因为它可能会耗尽内存。

那么你为什么首先要让它自动解压呢?

如果有一个选项可以在安装时自动解压缩必要的文件,那就太好了。

不,抱歉,这是不可能的。

How do i do this?

You don't. You unpack it yourself on first run of your application.

One way I could find is to use AssetManager and then with help of InputStream and OutputStream, i can write this file onto the device the first time it is run and then use it.

Correct.

But there is no point to write it manually on phone memory as it might eat up the memory.

Then why did you want it automatically unpacked there in the first place?

It would be great if there is an option to unzip the necessary files automatically at the time of installation.

No, sorry, this is not possible.

日裸衫吸 2024-10-04 01:51:42

我们有同样的问题......我们正在探索的方向是进行两次单独的安装 - 第一个是应用程序,第二个是数据应用程序。当数据应用程序安装时,它将二进制文件复制到 SD 卡。当我们卸载数据应用程序时,它会释放内部存储空间。

我们还没有完全解决这个问题,很想听到其他意见,也许可以找到人来帮助我们编写几个框架示例应用程序。

有很多人都在这条船上(根据我的谷歌搜索),如果这种方法不起作用,我建议我们(或某人)建立一个通用文件传输 Web 服务器和通用文件传输 Android 服务,并将其提供给开发商以极低的成本。

We have the same issue ... the direction we are exploring is to have two separate installs - the first one is the app and the second one is the data-app. When the data-app installs it copies the binary files to the SD card. When we uninstall the data-app it frees up the internal storage.

We don't have this one completely licked yet, and would love to hear other input and maybe find someone to help us by writing a couple of skeletal sample applications for us.

There are so many people who are in this boat (based on my googling) that if this approach doesn't work I suggest we (or someone) set up a generic file delivery web server and generic file delivery Android service and make it available to developers for a very low cost.

爱*していゐ 2024-10-04 01:51:42

这不是 OBB 的典型用法,但为什么不使用呢?然后它将是一个独立于安装在预定位置的 apk 的文件。它不必被压缩。

This isn't a typical use of OBBs but why not use one? It would then be a file separate to your apk installed in a pre-determined location. It doesn't have to be compressed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文