简体   繁体   English

编译和构建apk后如何向Android apk添加资源文件?

[英]How to add resource file to Android apk after compilation and build of 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文件中添加.class java类文件,或者在没有源代码的情况下将.txt文本文件添加到APK中呢?

We compile and build an Android application as apk file. 我们将apk文件编译并构建一个Android应用程序。 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安装到设备上之前,至少将自定义txt文本文件添加到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. 目标是我们编写一个程序,该程序将使用原始apk并将文本文件添加到apk,因此客户不需要任何开发工具。

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. 我们的工具也必须无需安装即可运行。

The good news is that an APK file is just a zip file, so it's pretty easy to manipulate files that inside it. 好消息是,APK文件只是一个zip文件,因此操作其中的文件非常容易。

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... 坏消息是您可以添加.class文件,但Android无法使用它。这是因为Android使用其他格式(Dex),并且期望代码位于Dex文件中,而不是纯Java字节码...

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. 如果您想包含一个自定义.txt文件,则只需将其复制到APK内的assets/目录中即可。 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文件会使签名无效,这意味着您必须重新签名该APK才能通过应用商店进行安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM