Comprehensive Understanding of Android phones (the second day of miui Rom adaptation-preparations)

Source: Internet
Author: User

1. Build a migration environment

"To do well, you must first sharpen your tools ". Before creating our own Rom, we must prepare for the migration environment.

The main idea of our series is how to modify it based on the original Rom. In theory, we do not need to modify the source code, the source code development interested can refer to the http://source.android.com. For Rom creators, we recommend that you download the android Source Code published by Google. This is not necessary, but it is helpful to understand some errors in ROM adaptation.

1.1 select the Operating System
The miui development team uses Ubuntu 10 or later for Rom development. For Rom transplantation, Windows (Windows XP and Windows 7) and Mac can both be used. However, because the development team uses the Ubuntu System for routine use, some of the script programs we will share will run on Ubuntu. Later we will introduce them based on Ubuntu, at the same time, I will try my best to mention the operation in windows. I'm sorry for using MAC very little. However, it is completely feasible to use MAC for transplantation. You can refer to the tools required in this article and refer to some materials on the Internet to build a Mac porting environment.

1.2 install Android SDK

For details about how to install the android SDK on Linux, windows, and Mac, refer to http://developer.android.com/sdk/installing.html. (What do people do if they don't understand bird's language? First, I sincerely think that Rom transplantation is better than basic bird's language. Second, I must admit that Rom transplantation is also possible if I don't understand bird's language. In this case, please go to Google to find out how to install android on the Internet.
SDK introduction in Chinese .)

To verify whether this step is successful, open the system settings in the mobile phone, select Application-development, make sure to select "USB debugging", and then connect your mobile phone with a USB cable, run the command ADB devices in Ubuntu shell or Windows console. If the display is similar to the following information, congratulations, ADB can recognize your mobile phone.
List of devices attached
304d1955996be28e Device
Note:
(1) You may be prompted that the ADB cannot be found. In this case, make sure to add the path of the ADB to the environment variable of the system.
(2) In windows, a driver must be installed on the mobile phone to identify the mobile phone.
(3) In ubuntu, the system may prompt "No such permissions". There are two methods at this time. The first method is to run as root. Method 2:
(3.1) run the lsusb command. For my SamSung mobile phone, the output is as follows:
Bus 002 device 001: Id 1d6b: 0002 Linux Foundation 2.0 root Hub
Bus 001 device 098: Id 04e8: 685e Samsung Electronics Co., Ltd
...
Find the row corresponding to the mobile phone and record 04e8: 685e, which respectively indicates the vendorid and productid of the device. If you are not sure which line the phone corresponds to, you can run lsusb before and after connecting the phone to find the line of the difference.
(3.2) create a file 99-android.rules in the/etc/udev/rules. d directory. Edit as follows:
Subsystems = "USB", attrs {idvendor} = "04e8", attrs {idproduct} = "685e", mode = "0666", owner = "your login identity"
(3.3) restart the USB service, sudo restart udev, and re-connect to the mobile phone.

ADB plays a very important role in our transplantation process. It and the next apktool will be introduced in the transplantation work of the Gemini constellation, and they are essential tools to walk the rivers and lakes. We will encounter it multiple times in subsequent chapters.

1.3 apktool and baksmali/smali
First, we recommend that you create a directory named tools and store all the tools to be downloaded in this directory.

Apktool: This is one of the most important tools for modifying Rom. We will introduce it in detail in the next chapter. Address: http://code.google.com/p/android-apktool/
Smali/baksmali: they are the compilation/anti-assembler of Dalvik virtual machines in Android. Apktool is actually based on the smali/baksmali encapsulation. We will introduce their usage in the next section. Address: http://code.google.com/p/smali/

2. Familiar with transplanted Models

"A journey of a thousand miles begins with a step ". Before porting, you must first familiarize yourself with the models we want to transplant.

2.1 browse Forum flash

If you want to beat people, learn to be beaten first, and learn to brush the machine first. Go to various forums to learn how your models are flushed. Here, we have to mention a required Forum: http://forum.x?#s.com /.

During this period, you must master the method of refreshing the machine model. What tools are needed? brush a few more Rom to play, and try to be familiar with the process of refreshing the machine.

2.2 find the appropriate original ROM and ensure the root

What is a proper original Rom? First, we need to use a proper version. We are talking about migrating miui based on the original Rom. Currently, 2.3 of miui is developed based on the source code of android2.3.7, versions from android2.3.3 to android2.3.7 have not changed much. Therefore, the original Rom versions from 2.3.3 to 2.3.7 are suitable. During the migration of the miui 4.0, we will also provide the source code development of the miui based on which android4.0 is used.

