问题描述
是否可以添加.class Java级文件,或者如果无法构建apk,没有源代码?
我们将Android应用程序编译为APK文件.现在,不需要开发工具的客户必须能够在将其安装在其设备上之前至少向APK添加自定义TXT文本文件.
目标是我们编写一个将使用原始APK并将文本文件添加到APK的程序,因此客户不需要任何开发工具.
客户没有获得源代码,而是不安装其他软件,这不是限制.我们的工具还必须在不安装的情况下运行.
推荐答案
好消息是APK文件只是一个zip文件,因此操纵其中的文件非常容易.
坏消息是您可以添加一个.class文件,但是Android将无法使用它...这是因为Android使用了其他格式(DEX),并期望代码在DEX文件中而不是普通的Java bytecode中...
如果要包含一个自定义.txt文件,那么您要做的就是将其复制到APK内部的assets/目录.可以将此文件夹中的文件提取到您的应用程序内部文件夹,因此直接从那里直接加载它应该很容易.但是,不要忘记修补APK文件将使其签名无效,这意味着您必须重新签名该APK才能通过App Store安装.
问题描述
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?
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.
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.
推荐答案
The good news is that an APK file is just a zip file, so it's pretty easy to manipulate files that inside it.
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...
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.