[GUIDE][LINUX] MIUI patchrom for jellybean roms

jackq

Senior Member
Mar 1, 2012
785
709
0
B-B
I searched and reading a lot but can't find properly guide how to use miui patchrom for jellybean roms. So i decided share what i've found and put all in one guide.

1. First of all you need linux on your machine. I use kubuntu, installed from windows (wubi) ->http://www.kubuntu.org/getkubuntu/download

2. Now you need SDK tools for linux http://developer.android.com/sdk/index.html
-download and unzip it to for egz home/your_username/android-sdk-linux
-set PATH for tools and platform-tools folders
Code:
export PATH=/home/your_username/android-sdk-linux/platform-tools:/home/your_username/android-sdk-linux/tools:$PATH
On x64 systems you are required to install some 32-bit libraries so in a terminal write:
Code:
sudo apt-get install ia32-libs
3. Download ROM which you want to patch with miui patchrom, must be deodexed and rooted. For us it must be jellybean ROM for egz 4.1.2. I suggest to use CM or AOSP based roms because stock sammy roms have a lot of differences and it's not so easy to port them. After downloading your ROM base rename it to something short and easy i use stock.zip.
In home create folder i use patchrom folder in this folder create for egz stock folder and put downloaded rom to it.

4. Download from MiCode github all necessary files https://github.com/MiCode we need:
https://github.com/MiCode/patchrom_tools/archive/jellybean.zip tools
https://github.com/MiCode/patchrom_miui/archive/jellybean.zip miui
https://github.com/MiCode/patchrom_i9100/archive/jellybean.zip i9100
https://github.com/MiCode/patchrom_build/archive/jellybean.zip build
https://github.com/MiCode/patchrom_android/archive/jellybean.zip android

all zips for jellybean, why downloading zips? because for me repo don't download all files, that way is much easiest.

Unzip all files to your stock folder which you create in step 3. Rename all folders by this way patchrom_tools_jellybean becomes tools, patchrom_miui_jellybean becomes miui ...

5. In i9100 folder you can find makefile its first of configuring files which you need to copy to stock folder and edit it.
This is my makefile, you should edit using this explanations:

'local-zip-file' = Name of your original 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-miui-apps' = MIUI Apps that will be integrated into the zip
'local-remove-apps' = Apps that will be removed from the original ROM
'local-pre-zip' = Refers to codeblock that should be executed before the zip is done.
'local-after-zip' = Refers to codeblock executed after the zip is completed
'local-zip-misc' = The codeblock just described at 'local-pre-zip'. It adds some Google Apps and a buid.prop
'local-test' = Another codeblock

Code:
#
# Makefile for i9100
#
PORT_BUILD=/home/jack/patchrom/build

PORT_ROOT=/home/jack/patchrom

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

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

# the location for local-ota to save target-file
local-previous-target-dir := ~/workspace/ota_base/i9100_4.1

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

local-modified-jars :=

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

local-miui-modified-apps := MiuiHome Settings Phone Mms ThemeManager MiuiSystemUI

# 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 := HDPI

include phoneapps.mk

# 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 $(PORT_BUILD)/porting.mk

