Contribute code process details to the android community

Source: Internet
Author: User

Everyone knows that android is an open source project, so anyone can contribute code to it, although there are detailed steps on the developer's website (http://source.android.com/source/submit-patches.html#upstream-projects ), however, one step by one may also cause a lot of trouble. Here, I will record the steps for successfully submitting the patch. On the one hand, I hope that others will not make any detour, on the one hand, it also provides a reference for students who are in conflict with English.

First, let's briefly introduce the official Android code review tool Gerrit. Gerrit is a git-based project management tool and code review tool. There are many articles about git on the Internet, we recommend a git classic book "Pro git", because the android source code is managed by git, and you will be familiar with it.

Git Chinese Tutorial: http://www.cnblogs.com/zhangjing230/archive/2012/05/09/2489745.html

Git get started with http://zhuidaniu.com/tutorials/22

Gerrit is a Web online tool. All externally submitted code must be submitted to this online tool for code review, only approved code can be incorporated into open-source projects. Once approved, Gerrit can automatically incorporate merge code into the code repository.

Android project Gerrit Portal: https://android-review.googlesource.com/#/q/status:open,n,z

If you are interested in Gerrit and want to integrate Gerrit into your current project, you can also refer to geriit's open source project: http://code.google.com/p/gerrit/

You also need to familiarize yourself with the repo commands officially provided by Android. repo is a Python script that encapsulates git commands and allows you to download multiple git repositories at the same time.

A Brief Introduction to git, Repo, Gerrit and the basic workflow for submitting a patch: http://source.android.com/source/version-control.html

I believe that you have a theoretical understanding of how to submit patches to the open-source Android project. Next, we will actually submit a patch from practice. We recommend that you use Ubuntu as the android source code development environment.

1. download Android source code, only based on the source code can submit our patch, source code download method please refer to the http://source.android.com/source/downloading.html, source code download may take a few hours or a few days of time, depending on the network situation, the connection to the android website in China is not very stable. It does not matter if a connection error occurs. Repo sync can be resumed and VPN can be used if possible.

1.1 create a local code directory and download the repo script.

$ Mkdir ~ /Bin $ Path = ~ /Bin: $ PATH // set ~ /Bin # Put the folder path to the system path, so that the command under this path can be directly called anywhere in the system $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo> ~ /Bin/repo # download the repo script to $ chmod A + x ~ in the bin folder ~ /Bin/repo # by default, the repo script does not have the execution permission and adds the execution permission to it.

1.2 install and configure Repo

You have downloaded the repo in 1.1, but you still need to install it to use it.

We create a separate folder to install the android source code and install the repo in this folder:

$ Mkdir working_directory $ CD working_directory $ repo init-u https://android.googlesource.com/platform/manifest # by default, the source code of the master branch is downloaded.

If you want to download the source code of the specified branch, such as the source code of Android 4.0.1r1, you can use the-B Option to specify

$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1

In this way, the repo is installed.

1.3 synchronize code to the local device.

$repo sync

Wait patiently...

2. Configure the Gerrit logon key

First, you need to create a Google account to log on to the Gerrit server. If you have Gmail, you can log on directly, but you do not have to register a Google account with a Gmail mailbox. Other mailboxes are also acceptable, here, I apply for a Google account to log on to Gerrit via email 163.

2.1 enter the https://android-review.googlesource.com/, click sign in the upper right corner to enter the Google account logon interface, if you have Gmail can directly log on, Otherwise click Create a new count to enter the following registration interface, enter the email address and other related information you want to display. After submission, the system will send a confirmation email to the email address you entered.

2.2 Open your mailbox and click the confirmation link to complete the confirmation.

2.3 click Continue and then log on to Gerrit, but I found that my login name is anonymous coward <springnap@163.com>, the reason why the show anonymous coward is because you have not set the display name, you can use setings --> contact information --> Edit to set your display name.

2.3.1

2.3.2

2.3.3

2.3.4 return to Gerrit's contact information page after the file is successfully saved, and Click Reload to update the display name.

Now let's see if the display information in the upper right corner of Gerrit is different?

2.4 configure the Gerrit authentication information in the local environment for identity authentication when submitting code to Gerrit.

2.4.1 In setting, click HTTP password --> obtain password to get the authentication information, and then copy the authentication information to your ~ /. In the netrc file, if there are two lines of passwords, copy both lines,

Because this information involves identity authentication information, it will no longer be here. Remember not to disclose your password. Otherwise, anyone can impersonate you to submit the code!

2.5 The preparation is complete, and the code can finally be moved!

2.5.1 before you submit the patchRequiredCreate a new code branch and see what the official documentation says:

Start a repo Branch

For each change you intend to make, start a new branch within the relevant git Repository:

$ repo start NAME .

You can start several independent branches at the same time in the same repository. The branch name is local to your workspace and will not be supported ded on Gerrit or the final source tree.

If you copy the command, you will encounter an error message "error: Project. Not Found". The key to the problem lies in this sentence.

For each change you intend to make, start a new branch within the relevant git repository

Do you still remember the repo features mentioned earlier? It means to download multiple git repositories to the local device at the same time. The GIT repository list has been mentioned before, which is in the android root directory /. repo (hidden in some cases)/manifest. XML. For example, we changed the file in packages/apps/gallery2.

As you can see, the path of the gallery2 project is the value of the path attribute. After finding the project path, replace '.' In 'repo start name. 'with the project path you want to change. (The name is the name of the local branch, which can be obtained by yourself)

2.5.2 if you want to submit a patch, you have to patch it. In fact, the so-called patch refers to your changes to the Code. Does it always pass the review as long as the logic of the change is correct? The answer is no, in addition to functional logic, the submitted patch thinks that the code format is very important. If you do not pay attention to it, it may be called back. Here is an example: in the android code specification, four spaces are used instead of tabs. If you are not familiar with the android code specification, let's take a closer look: http://source.android.com/source/code-style.html#use-spaces-for-indentation

2.5.3 submit code to the local branch. This is basically the same as submitting code to the local branch using git. note how to write the submitted information. The official website provides a template, it must be written in the standard format.

The first line cannot exceed 60 characters, and the next line is an empty line.

The description focuses on what problems you have solved and how the problem is solved. If you have added a new feature, you can add some new features.

To facilitate the work of other contributors in the future, add assumptions or background information.

  • Start with a one-line summary (60 characters max), followed by a blank line. This format is used by git and Gerrit for various displays.

    short description on first linemore detailed description of your patch,which is likely to take up multiple lines.
  • The description shoshould focus on what issue it solves, and how it solves it. The second part is somewhat optional when implementing new features, though desirable.

  • Include a brief note of any assumptions or background information that may be important when another contributor works on this feature next year.

2.5.4 submit your patch to Gerrit

$ repo upload

Remember that we are ~ /. Gerrit authentication information is written in netrc. The submitted code will be associated with the Gerrit account of the submitter.

No picture, no truth. Let's look at a commit:

Now, we have completed the entire process of submitting a patch to Gerrit to celebrate! The next step is to wait for the Community's experts to review your code. Only the code that passes the review and verification can be included in the open-source project repository!

Here is another tips to review and verify your code as soon as possible. You can invite others to help you review and verify your code. Review Code does not require special permissions, you can also help others review the code. The person who can verify the code is the person who master the power of killing and killing. Generally, this right is exercised by Google.

Inviting others to help you review can speed up your patch processing.

The above is my personal experience contributing code to Android. I hope to help those who are interested in Android. If not, I hope to correct them. Thank you.

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.