问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/27633323/how-to-add-resource-file-to-android-apk-after-compilation-and-build-of-apk