[Galaxy S Advance I9070 Q&A, Help & Troubleshooting] fedevd:
Building the kernel:

MIUI can boot with CM or AOSP kernel but you will need to change/add a few lines in it for MIUI. You have 2 ways to do those changes, unpacking the kernel or build it. Just because I am so nice and want you guys to take the most harder way because is the best way to learn and understand moaar all this I will tell you how to build the kernel from source, beside that is better this than unpacking and repacking the kernel. Let's start initializing the environment:

• Install the Android SDK and set it up (the instructions are on his own web page so I will not explain this)

• Open a 'Shell' (is the same as 'Terminal Emulator' on Android) and copy/pasta this:

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk

This step will install the Java JDK. After that, you will have to install a couple packages, so, again, copy/pasta this:

$ sudo apt-get install git gnupg flex bison gperf build-essential \
zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

After the required packages were installed, will be time to install 'repo', so copy/pasta this:

$ mkdir -p ~/bin
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

'CCACHE' (this will speed a lot the build proccess!!)

-TO BE ADDED-

Reboot your PC and boot again in Ubuntu. Now is time to sync the source, so open a 'Shell' again and copy/pasta this:

$ mkdir -p ~/android/system/
$ cd ~/android/system/
$ repo init https://github.com/TeamCanjica/android.git -b cm-10.1
$ repo sync -j4
$ ./vendor/cm/get-prebuilts
$ . build/envsetup.sh
$ cd frameworks/av
$ git fetch http://review.cyanogenmod.org/CyanogenMod/android_frameworks_av refs/changes/21/46421/3
$ git cherry-pick FETCH_HEAD
$ cd ../..
$ cd system/core
$ git fetch http://review.cyanogenmod.org/CyanogenMod/android_system_core refs/changes/32/45032/3
$ git cherry-pick FETCH_HEAD
$ cd ../..

At this point you will be able to build just the kernel or a fully CM10.1 rom. Maybe, when syncing and cherry picking ends, you wanna do again:

$ repo sync

Just to be sure that the entire source is fine.. Now, let's make some changes in the kernel. We will need to add the 'shelld' service, add 'framework_ext.jar' and make adb insecure:

* 'shelld' service and 'framework_ext.jar'

We will need to add this service (without this, Theme manager will not work or the launcher will FC, in example..) into the 'init.rc'. Watch the source https://github.com/TeamCanjica/android_system_core/blob/cm-10.1/rootdir/init.rc, that is the 'init.rc', now pay attention to the path of that file "android_system_core/rootdir/init.rc", that shows you where the file is, so in your PC will be on "android/system/core/rootdir/init.rc", that's the file we will use to add this service so open it scroll down to the bottom and add this at the end:

service shelld /system/xbin/shelld
class main

Now we will add 'framework_ext.jar' so press on the keyboard 'Ctrl+F' (search tool) and find 'export BOOTCLASSPATH', you will find something like this:

export BOOTCLASSPATH /system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar

Done? Fine, now to you have to add

:/system/framework/framework_ext.jar

between ':/system/framework/framework.jar' and ':/system/framework/telephony-common.jar', so the entire line should be:

export BOOTCLASSPATH /system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar[B]:/system/framework/framework_ext.jar[/B]:/system/framework/telephony-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar

Got it? Nice, that's all in the 'init.rc', now we can make it insecure or just build the kernel as 'eng' flag (Why 'eng' and not 'userdebug'? 'cus 'eng' will always be insecure), but if you wanna make it insecure just do this:

-TO BE ADDED-

Whitout this step, you will never be able to do logcats so you will never know why keeps bootlooping.. Interesting rigth? Jejeje

Now, fiiinaallyyy, let's build the kernel. Open a Shell and more copy/pasta:

$ cd ~/system/android/
$ . build/envsetup.sh
$ lunch cm_janice-eng
$ mka bootimage

Done, leave it building.. Could take 10~30 min. or even more.. You can pick the product on '/out' folder, the Shell will tell you where the file is anyway. Pick the kernel and copy to Windows partition through explorer (Why? You will need it and will not be able to pick it from Windows due to unsupported 'extx' partition from Windows).

Done with Ubuntu, time to get hands on Windows, so boot it up. The next step is the base of this 'cruzade' (LOL).

Our device, Advance or Janice or GT-I9070 (whatever), have a HDPI density so we will need to work with HDPI roms. First of all, we will use 2 roms:

* CM as base for port(called 'base' from now)

* MIUI as rom to port, obviouslly xD (called 'port' from now)

