How to Build or Port MIUI ROM to Any Device [COMPLETE GUIDE]


I decided to share this complete guide which will teach you how to build MIUI from scratch.

[featured ]
Hey guys! Here's a complete tutorial for building or porting MIUI to your device! I know there are already some guides for it but I felt none of them were noob-friendly and many were confusing and missing some important instructions. So I decided to share this complete guide which will teach you how to build MIUI from scratch. This is a basic guide in which I have taken building latest MIUI v7 as example. So let's start! 😇

STEP 1- Guide to build MIUI using PatchROM Sources
STEP 2- Modifying boot.img (Second Page)
STEP 3- Guide to port MIUI from another device (Third Page)

Basically,There are two methods by which you can build MIUI ROM for your device.

  1. Build from source using PatchROM Method
  2. Port manually from another device which already has MIUI

Let's start with PatchROM Method:-


  1. Ubuntu 14.04 64-bit. (Installed as virtual machine like in VMware will also work)
  2. Base ROM for your device.
    NOTE- Preferably take pure AOSP built for your device as base ROM rather than CyanogenMod. You'll get less rejects while patching MIUI framework. But CM works too! Your choice.. 
  3. Apktool. You can use Advanced Apktool by BDFreak. It's easier to use.
  4. Working brain and a lot of patience!! 
  • First of all, take framework-res.apk, framework.jar, framework2.jar, services.jar, android.policy.jar and telephony-common.jar from your base ROM zip.
  • Now using apktool, decompile all above files.
  • If you're using advanced apktool then go to 3-Out folder and rename the respective folders to-
[ sudo apt-get update ]
 Then after run this-

sudo apt-get install bison build-essential curl flex git git-core gnupg gperf libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 libxml2-utils lzop openjdk-7-jdk openjdk-7-jre pngcrush schedtool squashfs-tools xsltproc zip zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev unzip lib32readline-gplv2-dev lib32z1-dev make python-networkx zlib1g-dev:i386 phablet-tools ]
  • All the necessary packages are now installed. Now the next step is to configure repository.
  • In terminal,run following commands-
mkdir -~/bin ]
PATH=~/bin:$PATH ]
 [ cd ~/bin ]
curl > ~/bin/repo ]
 [ chmod a+~/bin/repo  ]
mkdir ~/patchrom ]
cd ~/patchrom ]
repo init -u git:// -b miui-7 -m android-4.4.4.xml  ]

 Now you'll have to configure git. Run following commands in terminal-

git config --global ENTER_YOUR_EMAIL_ID_HERE]
git config --global ENTER_YOUR_REAL_NAME_HERE]

 Now it's time to download the MIUI source code! Run the following command in terminal-

repo init -u git:// -b miui-7 -m android-4.4.4.xml  ]
 [ repo sync ]
  • Now grab a cup of coffee while the MIUI source gets downloaded. Required time depends on speed of your internet connection. The MIUI source is of size about 600-700 MB (With .repo total is 1.5 GB). 
  • After the source is downloaded,create a new directory in /home. Name it whatever you want. (Preferably codename of your device) In my case, it's taoshan.
cd /home/gagan/ ]
 [ mkdir taoshan  ]
 [ cd taoshan  ]
  • Now create a makefile for your device. If you want, you can make changes to this my makefile and use.
