Tutorial Definitive guide for APK editing on miuiandroid.com


MarkHUK

Site Founder
Staff member
Nov 6, 2010
5,251
1,000,000
hi all,

I was putting this guide together for one of our staff members as we are automating our builds soon and I needed to compile a proper list of the effected files and folders.

Here is a good summary of all the editing I do each week:


PRE-CHECK

1. Always make sure to run: apktool if framework-res.apk before running the decompile command
2. apk files and source files MUST NOT be in the same folder
3. When rebuilding the apks from the source file folder the source is created in: Source/build/apk/

From there we need to get:

resources.arsc and in some cases the classes.dex

APKS requiring the classes.dex are:

MiuiMusic/build/apk/classes.dex
Mms/build/apk/classes.dex

For other apks just the resources.arsc is needed and also in some cases the drawable-en-hdpi folder, layout-en, xml-en and one file from xml (will list these below)

AccountAndSyncSettings.apk
AccountAndSyncSettings/res/values-en/strings.xml

Copy: AccountAndSyncSettings/build/apk/resources.arsc to the original AccountAndSyncSettings.apk

Backup.apk
Backup/res/values-en/arrays.xml
Backup/res/values-en/strings.xml

Copy: Backup/build/apk/resources.arsc to the original Backup.apk

CloudService.apk
CloudService/res/values-en/strings.xml

Copy: CloudService/build/apk/resources.arsc to the original CloudService.apk

Contacts.apk
Contacts/res/values-en/arrays.xml
Contacts/res/values-en/strings.xml
Contacts/res/drawable-en-hdpi-finger/ (All images)

Copy: Contacts/build/apk/resources.arsc to the original Contacts.apk
Copy: Contacts/build/apk/res/drawable-en-hdpi-finger/ to the original Contacts.apk

ContactsProvider.apk
ContactsProvider/res/values-en/arrays.xml
ContactsProvider/res/values-en/strings.xml

Copy: ContactsProvider/build/apk/resources.arsc to the original ContactsProvider.apk

DownloadProviderUi.apk
DownloadProviderUi/res/values-en/strings.xml

Copy: DownloadProviderUi/build/apk/resources.arsc to the original DownloadProviderUi.apk

FileExplorer.apk
FileExplorer/res/values/strings.xml

Copy: FileExplorer/build/apk/resources.arsc to the original FileExplorer.apk

framework-res.apk
framework-res/drawable-en-hdpi/ (All files)
framework-res/values-en-rAU/plurals.xml
framework-res/values-en-rAU/strings.xml
framework-res/values-en-rCA/plurals.xml
framework-res/values-en-rCA/strings.xml
framework-res/values-en-rGB/plurals.xml
framework-res/values-en-rGB/strings.xml
framework-res/values-en-rIE/plurals.xml
framework-res/values-en-rIE/strings.xml
framework-res/values-en-rNZ/plurals.xml
framework-res/values-en-rNZ/strings.xml
framework-res/values-en-rUS/plurals.xml
framework-res/values-en-rUS/strings.xml

Copy: framework-res/build/apk/resources.arsc to the original framework-res.apk
Copy: framework-res/build/apk/res/drawable-en-hdpi/ to the original framework-res.apk


Gallery.apk
Gallery/res/values-en/arrays.xml
Gallery/res/values-en/strings.xml
Gallery/res/menu-en/media_context_menu.xml

Copy: Gallery/build/apk/resources.arsc to the original Gallery.apk
Copy: Gallery/build/apk/res/menu-en/ to the original Gallery.apk

Launcher2.apk
Launcher2/res/drawable-en-hdpi/ (All files)
Launcher2/res/values-en/strings.xml
Launcher2/res/xml-en/default_workspace.xml

Copy Launcher2/build/apk/resources.arsc to the original Launcher2.apk
Copy Launcher2/build/apk/res/xml-en/ to the original Launcher2.apk
Copy Launcher2/build/apk/res/drawable-en-hdpi/ to the original Launcher2.apk

MiuiCamera.apk
MiuiCamera/res/values-en/strings.xml

Copy MiuiCamera/build/apk/resources.arsc to the original MiuiCamera.apk


