I would like to include additional (per-user) data in each downloaded APK file. In other words, I have an existing APK file on server and would like to:
/res/user_info.xml
in existing APK with dynamically generated XML fileMore info: I know it can be done using aapt, apktool, jarsigner,... The problem is that the documentation is quite poor and I was unable to find (or develop) a working technique to re-pack the APK file. For instance aapt
always puts the XML file in root path (/
) no matter what I do. I am also unsure which resources need to be updated so that the APK file is valid again. Also, the existing XML files in /res/
are compiled - do I need to do that with my XML file too? If yes, how do I do that? If no, should I put my XML file in /res/raw/
?
Question: how do I replace an XML file in APK and repackage it? What steps are needed and which tools do I use?
In Android Studio, you will see all the projects's XML files and can edit them with all the tools Android Studio provides, including the visual designers. As you make changes and save them in Android Studio, they will automatically reflect back into your Elements project inside Visual Studio.
To edit the files inside, you'll need to decompile (and then recompile) the package using APKtool on a computer. Editing APK files requires knowledge of Java, as well as the file systems on both Windows and Android. This should only be done by advanced users.
String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc.
In this writing you can find the basic steps of unpacking and packing an apk file.
Basicly;
= Use apktool.bat d -s sample.apk .\sample\
to decode only resources of the apk.(In your situation there is no need to decode source part)
= Add/edit/replace your required resources.
= Use apktool.bat b .\sample\ .\sample_edited.apk
to build changed apk.
= Generate a RSA 2048 key to sign apk if you dont already have one : keytool -genkey -v -keystore my.keystore -alias myandroidalias -keyalg RSA -keysize 2048 -validity 20000
= Sign apk with generated key jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore my.keystore .\sample_edited.apk -signedjar .\sample_signed.apk myandroidalias
= And align signed apk with 4-byte boundary zipalign.exe -v 4 .\sample_signed.apk .\sample_aligned.apk
(zipalign comes with the android-sdk)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With