gedit makefile ]
 You can copy the following content in makefile (Don't forget to make changes in it according to your device) and save it.

# Makefile for taoshan

# The original zip file, MUST be specified by each product
local-zip-file     :=

# The output zip file of MIUI rom, the default is if not specified
local-out-zip-file :=

# All apps from original ZIP, but has smali files chanded
local-modified-apps :=

local-modified-priv-apps := 

local-modified-jars := 

# All apks from MIUI
local-miui-removed-apps := 

local-miui-removed-priv-apps := 

local-miui-modified-apps := 

# All apps need to be removed from original ZIP file
local-remove-apps   := Gallery2 Exchange2

# Config density for co-developers to use the aaps with HDPI or XHDPI resource,
# Default configrations are HDPI for ics branch and XHDPI for jellybean branch
local-density := XHDPI

PORT_PRODUCT := taoshan

# To include the local targets before and after zip the final ZIP file, 
# and the local-targets should:
# (1) be defined after including if using any global variable(see
# (2) the name should be leaded with local- to prevent any conflict with global targets
#local-pre-zip := local-pre-zip-misc
#local-after-zip:= local-put-to-phone

# The local targets after the zip file is generated, could include 'zip2sd' to 
# deliver the zip file to phone, or to customize other actions


include $(PORT_BUILD)/

 @echo Update boot.img
 cp other/boot.img $(ZIP_DIR)/boot.img
 @echo Update build.prop
 cp other/build.prop $(ZIP_DIR)/system/build.prop

 @echo Delete some unneeded files
 rm -rf $(ZIP_DIR)/system/etc/.has_su_daemon

 rm -rf $(ZIP_DIR)/system/priv-app/Dialer.apk

 rm -rf $(ZIP_DIR)/system/priv-app/Keyguard.apk

 rm -rf $(ZIP_DIR)/system/priv-app/SystemUI.apk

 rm -rf $(ZIP_DIR)/system/priv-app/VoiceDialer.apk

 rm -rf $(ZIP_DIR)/system/priv-app/Launcher3.apk

 rm -rf $(ZIP_DIR)/system/priv-app/ParanoidOTA.apk

 rm -rf $(ZIP_DIR)/system/priv-app/ThemeChooser.apk

 rm -rf $(ZIP_DIR)/system/priv-app/ThemesProvider.apk

  • 'local-zip-file' = Name of your original Base ROM zip
  • 'local-out-zip-file' = Name for your finished MIUI rom
  • 'local-modified-apps' = Apps that will be modified to fit in with the framework. They need to be modified because they contact with the system
  • 'local-remove-apps' = Apps that will be removed from the original ROM
  • 'local-pre-zip' = Refers to code-block that should be executed before the zip is done.
  • 'local-after-zip' = Refers to code-block executed after the zip is completed
  • 'local-zip-misc' = The code-block just described at 'local-pre-zip'. It adds some Google Apps and a build.prop
  • 'local-test' = Another code-block
  • Now, manually copy the previously decompiled framework folders to your device folder.
framework-resframework.jar.outframework2.jar.outservices.jar.outandroid.policy.jar.out telephony-common.jar.out  ]

  • Next,copy your Base ROM zip in your device folder.
  • Now move to patchrom folder.
cd ~/patchrom ]
source build/  ]

  • Again move to your device folder and start MIUI framework patching.
cd /home/stryder/taoshan  ]
make firstpatch  ]

  • Now a new folder folder temp will be created. In that you'll find the reject folder in which there will be rejects which you have to fix manually. Follow THIS excellent guide by @JavierAlonso to fix rejects. Also see THIS guide.
  • After fixing all the rejects, type following command to create a flashable zip of your MIUI ROM. 
make fullota  ]
 or you can also use 
