Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I replace XML file in APK?

Tags:

android

apk

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:

  • replace file /res/user_info.xml in existing APK with dynamically generated XML file
  • update and re-sign the whole package before user downloads it

More 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?

like image 345
johndodo Avatar asked Aug 30 '12 09:08

johndodo


People also ask

Can I edit XML files Android?

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.

What is the best way to modify or edit APK files?

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.

Where is strings XML in APK?

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.


1 Answers

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)

like image 63
Akdeniz Avatar answered Oct 03 '22 03:10

Akdeniz