MiuiMusic.apk
MiuiMusic/res/drawable-en-hdpi/ (All files)
MiuiMusic/res/values-en/arrays.xml
MiuiMusic/res/values-en/plurals.xml
MiuiMusic/res/values-en/strings.xml
MiuiMusic/res/layout-en/media_player_navigation_header.xml

Copy MiuiMusic/build/apk/resources.arsc to the original MiuiMusic.apk
Copy MiuiMusic/build/apk/classes.dex to the original MiuiMusic.apk
Copy MiuiMusic/build/apk/res/drawable-en-hdpi/ to the original MiuiMusic.apk
Copy MiuiMusic/build/apk/res/layout-en/ to the original MiuiMusic.apk

Mms.apk
Mms/res/drawable-en-hdpi/ (All files)
Mms/res/raw-en/sms_frequently_used_phrase
Mms/res/values-en/arrays.xml
Mms/res/values-en/strings.xml
Mms/res/xml/mms_config.xml

Copy Mms/build/apk/resources.arsc to the original Mms.apk
Copy Mms/build/apk/classes.dex to the original Mms.apk
Copy Mms/build/apk/res/raw-en/ to the original Mms.apk
Copy Mms/build/apk/res/drawable-en-hdpi/ to the original Mms.apk
Copy Mms/build/apk/res/xml/mms_config.xml to the original Mms.apk

Monitor.apk
Monitor/res/values-en/arrays.xml
Monitor/res/values-en/strings.xml

Copy Monitor/build/apk/resources.arsc to the original Monitor.apk

Notes.apk
Notes/res/drawable-en-hdpi/ (All files)
Notes/res/raw-en/introduction
Notes/res/values-en/arrays.xml
Notes/res/values-en/strings.xml

Copy Notes/build/apk/resources.arsc to the original Notes.apk
Copy Notes/build/apk/res/raw-en/ to the original Notes.apk
Copy Notes/build/apk/res/drawable-en-hdpi/ to the original Notes.apk

Phone.apk
Phone/res/values-en/arrays.xml
Phone/res/values-en/strings.xml

Copy Phone/build/apk/resources.arsc to the original Phone.apk

Settings.apk
Settings/res/drawable-en-hdpi/ (All files)
Settings/res/values-en/arrays.xml
Settings/res/values-en/strings.xml
Settings/res/xml-en/about_device.xml

Copy Settings/build/apk/resources.arsc to the original Settings.apk
Copy Settings/build/apk/res/xml-en/ to the original Settings.apk
Copy Settings/build/apk/res/drawable-en-hdpi/ to the original Settings.apk

SettingsProvider.apk
SettingsProvider/res/values-en/bools.xml
SettingsProvider/res/values-en/strings.xml

Copy SettingsProvider/build/apk/resources.arsc to the original SettingsProvider.apk

SideKick.apk
SideKick/res/values-en/strings.xml

Copy SideKick/build/apk/resources.arsc to the original SideKick.apk

SoundRecorder.apk
SoundRecorder/res/values-en/strings.xml

Copy SoundRecorder/build/apk/resources.arsc to the original SoundRecorder.apk

Superuser.apk
Superuser/res/values-en/strings.xml

Copy Superuser/build/apk/resources.arsc to the original Superuser.apk

SystemUI.apk
SystemUI/res/values-en/bools.xml
SystemUI/res/values-en/strings.xml

Copy SystemUI/build/apk/resources.arsc to the original SystemUI.apk

TelephonyProvider.apk
TelephonyProvider/res/values-en/strings.xml

Copy TelephonyProvider/build/apk/resources.arsc to the original TelephonyProvider.apk

TelocationProvider.apk
TelocationProvider/res/values-en/strings.xml

Copy TelocationProvider/build/apk/resources.arsc to the original TelocationProvider.apk

ThemeManager.apk
ThemeManager/res/drawable-en-hdpi/ (All files)
ThemeManager/res/raw-en/description.xml
ThemeManager/res/values-en/strings.xml

Copy ThemeManager/build/apk/resources.arsc to the original ThemeManager.apk
Copy ThemeManager/build/apk/res/raw-en/ to the original ThemeManager.apk
Copy ThemeManager/build/apk/res/drawable-en-hdpi/ to the original ThemeManager.apk

Torch.apk
Torch/res/values-en/strings.xml

