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!
POST 1- Guide to build MIUI using PatchROM Sources
POST 2- Modifying boot.img
POST 3- Guide to port MIUI from another device
Basically,There are two methods by which you can build MIUI ROM for your device.
- Build from source using PatchROM Method
- Port manually from another device which already has MIUI
Let's start with PatchROM Method:-
- Ubuntu 14.04 64-bit. (Installed as virtual machine like in VMware will also work)
- 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..
- Apktool. You can use Advanced Apktool by BDFreak. It's easier to use.
- 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-
- We'll need these folders further for MIUI framework patching.
- Switch to Ubuntu 14.04. We'll have to prepare ROM building environment.
- Next step is to setup android sdk. Follow THIS guide. (Look at 2nd answer graphical image explanation. Follow till step 5.)
- Now run the following commands as superuser from terminal-
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-
PHP Code:PHP Code:PHP Code:PHP Code:PHP Code:PHP Code:PHP Code:PHP Code:
- Now you'll have to configure git. Run following commands in terminal-
git config --global user.email ENTER_YOUR_EMAIL_ID_HERECode:
git config --global user.name ENTER_YOUR_REAL_NAME_HERE
- Now it's time to download the MIUI source code! Run the following command in terminal-
PHP Code:PHP Code:
- 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.
PHP Code:PHP Code:PHP Code:
- Now create a makefile for your device. If you want, you can make changes to this my makefile and use.
# # Makefile for taoshan # # The original zip file, MUST be specified by each product local-zip-file := stockrom.zip # The output zip file of MIUI rom, the default is porting_miui.zip if not specified local-out-zip-file := MIUI7_taoshan.zip # 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 porting.mk if using any global variable(see porting.mk) # (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 phoneapps.mk include $(PORT_BUILD)/porting.mk local-pre-zip-misc: @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.
- Next,copy your Base ROM zip in your device folder.
- Now move to patchrom folder.
PHP Code:PHP Code:
- Again move to your device folder and start MIUI framework patching.
PHP Code:PHP Code:
- 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.
- With this, the flashable zip file is built. Now follow the tutorial from next post 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.