Download both of those roms, most newer CM build and MIUI. For MIUI, download most newer rom of any HDPI device based on 4.2.2 (yes, 4.2.2, so no place here for any CM10 build, CM10.1 only allowed). In MIUI v4 port I used 'crespo' (or better known as 'Nexus S') MIUI rom 'cus that device and the Advance have the same screen and density but the main issue is that I found just one MIUI rom for Nexus S based on 4.2 and I was unable to make it boot (I didn't worked hard anyway, just focused on the kernel only and minnor changes) so I can't be sure if that MIUI will be bootable, anyway if you find any other MIUI rom or wanna try with another rom is fine, but I recommend same screen and density. If you choose, in example, a XHDPI rom to port be prepared to face some oversized UI, but if you can deal with that then is fine for me, just be sure that is 4.2.2 based, no 4.1.2. I found this MIUI, maybe is the best shot:

http://en.miui.com/download-4.html

'Developer' version (not in the image case, that dev. version are v4, the third are v5.. Nevermind, the image is just illustrative) will be better 'cus MIUI came with his native root admin but in the 'stable' version they sometimes deactivate that, in 'developers' no, so you will not face any root headache.. =P

Let's see what we already did:

* Installed all the tools for Windows

* Installed Android SDK

* Installed Java

* Installed all the needed packages

* Synced the CM source for the kernel

* Modded and built the kernel

* Downloaded latest stable CM10.1 for base and MIUI for port

* Donated a beer to me and my awesome Canjica crew

* Sent me your credit card number

Nah, just kidding in the latest 2 points. I'm trying to make you laugh, this make this heavy work more funny instead of boring. Did you realized all the stuffs you did? Be proud that you already made too much and hope you learn a bit more about all this Android world, not about coding, just about necessary tools, how to set it up, the proccess, etc..