make zipfile ]

  • With this, the flashable zip file is built. Now follow the tutorial from next page to modify your boot.img and include this new boot.img in your flashable MIUI ROM zip. Then flash the zip from recovery and enjoy your source built MIUI ROM!
  • Sometimes, your device might get stuck on bootanimation so in this case, take LOGCAT and look for the error and solve it. You can use some tools like Advanced Logcat Viewer to read the log. 
    👿 Modifying boot.img

    Now, let's modify the boot.img from base ROM zip to it make compatible with our MIUI ROM.
    • First of all, download any boot image kitchen or editor. I used Android Image Kitchen for Windows.
    • Assuming you're using the same kitchen, Extract the files from Android Image Kitchen in a separate folder. Copy your base ROM boot.img in that folder.
    • Now drag and drop the boot.img on unpackimg. The kernel files will be extracted in ramdisk and split_img folder.
    • We have to modify the ramdisk so move to that. In sbin folder, you'll see the extracted files.
    • Now there are two chances- First, Your ramdisk is already extracted with various folders and files. In that case ignore the next steps and directly modify in respective files using Notepad++.
    • While in second case, you'll get the ramdisk as ramdisk.cpio file. If you get this the you'll have to move to Ubuntu again for extracting it.
    • Now in Ubuntu, copy your ramdisk.cpio in a seperate folder (suppose in stryder folder) in your home directory.
    • Now, open terminal and run the following command-[No need as superuser]
    cd gagan ]
    [  cpio --F ramdisk.cpio  ]
    • Some output will be shown in terminal as 2320 blocks or something like that!
    • Now in your folder, you'll see the extracted ramdisk files.
    • Now comes the actual modification.
    • First of all, download attached zip and extract the files in appropriate folders. (If the folder is not present, add that folder).
    • Open default.prop and edit the lines like this-
    [ # # ADDITIONAL_DEFAULT_PROPERTIES,adb persist.service.adb.enable=persist.service.debuggable=1  ]

    Save the changes and open (In case of CyanogenMod) or case of AOSPA). Add # before the import line like this-

    # Superuser #import /init.superuser.rc  ]
    • Save this file and now open init.rc.
    • At the end of init.rc file, add these lines-
    #service for shelld service shelld /system/xbin/shelld
        class main
    #service for su service su_daemon /system/xbin/su --daemon
        class main

    service lbesec 
    service lbesec /system/xbin/lbesec
        class main
        oneshot  ]
    • Save this file and then open seapp_contexts.
    • In that file, add at the end-
    user=theme seinfo=platform domain=platform_app type=platform_app_data_file user=backup seinfo=platform domain=platform_app type=platform_app_data_file user=updater seinfo=platform domain=platform_app type=platform_app_data_file user=theme_man domain=system_app type=system_data_file  ]

    • Also modify these lines (if present) to look like this-
    user=_app domain=untrusted_app type=app_data_file user=_app seinfo=platform domain=platform_app type=app_data_file user=_app seinfo=shared domain=shared_app type=app_data_file user=_app seinfo=media domain=media_app type=app_data_file user=_app seinfo=release domain=release_app type=app_data_file  ]
    • Save this file and if present, open init.qcom.rc.
    • And before this line (at the end)-
    on property:sys.boot_completed=1  ]
    • Add these lines-
    service shelld /system/xbin/shelld     class main  ]
    • Save the file. Now it's time to repack your ramdisk.
    • First, move your original ramdisk.cpio from the extracted folder to /home. 
    • That is, if your extracted ramdisk is in 
    /home/gagan/  ]
    Move original ramdisk.cpio file to-
    /home/  ]
    • After that, run this command in terminal-
    cpio ---../ramdisk.cpio cpio --H newc -../ramdisk_new.cpio  ]
    • Now a new file ramdisk_new.cpio will be created. Take a look if it's of the same size as the original one just a few bytes difference.
    • Also open this ramdisk_new.cpio and make sure you have the newly added files in it. (Ex. otad in bin folder etc.)
    • Now move this ramdisk_new.cpio to previously extracted Android Image kitchen ramdisk/sbin/ directory.
    • Delete the original ramdisk.cpio from it and rename the ramdisk_new.cpio to ramdisk.cpio.
    • Now come back and directly run repackimg. The modified image_new will be generated. Rename it to boot and include this modified boot.img in your MIUI ROM zip. Now you can proceed to flash your MIUI ROM!

    👿 Port MIUI from another device

    • 7-zip, Winrar or similar software
    • Notepad++

    First of all, make 2 folders- 1. BASE ROM 2. PORT ROM
    • What is Base ROM: It is the ROM which is built for your device. (AOSP or CM etc.)
    • What is Port ROM: MIUI ROM of other device which you want to port to your device.
    • NOTE- It's better if the port device and your device has same CPU architecture and specifications. If you couldn't find same specification device then try the device having almost similar specification of your device.
    • Now extract the Base ROM zip in BASE ROM folder and Port ROM zip in PORT ROM folder.
    • Next, Delete addon.d (If present), app, framework, fonts, media and priv-app folder in System folder of BASE ROM.
    • Now copy addon.d (If present), app, framework, fonts, media and priv-appfolder from system folder of PORT ROM to system folder of BASE ROM.
    • Now open etc folder in both ROMs folder. Go to init.d folder of PORT and copy and replace any extra files except 00banner to init.d of BASE ROM.
    • Now open permissions folder in etc of both ROMs and copy and replace all the permissions files from PORT ROM to your BASE ROM folder excepthandheld_core_hardware.xml and platform.xml. (In case of CM based BASE ROM, also don't replace org.cyanogenmod.hardware.xml).
    • Also copy any extra folder available in PORT ROM etc/ to BASE ROM etc/ e.g. miui_feature folder.
    • Now open your system_fonts.xml in etc folder of BASE ROM and copy this before end of file. 
    <family        <nameset            <name>miui</name        </nameset        <fileset            <file>Miui-Regular.ttf</file            <file>Miui-Bold.ttf</file        </fileset    </family
        <family        <nameset            <name>miuiex</name        </nameset        <fileset            <file>MiuiEx-Regular.ttf</file            <file>MiuiEx-Bold.ttf</file        </fileset    </family
        <family        <nameset            <name>miuiex-light</name        </nameset        <fileset            <file>MiuiEx-Light.ttf</file        </fileset    </family>  ]

    • Now copy all the extra files from PORT ROM binlib and xbin folder to BASE ROM respective folders. Remember, DO NOT REPLACE anything. Just copy and paste and skip the files with same name.
    • Now, open build.prop of BASE ROM. You can change these value to anything you like- ro.product.locale.region=US  ]

    • Now copy paste these values at the end of your BASE ROM build.prop. You can edit the fields but keep the structure same.You can look at PORT ROM build.prop for reference. 4.4.2 yourname C2104XXUCNG1 release-keys ro.product.model=Xperia L ro.product.device=taoshan #MIUI_Features ro.miui.has_real_blur=ro.miui.has_handy_mode_sf=ro.config.sms_received_sound=FadeIn.ogg ro.config.sms_delivered_sound=MessageComplete.ogg ro.product.manufacturer=Xiaomi ro.config.elder-ringtone=Angel.mp3 persist.sys.mitalk.enable=true persist.sys.strictmode.disable=true ro.product.mod_device=yourdevice  ]

    • Change these fields in BASE ROM build.prop according to PORT ROM build.prop-
    ro.config.notification_soundro.config.alarm_alertro.config.ringtone=  ]

    • If your device has On-screen buttons, then add this value at the end of BASE ROM build.prop-
    qemu.hw.mainkeys=0  ]

    • Now we're done with build.prop.
    • Next, open META-INF/com/google/android/updater-script from BASE ROM using Notepad++ and change, compare and replace all the symlink and set_metadata lines in updater-script according to PORT ROM updater-script.If some extra lines are there in BASE ROM updater-script, keep it as it is.
      NOTE:-I have attached one sample updater-script with this post. Look below. You can refer from that if you feel any difficulty. 😁
    • Add these before unmount("/system"); at the end of updater-script-
    set_perm(0100006750"/system/xbin/shelld"); run_program("/sbin/busybox""mount""/data"); package_extract_dir("data""/data"); package_extract_file("META-INF/com/miui/relink""/tmp/relink"); set_perm(000555"/tmp/relink"); run_program("/tmp/relink"); delete("/tmp/relink"); set_perm_recursive(1000100007550644"/data/miui"); set_metadata("/system/bin/debuggerd""uid"0"gid"2000"mode"0755"capabilities"0x0"selabel""u:object_r:system_file:s0"); set_metadata("/system/bin/debuggerd_vendor""uid"0"gid"2000"mode"0755"capabilities"0x0"selabel""u:object_r:debuggerd_exec:s0"); set_metadata("/system/xbin/su""uid"0"gid"2000"mode"06755"capabilities"0x0"selabel""u:object_r:su_exec:s0"); delete_recursive("/data/miui/preinstall_apps"); delete_recursive("/data/miui/cust/preinstall_apps"); ui_print("Installation finished...Enjoy!"); unmount("/data");  ]

    • Also copy META-INF/com/miui and data folder to BASE ROM from PORT ROM.
    • Now modify your BASE ROM boot.img using the tutorial from previous post and put that new boot.img in BASE ROM folder.
    • Finally, select META-INF, system, boot.img, file_contexts(If present) and data folder in BASE ROM.
    • Right click and select Add to Archive. Select Zip. Type the name of zip. (Don't delete ".zip" at the end!) Click OK.
    • Now you're ready to flash this zip from recovery.
    • Sometimes, your device might get stuck on bootanimation so in this case, take LOGCAT and look for the error and solve it. You can use some tools like Advanced Logcat Viewer to read the log. Look HERE for fixing bootloop.
    I hope you guys understood how to build and port MIUI. I wish you good luck! If you get stuck anywhere, If you become successful building MIUI, feel free to post here. Also if you succeed, I'll appreciate if you give me credits and add link to this thread.



    AI,4,AMD,1,Android,8,Apple,2,Automobile,1,Bitcoin,2,Blogger,7,Bloging,4,Breakthrough,1,Camera,1,Computer,9,CPU,1,Cryptocurrency,1,CuttingEgde,2,CyberSecurity,5,Download,1,Editing,1,Gaming,44,Giveaway,4,Guide,1,Hacking,3,Hacking News,4,Hardware,18,How To,12,i,4,iOS & Mac,9,iPhone,8,Laptop,1,Leak,6,Malwares,1,Marketing,2,Mobile,46,News,5,Notebook,2,Programming,14,Robotics,2,Rumor,5,Science,1,Security,14,SEO,2,Social Media,5,Software,14,Tablet,1,Technology,42,Weapon,1,Web,11,Website,1,Windows,1,
    TechFonder: How to Build or Port MIUI ROM to Any Device [COMPLETE GUIDE]
    How to Build or Port MIUI ROM to Any Device [COMPLETE GUIDE]
    I decided to share this complete guide which will teach you how to build MIUI from scratch.
    Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy