Android dual-host (network and USB) debugging and its perfect root

Source: Internet
Author: User

This article focuses on the following two parts.

1. How to bring two PCs to an Android mobile phone for debugging.

2. How to Perfect the root Android phone.

I have encountered this problem. I tested the Android system on Mac OS X.ProgramAs we all know, AndroidSource codeUbuntu Linux is usually required for compilation. Therefore, VMWare Ubuntu is installed on Mac OS X. So there is no problem. Connect the Android phone to the MBP, and the system will prompt you to connect to Mac OS X or ubuntu. However, there is one problem, that is, Ubuntu and Mac OS X can only be connected at the same time. Due to some requirements, it is depressing to use eclipse on Mac OS X to write Android applications and install them on the same Android phone, only one PC (including virtual machines) can be connected through USB cables ).

Technically, ADB has the ability to connect an Android mobile phone to two PCs. However, most readers may use the Rom, Which is disabled for security purposes. If the reader uses the latest cm Rom (cm10.1, this function may also be available in the old version, which has not been tested yet ), you will find a "Network ADB debugging" added in the "Developer options ". 1. This is a sought-after function.

Figure 1

Select "Network ADB debugging. Remember the following IP address and port number. Connect to your mobile phone with a USB cable on a machine. The devices list of eclipse shows that the mobile phone has been connected successfully. If you still use the current PC to connect to ADB through the network, you need to execute the following command (the PC and the mobile phone are in the same network segment ).

ADB kill-Server

ADB connect 192.168.17.103: 5555

If everything is normal, it is connected. Open eclipse and you will see the device 2 in the devices list.

Figure 2

In fact, the two devices are one, but the above is the mobile phone connected through the network, and the below is the mobile phone connected through the USB cable. Run the program now and you will still see the requirement to select the running device, as shown in 3.

Figure 3

You can choose either of them, because the two devices only connect to the PC in different ways.

If it is on different PCs (or PCs and virtual machines), one goes through the USB cable and the other goes through the network. Eclipse on the two machines can debug the program on the same mobile phone. Isn't that great!

If you want to disconnect the network ADB, run the ADB disconnect command.

Note that this operation is dangerous. Once you select "Network ADB debugging", as long as other users in the same network segment know the IP address and port number, you can operate your mobile phone at will, and there will be no prompts. Even on the other end of the Earth (as long as you are in the same network segment, including VPN ).

Now go to the second topic. If you get the ROM of your Android phone perfectly. Because cmrom is used previously (I don't know what cm Rom is, I will check it myself), so the root process of CM Rom is still discussed here.

Readers who are new to Android mobile phones may feel that the root mobile phone is very complicated, but it is actually easy. The basic principle of root is to place an su command in the/system/xbin directory of the Android system. Linux users who have used su know what Su is and a command to extract root permissions. If the reader uses cm Rom, the su command is available in the/system/xbin directory. In addition, you can enable the root permission in the settings (lower versions of CM directly enable the root permission). Therefore, you can use cm Rom to save this step. Of course, if you are not using the CM Rom, that's fine. The next CM Rom compressed package deletes all the miscellaneous items in it (including kernel image boot. IMG), only the su file in the system/xbin directory is retained (this file can also be found online to find a ready-made file, or directly compile the android SourceCodeSucan, instead of the script and meta-infest. Then, rewrite the script to update.zip. Then, you 'd better click clockworkmod recovery. in this case, update.zip can be refreshed without signature verification. Then you can use the recoverytemplate to refresh update.zip. This update.zip file is not a complete Rom, but an upgrade package. The purpose is to put the su file in the/system/xbin directory (this directory is read-only without the root permission ). After refreshing, enter the shell (ADB shell) of the mobile phone and execute Su to find that the original $ is changed to #, which indicates that it is already root. Of course, some directories are still not writable, for example, to make the system and its sub-directories writable, You need to execute the following command again.

Mount-o rw, remount/System

Now there is another problem, that is, entering the shell through the ADB shell, the default is still $, which is a bit of trouble, because for programmers, You Need To debug the system program, use the adbremount command to change the/system/APP directory to writable. Then, use the ADB push command to directly upload the APK file to this directory. However, if it is not root by default, the command cannot be executed (the permission is not allowed ). So another thing we need to do is to modify the content of default. prop in the root directory of the Android system, which can be changed to the following content.

 
Ro. ADB. secure = 0ro. secure = 0ro. allow. mock. location = 1ro. debuggable = 1persist. SYS. USB. config = mass_storage, adbpersist. service. ADB. enable = 1

The biggest problem is that the default. Prop is a memory file, and it is useless if it is changed. It will be restored once it is restarted and will only take effect after it is restarted (it seems that it is difficult to reason ). Therefore, you can modify the default. Prop file directly by modifying the boot. imgfile. The file consists of zimage and ramdisk. IMG. Zimage is the binary file of the Linux kernel. Ramdisk. IMG is a memory disk image. The image contains the INIT program called the first running program of Android. The default. Prop file is also included in the image. The android source code and Linux kernel source code are required below. We strongly recommend that you use the source code provided by cm. Because the CM team has made perfect adaptation for us, you only need to modify the business-related content. Now let's pay tribute to the CM team.

After the android source code is compiled, a root directory is generated in the related sub-directories of the out directory. The contents in this directory are extracted from the ramdisk. imgfile. Now find the default. Prop file and install the above content to modify it. Then use the following command to regenerate the ramdisk. imgfile.

Mkbootfs root | minigzip>/ramdisk. img

Next, use the following command to regenerate the boot. imgfile.

Mkbootimg -- kernel -- ramdisk. IMG-O boot. img

The kernel binary file is exactly the same as zimage. Only when compiling Android source code, name it

OK, now you can enter the bootloader mode, and then re-Execute fastboot flash bootboot. IMG to brush the kernel image, and then restart the mobile phone. Now you can go to shell. OK, the default value is. Exit shell and execute ADB remount. You can use ADB push to upload files to other directories of the/system, such as/system/app.

Related Article

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.