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

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

问题描述

是否可以将.cl​​ass Java类文件添加到APK中,或者在没有源代码的情况下将.txt文本文件添加到APK中?

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?

我们以apk文件的形式编译并构建了一个Android应用程序.现在,无需开发工具的客户就必须能够在APK上至少将自定义txt文本文件添加到APK上.

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天全站免登陆