如何在编译构建apk后将资源文件添加到Android apk? [英] How to add resource file to Android apk after compilation and build of apk?

查看:35
本文介绍了如何在编译构建apk后将资源文件添加到Android apk?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以添加一个 .class java-class 文件,或者如果在 APK 已经构建并且没有源代码的情况下将 .txt 文本文件添加到它是不可能的?

Is it possible to add a .class java-class file or if that's not possible a .txt text-file to an APK after it has been built and without source code?

我们编译并构建一个 Android 应用程序作为 apk 文件.现在,无需开发工具的客户必须能够在将 APK 安装到他的设备之前至少向 APK 添加一个自定义 txt 文本文件.

We compile and build an Android application as apk file. And now the customer without needing the development tools has to be able to add at least a custom txt text-file to the APK before installing it on his devices.

我们的目标是我们编写一个程序,将使用原始apk并将文本文件添加到apk中,因此客户不需要任何开发工具.

The goal is that we write a program that will use the original apk and will add the text file to the apk, so the customer does not need any development tools.

客户无法获得源代码,但不得安装其他软件,这不是限制.我们的工具也必须在没有安装的情况下运行.

It is not a restriction that the customer does not get the source code but that no additional software shall be installed. Our tool also has to run without installation.

推荐答案

好消息是 APK 文件只是一个 zip 文件,因此很容易操作其中的文件.

The good news is that an APK file is just a zip file, so it's pretty easy to manipulate files that inside it.

坏消息是你可以添加一个 .class 文件,但 Android 将无法使用它......这是因为 Android 使用不同的格式 (Dex) 并期望代码在 Dex 文件中而不是普通的 Java 字节码...

The bad news is that you can add a .class file but Android will not be able to use it... that's because Android uses a different format (Dex) and expects code to be in Dex files instead of plain Java bytecode...

如果您想包含自定义 .txt 文件,那么您只需将其复制到 APK 内的 assets/ 目录中.此文件夹中的文件可以提取到您的应用程序内部文件夹,因此直接从那里加载它应该很容易.但不要忘记修改 APK 文件会使它的签名失效,这意味着您必须重新签署该 APK 才能通过应用商店安装它.

If you wanted to include a custom .txt file then all you'd have to do is copy it to the assets/ directory inside of the APK. Files in this folder are can be extracted to your applications internal folders, so it should be pretty easy to load it directly from there. But don't forget that tinkering with an APK file will invalidate its signature, meaning that you'll have to re-sign that APK in order to install it via an app store.

这篇关于如何在编译构建apk后将资源文件添加到Android apk?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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