Now that we already have the kernel ready and we have the base rom and the port rom we will start with the most simple proccess, copy/pasta the necessary files. As [MENTION=2399936]Lens_flare[/MENTION] shared to everyone in his excellent guide (trust me, you will use more that guide than this one, here you have a more detailed proccess for one specific device, there you have a more detailed fixes of almost every 'framework' issue, so he really deserves a hugh thanks guys). Take the CM zip file and unpack it on a new folder (I always make a new folder on desktop called 'MIUI v'x' - 'device', in example: 'MIUI v5 - Advance', got it? Great!). We will basically drag and drop some files from port zip file into base project folder (the 'project folder' will be the folder you made and where you unpacked the base rom to work with it). Now you will have 2 folders, 'META-INF' and 'system', and 1 kernel, 'boot.img'.

Let's talk about it:

* 'META-INF' folder have the necessary files to make it flashable through CWM/TWRP recovery, the most important is the 'updater-script' because it have the 'instructions' and 'how will install' the rom

* 'system' folder, hmm, well, this have the system, should I have to explain something about this folder? =P

* 'boot.img' file is the kernel so no need to explain anything about it too

Now that you have those 3 folders/file, let's continue with the copy/pasta of neccessary files:

* Delete 'boot.img'

* Open 'system' folder and delete 'apps', 'fonts', 'framework' and 'media' folders

We will need those folders but the MIUI ones, so take those folders from port rom zip file and paste in 'system' of the project folder. Do not overwrite those folders, just remove the CM ones and add the MIUI ones.

Now, in the port rom zip file, go to '/system/etc' and copy this files:

* telocation.idf

* yellowpage.db

* secomxregistry

* pinyinindex.idf

* unicode_py_index.td

* permission_config.json

* spn-config.xml

And paste it on '/system/etc' folder in the project folder. Now you can overwrite those files and if you can't find any of the listed files in the port rom, just ignore it.

Now, '/system/etc/permissions' of port rom zip file. Some users, me too for v4, took this files:

* com.nxp.mifare.xml

* com.google.android.media.effects.xml

* com.google.widevine.software.drm.xml

* com.google.android.maps.xml

And placed in '/system/etc/permissions' of the project folder. The main issue is that I never saw those files in MIUI v5, that's why some users directly copy all the files from that folder, so let's try this, copy all files from '/system/etc/permissions' in port rom zip file except:

* handheld_core_hardware.xml

* platform.xml

Do the same with the '/system/lib' folder, copy this files:

* content-types.properties

* libFreqFilter.so

* libaudiofp.so

* libffmpeg_xm.so

* libffplayer_jni.so

* libimageutilites_jni.so

* libjni_resource_drm.so

* liblbesec.so

* liblocSDK_2.5OEM.so

* liblocSDK_2_5OEM.so

* libmp3lame.so

* libpatcher_jni.so

* libphotocli.so

* libshell*.so

And paste in '/system/lib' folder. Again, if you have to overwrite any of those files, do it and if you can't find any oh those files in the port rom zip file then just ignore it.

Now, in the port rom zip file go to '/system/xbin' and take this two files:

* shelld

* su

Like before, drag and drop in '/system/xbin' on the project folder and overwrite it. Done? Excellent, now we are going to work with the 'build.prop' located in '/system' on the project folder. Open it with 'Notepad++' and search this lines:

* ro.build.id​

* ro.build.display.id​

* ro.build.version.incremental

* ro.config.ringtone​

* ro.config.notification_sound​

* ro.config.alarm_alert

We need to set these lines with proper values:

​
ro.build.id=MIUI​
ro.build.display.id=MIUI​
ro.build.version.incremental=x.x.x​
ro.config.ringtone=MI.ogg​
ro.config.notification_sound=FadeIn.ogg​
ro.config.alarm_alert=GoodMorning.ogg

'x.x.x': this value can be setted with your birthday if you want it but will be better if we set the proper value to remember what MIUI build was used to port. To be more clear, watch the image I posted a couple lines up near of the red 'PORTED ROM', below the author you will see this: 'Version 3.12.6 ( V5 )'. The '3.12.6' is the incremental number and means this:

* '3' -> 2013

* '12' -> December

* '6' -> Day 6 of the current month

Got it? Great. Now you know how to set that value, the rest leave it like I posted.

Now, pick the 'boot.img' already compiled on Ubuntu and place it on the project folder. Done? Great, now you can select 'META-INF', 'system' and 'boot.img' files and compress it in a '.zip' file with WinRAR. Remember to select it as a zip file and Normal compression. Name that zip file as you want it, I always named as "MIUI vx - Test 1".

Finally you have the zip file, of course will booloop 'cus the framework were not diffed and patched, here is when 'adb' is crucial, from now we will work with 'smali'backsmali' and 'adb' tools.

To fix it step by step, you have 2 methods, one of them is flash the rom and make logs looking the error that cause the bootloop or patch the commons smali's first and then look the errors that cause the bootloop. Those smali's are inside of 'framework.jar' and 'services,jar' located on '/system/framework'. So, create 2 folders, the first one called 'CM' and the second one called 'MIUI'. Now open the original CM zip file and extract 'framework.jar' and 'services.jar' on CM folder. Do the same with the original MIUI zip file, pick those 2 files and extract it but on MIUI folder. Now we need to put a copy of 'smali' and 'baksmali' tools files on both folders. Done? Ok, now let's decompile the 'framework.jar' first opening the CM folder and a cmd window (just press 'Mayus' on keyboard and left click on any clean space on CM folder and select 'Open a command prompt here...' or go to 'Start' and write 'cmd' on search toolbox, open it and use 'cd' command to go to the CM folder). Now on the 'cmd' run this command:

java -jar baksmali.jar -b framework.jar -o framework.jar.out

Leave it finish and you will have a new folder called 'framework.jar.out', open it and you will find all the smalis in those folders. Do the same with the MIUI framework, open the folder, open a cmd and run that command. Ok, now it's time to overwritte the common smali files from CM folder to MIUI. Those common smali's files are this:

* android/content/res/PackageRedirectionMap*.smali

* android/hardware/Camera*.smali

* android/media/AudioFormat.smali

* android/net/wifi/wifichannel.smali

* android/net/wifi/wifinative.smali

* android/os/SystemProperties.smali

* android/view/Gles20*.smali

* android/view/inputmethod/inputmethodinfo*.smali

* android/webkit/html5*.smali

* android/webkit/selectactionmodecallback.smali

* com/android/internal/app/ActivityTrigger.smali​

You can just take those smali's and overwritte it. The next step will be add/patch missing 'methods' (the 'methods' are blocks of code), you only need to add the missing methods, not modify anything, I mean, if 'x' are not present in the MIUI smali, you will have to add it, here is where Winmerge gets in. The smalis you will have to patch are:

* android/content/res/AssetManager.smali

* android/media/AudioFormat.smali

* android/webkit/WebSettingsClassic.smali

So compare those files with the CM ones and add from CM smalis to MIUI smalis always. That's all with 'framework.jar', now we will patch 'services.jar', so again, overwrite from CM smali files to MIUI files this files:

* com/android/server/input/InputManagerService*.smali​

After that you will have to patch 'PowerManagerService.smali' located at 'com/android/server/power'. Search the block '.method private static native nativeCpuBoost(I)V​' and add it from CM to MIUI one. Done? Nice, now compile 'framework.jar' and 'services.jar' doing this from a Shell (or cmd or whatever you call it):

java -jar smali.jar framework.jar.out

and

java -jar smali.jar services.jar.out

Running those commands you will compile both files again and you will have as result a file called 'out.dex', that file will have to replace the 'classes.dex' inside of both '.jar' files (framework and services). So, to make it easyer, compile 'framework.jar', rename 'out.dex' result to 'classes.dex', open 'framework.jar' and drag and drop 'classes.dex' from folder to 'framework.jar' zip file overwritting the one inside, then do the same with 'services.jar'. Done? Great, now pick 'framework.jar' and 'services.jar' and paste in the rom in 'framework' folder. Excellent, now is time to flash the rom and start making logs. This is the most heavy step 'cus you will have to test, find the error (for sure will be a smali framework error), patch it and then flash it, agaain, test, search the error in logs, patch it too, and flash it, that's why is heavy, is a repetitive proccess. You will have to do that one, two, three, four, five times until properlly boot.

ⓣⓐⓟⓐⓣⓐⓛⓚ