Copy Torch/build/apk/resources.arsc to the original Torch.apk
 
SMALI EDITS
====================

MiuiMusic.apk
-----------------------------------

MiuiMiusic/smali/com/miui/player/MusicUtils.smali


from: .method public static updateNavigationHeader(Landroid/app/Activity;I)V

to:

.end method

(Remove)

approx start line: 8105
approx end line: 8184


MiuiMusic/smali/com/miui/player/R$id.smali

remove: .field public static final online_navigation_title:I = 0x7f0c006e

MiuiMusic/smali/com/miui/player/ui/MusicBrowserActivity.smali

Remove:

.line 105
const v4, 0x7f0c006e

invoke-static {p0, v4}, Lcom/miui/player/MusicUtils;->updateNavigationHeader(Landroid/app/Activity;I)V


approx start line: 676
approx end line: 679

Mms.apk
-----------------------------------

Mms/smali/com/android/mms/ui/MmsTabActivity.smali

approx start line: 135

remove from:

.method private setupRecommendationTab()V

to:

.end method

approx end line: 178

Look for:

invoke-direct {p0}, Lcom/android/mms/ui/MmsTabActivity;->setupRecommendationTab()V

.line 47

and remove it. (approx start line after 1st edit = 274 ending line at 276)
 
If you are using linux you can do the following:

1. mkdir device_rom (Where device = nexusone for example)
2. Copy the following apks from system/app in your unzipped deodex

AccountAndSyncSettings.apk (Account manager for sync contacts, pictures e.g. Google (Gmail))
Backup.apk (MIUI Backup utility including Cloud backup and automatic backup)
Contacts.apk (MIUI Contacts app)
ContactsProvider.apk (Provider for Contacts, background app)
CloudService.apk (MIUI User account management apk)
DownloadProviderUi.apk (Used for Download management UI)
FileExplorer.apk (MIUI File manager)
Gallery.apk (MIUI Gallery app)
Launcher2.apk (MIUI Launcher)
MiuiCamera.apk (MIUI Camera)
MiuiMusic.apk (MIUI Music player)
Mms.apk (MIUI SMS / MMS app)
Monitor.apk (System application monitoring and firewall app)
Notes.apk (MIUI / Xiaomi notes app)
Phone.apk (MIUI Phone app)
Settings.apk (Common system settings)
SettingsProvider.apk (Background provider for settings app)
SideKick.apk (Search app in MIUI for global searching)
Superuser.apk (MIUI Customised superuser for application permissions management)
SoundRecorder.apk (MIUI Sound recording app)
SystemUI.apk (System user interface for status bar and toggle interactions etc)
TelephonyProvider.apk (Used for number lookup in framework etc)
TelocationProvider.apk (Used for GPS tracking)
ThemeManager.apk (mtz Theme manager from MIUI)
Torch.apk (Do not package with i9000 roms! no support for this apk) (CM Torch app customised by MIUI)

From system/framework you will need to get:

framework-res.apk (System framework)

Once you have all of these files in device_rom/ you can proceed to the next step.

Decompiling apks

On Linux and OSX you can issue the following command once you have ensured to run: apktool if framework-res.apk from within the device_rom folder:

Code:
for apk in *; do apktool d $apk; echo Decompiled $apk; done

(Note: Running apktool if framework-res.apk is essential for each and ever weekly build as it ensures the correct dependants of the system framework are available as part of the decompile and compile processes)

To recompile apks you simply need to switch the command to the following:

Code:
for apk in *; do apktool b $apk; echo Decompiled $apk; done

Summary:

apktool d = decompile command switch
apktool b = compile command switch

The above for commands are loops which run like any 'for' operator in programming so they make the task so much easier.

You can then see from running the apktool b command option that you have not got a 'build' and 'dist' folder within the unpacked apk folder e.g device_rom/Backup/build device_rom/Backup/dist

What you need to do is grab the compiled files from the Apkname folder (where apk name is = Backup for example) e.g. Backup/build/apk folder. This folder contains all the compiled files, drawables, xmls and classes.dex (Smali).

I'll add more to this later.

Cheers,

Mark
 
Awesome write-up.

I do my fair share of modding to MIUI on a weekly basis; this should prove to be a great help.

Thanks!