# To define any local-target
updater := $(ZIP_DIR)/META-INF/com/google/android/updater-script
pre_install_data_packages := $(TMP_DIR)/pre_install_apk_pkgname.txt
local-pre-zip-misc:
	cp other/spn-conf.xml $(ZIP_DIR)/system/etc/spn-conf.xml
	cp other/build.prop $(ZIP_DIR)/system/build.prop
	#cp stockrom/system/app/FFFFFFFF000000000000000000000001.drbin $(ZIP_DIR)/system/app
	#cp -r stockrom/system/app/mcRegistry $(ZIP_DIR)/system/app
	rm -rf $(ZIP_DIR)/system/csc
	rm -rf $(pre_install_data_packages)
	for apk in $(ZIP_DIR)/data/media/preinstall_apps/*.apk; do\
		$(AAPT) d --values resources $$apk | grep 'id=127 packageCount' | sed -e "s/^.*name=//" >> $(pre_install_data_packages);\
	done
	more $(pre_install_data_packages) | wc -l > $(ZIP_DIR)/system/etc/enforcecopyinglibpackages.txt
	more $(pre_install_data_packages) >> $(ZIP_DIR)/system/etc/enforcecopyinglibpackages.txt

out/framework2.jar : out/framework.jar

%.phone : out/%.jar
      [user=279333]@ECHO[/user] push -- to --- phone
	adb remount
	adb push $< /system/framework
	adb shell chmod 644 /system/framework/$*.jar
	#adb shell stop
	#adb shell start
	#adb reboot

%.sign-plat : out/%
#%.sign-plat : /home/gexudong/libra.jbmiui/out/target/product/maguro/system/app/%
	java -jar $(TOOL_DIR)/signapk.jar $(PORT_ROOT)/build/security/platform.x509.pem $(PORT_ROOT)/build/security/platform.pk8  $< $<.signed
      [user=279333]@ECHO[/user] push -- to --- phone
	adb remount
	adb push $<.signed /system/app/$*
	adb shell chmod 644 /system/app/$*
So, you have to change:
local-zip-file := stock.zip name of your base rom
PORT_BUILD=/home/jack/patchrom/build to your patch for build folder
PORT_ROOT=/home/jack/patchrom to your root folder

After edit in makefile and save it in patchrom/stock folder you sholud copy from patchrom/build folder these files: porting.mk and phoneapps.mk
you can edit phoneapps.mk too add or delete files which you want.

File structure must look like this:
home
-your_username
-android-sdk-linux:
(-extras
-platform-tools
-platforms
-system-images
-tools)

-patchrom:
(-android
-build
-i9100
-miui
-stock (including: stock.zip - your base rom, makefile edited by you, phoneapps.mk edited by you, porting.mk - copied from build folder)
-tools)

6. Ok, files is prepared, now we can start. Open console and type:
cd patchrom - go to patchrom folder
cd stock - go to stock folder
cd .. - go back

make workspace - this command create temp folder in stock folder, and decompile all necessary files from stock.zip and from miui patchrom, it decompile also files which you add in makefile 'local-modified-apps'

Now in temp you have 5 folders, in reject folder you can resolve any conflicts to prepare necessary files for miui rom.

7. After fixing problems with smali type in console
make firstpatch

this command will apply all rej changes and miui patch for your decompiled files.

8. In console type:

Code:
source build/envsetup.sh
cd stock 
make zipfile
Thats all.

If you have problems google it ;)
Don't ask me for anything, use your brain! :p
 
Last edited:

serfer222

Senior Member
Sep 15, 2008
423
22
0
Moscow
Thank you for the information!
I think, you should add a couple of words to help linux newbies.
1. To set $PATH variable you need to edit "bashrc" file.
  • open terminal, run following command
  • Code:
    gedit ~/.bashrc
    gedit is an editor in Ubuntu, you can use any other editor
  • add to the begining
    Code:
    export PATH=/home/your_username/android-sdk-linux/platform-tools:/home/your_username/android-sdk-linux/tools:$PATH
  • save file
  • reboot to activate changes
  • test - open terminal, and execute "echo $PATH"

2. You need to generate keys to sign your rom.
http://android-dls.com/wiki/index.php?title=Generating_Keys
 
  • Like
Reactions: Koragg618

neXus PRIME

Senior Member
Nov 22, 2011
3,548
4,540
0
Lahore, Pakistan
Hi,
I just need to ask a few things.
1. How do we know which local apps need to be modified. and which miui apps need to be modified.? I mean is there a pre-defined list or its hit n trial??

I can follow the instructions and run the scripts, but i need to make sure how do we select the criteria for above files. Rest i'll try to figure out myself.

Regards
Yasir
 

adyscorpius

Senior Member
Oct 6, 2010
2,405
1,728
183
Delhi
www.aditsharda.com
I think a couple of mistakes there are, its make fullota where you have written make firstpatch because make firstpatch will create the temp poster where the 5 folders exist. Once you've fixed the rejects, that's when you make fullota. Also, we don't need PORT_BUILD and PORT_ROOT exports.
 
  • Like
Reactions: werty100

celderic

Senior Member
Dec 1, 2010
1,142
520
0
Thanks for the guide.
Going to try this out in a few hours, installing Linux in vmware workstation 10 currently :)

Sent from my GT-I9100 using Tapatalk 4
 

alfan.y

Senior Member
Feb 2, 2013
76
16
38
MTK 6575 - acer z2 JB4.1.1 dual sim

which branch do i used to patching MTK6575 JB4.1.1, JB4.2-MTK or JB4.1-non MTK?

[edit]
basicly as i know, that we have doing is:
- merged Miui framework(smali) to stock framework (smali), right?
- copy lib/etc/xbin ...
- edit bootclasspath if need.
- edit updater-script.
- repack all.
 
Last edited:

askpcguy

Senior Member
Aug 8, 2010
1,952
189
0
which branch do i used to patching MTK6575 JB4.1.1, JB4.2-MTK or JB4.1-non MTK?

[edit]
basicly as i know, that we have doing is:
- merged Miui framework(smali) to stock framework (smali), right?
- copy lib/etc/xbin ...
- edit bootclasspath if need.
- edit updater-script.
- repack all.
These pages are a great help. There are many others but start here.

Porting miui to other devices http://en.miui.com/thread-4569-1-1.html

Porting miui cm10.1 based devices http://en.miui.com/thread-6395-1-1.html

Porting miui patchrom guide http://en.miui.com/thread-9630-1-1.html