Check whether the installed rom has the root permission. There are two root permissions:
One is the mobile phone root: this root permission is shown in the external form that an authorization management software is installed on your mobile phone. When you use the re manager, a dialog box is displayed asking whether to grant the root permission.
One is the kernel root: This is the superset of the previous root permission.
To determine the root permission, run the following command on the Ubuntu shell or Windows console:
ADB root (this command means to run ADB with the root permission)
ADB remount (this command indicates that the system partition permission can be set to read/write)
If both commands are successful, it is the kernel root. Run ADB shell. The shell prompt on the mobile phone is #.
If the preceding two commands fail, run ADB shell and you can see that the shell prompt on the mobile phone is $. If the su command is run at this time, whether to grant the root permission is displayed on the mobile phone. This indicates that the authorization management program is installed on the mobile phone. In this case, after running the su command, the shell prompt on the mobile phone will change #.
Some of the tools we provide are based on your mobile phone to obtain the kernel root permission. If it is the mobile phone root, it is also possible, but you need to modify the script. Because the mobile phone is only root, the ADB remount command will fail. In this case, you need to re-Remount the system partition in the shell of the mobile phone and modify the directory permission of the system to modify the content of the system partition and modify some of the scripts we provide. (We do not recommend that you modify the system partition in this mode unless you have the root permission on your mobile phone ).

Generally, we can find the original root ROM on the Internet. If not, you need to find the relevant information in the Forum to learn in detail how to root, and how to obtain root permissions for different models is not the same, it is impossible to fully list in such an article, you can learn more about it on the forum.

Check that the selected ROM can enter the recovery mode and flash the machine. It is not necessarily required to be a CWM recovery. You can simply find a simple recovery with features such as wipe data/cache and zip package installation, of course, it is better to have CWM recovery.

2.3 ADB logcat

As mentioned above, ADB is a very important command. In the model adaptation process, we usually use ADB logcat. Through this command, we can see detailed log information.
The approximate format of each row is:
I/activitymanager (585): starting activity: intent {Action = Android. Intent. Action ...}
The first letter indicates priority (E indicates an error, W indicates a warning, And I indicates normal information ).
The activitymanager after the slash indicates the tag of the information, which usually indicates the module or program that prints the corresponding information.
You can use ADB logcat Tag: **: s to display only all information printed by the corresponding tag.
The number in the brackets indicates the process ID (PID), indicating the process ID of the program.
The sentence after the colon is a detailed description. When an error occurs, ADB logcat will provide a detailed error message, through which we can locate the error. Subsequent chapters will be mentioned one after another.
In model adaptation, ADB logcat *: E is often used to view all error messages.

For more information about ADB, see http://developer.android.com/guide/developing/tools/adb.html. After selecting the Rom, make sure that the ADB logcat command displays detailed log information at the beginning of the boot, if Adb logcat only prints information after the desktop program appears or does not print any information at all, it is difficult to transplant the program. You can modify some image resources, but for miui adaptation, we need to ensure that the ADB
The logcat function is running normally.

3. deodex
The first thing to do is deodex. What is deodex? Ah, this is really a long story.

Starting from the date of Android's invention, developers are expected to use the Java language to develop applications on the Android mobile platform, who uses it ). Java programs generally use the Java compiler (javac command) from the source file (. compiled into a class file (. files end with a class, also known as bytecode). Generally, many class files are packaged into a jar package (the jar package is actually a zip package ), then, use the Java Virtual Machine to explain and execute these class files. The use of file-like formats and the use of standard Java virtual machines need to pay the authorization fee to the Java owner (Sun was later acquired by Oracle, with silence) and comply with the relevant copyright agreement. Google does not want to pay this fee and is subject to the agreement. Therefore, it comes up with a method to "steal days, steal beams, and change columns", using a Java shell, but that heart is no longer a Java heart. To put it simply, when compiling a Java program on Android, the first step is to compile it into a class file and package it into a jar package, and then convert the jar package into a class file named classes. dex file. What is this Dex file? This is a bytecode file format invented by Google for its own virtual machine. On Android, this virtual machine is called the Dalvik Virtual Machine (Dalvik is the name of a small town in Iceland. At that time, Google engineers gave the virtual machine a name, and then Dan, a major engineer
Bronstein my ancestors lived in the town of Iceland and named it. It is said that Dan has never been to Iceland. After Android was released, Iceland was very proud. His local newspaper published this article and welcomed Dan to visit his hometown ). So what is odex? It is called optimized Dex, which is an optimized Dex file.

After talking about this, you only need to understand that odex is an optimized Dex file. As for how to optimize it, it is not within our scope. Odex files are mutually dependent. A simple understanding is that we have changed one of the files, and other odex files won't work. Therefore, we must perform a deodex operation to convert the odex file to the DEX file.

Generally, the original Rom is released in the odex file format. How can this problem be determined. Run the following command:
ADB shell ls/system/framework
If you see a lot of files ending with odex, the Rom is an odex. You can use the script deodex. Sh provided in the attachment to perform the deodex operation automatically.

The script first makes sure that you have installed smali/idea. Then perform deodex operations on the two directories respectively, and finally push the files after deodex to the mobile phone. For details, refer to the script.

Windows users can download idea.

4. Summary and case analysis
In this chapter, we will first familiarize ourselves with our models, and then look for a kernel root, a suitable version, and an original Rom capable of recovery mode flash. Take i9100 as an example, first we find the i9100 Odin package brush method in the miui Forum novice Road area, and then download to the http://115.com/file/cl7t65xn# i9100_zckjw.wipe.zip on the internet this factory root zip package, click the zip package in recovery mode. Verify ADB
Root available, run the deodex tool to perform the deodex operation, so that we have a factory Rom that has been used for deodex.

Tomorrow we will focus on the apktool and smali files, which are the key to porting.

Deodex. Sh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.