[Android Software Development] Lens_flare:
I know there is a Proxuser's guide - "How to Port MIUI v4 for your device" and GREAT thread intended to eliminate porting quirks.

My goal is to collect all the experience we got in that thread, which could be helpful for new users porting newest releases of miui.

FAQ assumes questionaire, but my format will be more look like a guide but as collection, it could be treated as FAQ.

Structure will be Stage-divided to ease of use.

Stage 1. Initial port

Let's start with first moment - bases choice.

Under base I will mean rom which could be used to port miui and also miui release you choose.

Let's assume - just "Base" will mean rom for your device with ICS/JellyBean, such as Cyanogen Mod or AOKP or AOSP and their variations(I don't know if it is possible to use stock rom for porting and wouldn't recommend it), when "MIUI base" means any miui rom you prefer (my preference and advice - MIUIandroid crespo [nexus S] or MIUIandroid maguro (Galaxy Nexus) release). You could use any miui base but results will be unpredictable and may very vary from guide stands, for those cases I prepared common debugging stage, which will help to eliminate bugs I haven't listed.

MIUI for nexus S and Galaxy Nexus are now upgraded to Jelly Bean. That actually means - you couldn't use their miui bases to port ICS roms(which still under support).

For those who stuck at ICS the situation is as follows:

If version number is not crucial, you might just stick at MIUI 2.8.10 http://weedy.ca/miuiandroid/ and use old kind Nexus S/Galaxy Nexus roms. In guide I will describe steps right for you with mark "ICS-only".

If for you version number is crucial - stop reading this guide and just use PatchROM (though rom will be based on Stock rom).

There is third variant, but it needs a device with nearly same specs:

you might just replace some files in miui-supported device rom with files from your stock rom. For now that case is only tested on xperia 2011 products (play,live with walkman,ray, mini, pro, mini pro etc) - arc s [lt18i] miui base and xperia 2012 (u,p, sola etc) - S miui base.

When base choosen, start to port:

Copy unpacked base rom (so set of folders) to any folder you prefer (let's name it "MIUI"), it usually contains:

system - folder on which we will work more often

data - may contain something necessary such as first boot scripts, config files etc.

META-INF - contains certificates and signature for signcheck, updater-script(we also will work on it) update-binary (updater-script command processor)

boot.img, kernel and ramdisk packed together, touch only if kernel should be changed to something more recent or if your preference is not similar with base rom maker's, but keep in mind that you have to place modules that provided with kernel to lib/modules [or in place where .ko files are]

Starting with system:

delete:

app

framework

media

fonts

then open miui archive and extract those folders to system. Don't close archive.

Open lib folder in system to add from the same archive:

content-types.properties [for themes]

liblbesec.so [for LBE Guard - MIUI superuser]

liblocSDK_2.2.so [for baidu location service, prevents network location provider FC]

JellyBean-only:

libjni_resource_drm.so [themes DRM, actually involves download online themes screen]

Open etc folder in system to add from the same archive:

yellowpage.db [Phone calls ability]

ICS-only

telocation.td (as for nexus S and telocation.db in others) [location provider dependency]

JellyBean-only:

telocation.idf (possible new telocation.db)

go to permissions folder in etc to add:

com.nxp.mifare.xml [NFC]

miui-framework.xml [activates miui framework, near all apps won't work without that]

com.google.android.media.effects.xml [gallery]

com.google.widevine.software.drm.xml [something also related to google may affect play market]

com.google.android.maps.xml [gmaps]

Open xbin folder in system to add from the same archive:

su [replace, don't even use base one!]

invoke-as [binary with near busybox and toolbox functionality, need everywhere in system, mostly in themes and SU]

that's all about additional files. Devices which don't have NFC(Near Field Communication chip) also shouldn't have Nfc.apk in app folder!

Let's modify build.prop then, to add:

ro.build.id=MIUI
ro.build.display.id=MIUI
ro.build.version.incremental=2.x.x

ro.config.ringtone=MI.ogg
ro.config.notification_sound=FadeIn.ogg
ro.config.alarm_alert=GoodMorning.ogg
ro.config.sms_received_sound=FadeIn.ogg
ro.config.sms_delivered_sound=MessageComplete.ogg

ro.build.version.incremental points to MIUI you port, so specify it.

At your base you will most likely see these lines

ro.config.ringtone=
ro.config.notification_sound=
ro.config.alarm_alert=
ro.config.sms_received_sound=
ro.config.sms_delivered_sound=

are filled with ringtones that only base have, soo just change them as MIUI do have different ringtone set.

Initial port done, in system part, let's talk about Updater-script:

any release of miui you port should have that line:

set_perm(0, 0, 06755, "/system/xbin/invoke-as");

for example you have that bunch of code [which is mostly common for CM9 release]:

set_perm_recursive(0, 0, 0755, 0644, "/system");
set_perm_recursive(0, 2000, 0755, 0755, "/system/bin");
set_perm(0, 3003, 06755, "/system/bin/ip");
set_perm(0, 3003, 02750, "/system/bin/netcfg");
set_perm(0, 3004, 02755, "/system/bin/ping");
set_perm(0, 2000, 06750, "/system/bin/run-as");
set_perm_recursive(1002, 1002, 0755, 0440, "/system/etc/bluetooth");
set_perm(0, 0, 0755, "/system/etc/bluetooth");
set_perm(1000, 1000, 0640, "/system/etc/bluetooth/auto_pairing.conf");
set_perm(3002, 3002, 0444, "/system/etc/bluetooth/blacklist.conf");
set_perm(1002, 1002, 0440, "/system/etc/dbus.conf");
set_perm(1014, 2000, 0550, "/system/etc/dhcpcd/dhcpcd-run-hooks");
set_perm(0, 2000, 0550, "/system/etc/init.goldfish.sh");
set_perm_recursive(0, 0, 0755, 0555, "/system/etc/ppp");
set_perm_recursive(0, 2000, 0755, 0644, "/system/vendor");
set_perm_recursive(0, 2000, 0755, 0755, "/system/xbin");
set_perm(0, 0, 06755, "/system/xbin/librank");
set_perm(0, 0, 06755, "/system/xbin/procmem");
set_perm(0, 0, 06755, "/system/xbin/procrank");
set_perm(0, 0, 06755, "/system/xbin/su");
set_perm(0, 0, 06755, "/system/xbin/tcpdump");
set_perm_recursive(0, 0, 0755, 0644, "/system/vendor/firmware");
set_perm(0, 2000, 0755, "/system/vendor/firmware");
set_perm_recursive(0, 0, 0755, 0555, "/system/etc/init.d");

So line I pointed should be somewhere there, for example:

set_perm(0, 0, 06755, "/system/xbin/librank");
set_perm(0, 0, 06755, "/system/xbin/procmem");
set_perm(0, 0, 06755, "/system/xbin/procrank");
set_perm(0, 0, 06755, "/system/xbin/su");
[B][SIZE="4"]set_perm(0, 0, 06755, "/system/xbin/invoke-as");[/SIZE][/B]
set_perm(0, 0, 06755, "/system/xbin/tcpdump");

IF you have problems with SU, that line may help:

symlink("/system/xbin/su", "/system/bin/su");

paste it somewhere after

symlink("busybox"[B][COLOR="YellowGreen"][later big code bunch like "/system/xbin/[" etc][/COLOR][/B]

but before

unmount("/system");

Your own MIUI is now ready to be flashed, but only, if your device is SOOO near on hardware part with MIUI base :D

For those who didn't met that rule I prepared next parts - framework mods and common debugging and troubleshooting. See next 2 posts.