[GUIDE] How-To Cherry-Pick Features for your ROM (both GitHub and Gerrit)

Search This thread

jabza

Senior Member
Aug 20, 2012
521
708
Hi guys. So I've had a few people PM me and ask for help cherry picking features to build a ROM from source. I've decided I might as well post a guide with what I've gathered. I'll outline the procedure for cherry-picking from both gerrit as well as GitHub, and what to do afterwards.

Once you've completed the guide, feel free to post questions/comments/advice in the thread. If you run into any issues, I will be happy to answer them (along with other helpful members of our community). If you think I should add something to the guide or change something, also feel free to let me know. I haven't noticed any good resource concerning cherry-picking on XDA, so discussion is encouraged.

Before we begin cherry-picking, I'm going to be making a few assumptions. I assume that:
  • you are using Ubuntu (or another Linux distribution) and you have git installed
  • you have the source code for your ROM downloaded on your PC
  • you know how to compile your ROM
  • you are somewhat comfortable using the terminal

Let's get started!

Table of contents:
1. Cherry-Picking from Gerrit
2. Cherry-Picking from GitHub
3. Conflict Resolution
4. Troubleshooting/After the Cherry-Pick
 
Last edited:

jabza

Senior Member
Aug 20, 2012
521
708
Cherry-Picking from Gerrit

Cherry Picking a feature from Gerrit

To begin cherry-picking, you should first go to the gerrit for your desired cherry-pick and find its entry/entries. I'll cherry-pick Halo from the ParanoidAndroid gerrit into AOSP.

Because I want Halo, I'll open go to ParanoidAndroid gerrit at http://gerrit.paranoidandroid.co and find the Halo entries. This is what it looks like:

etbBbb4.png


You'll notice there are two Halo entries, one titled [1/2] Settings: HALO, and one titled [2/2] Frameworks: HALO. To get this feature, I'll need both, hence the tags 1/2 and 2/2 at the beginning. Here are the links for reference:

[1/2] Settings: HALO
[2/2] Frameworks: HALO

Great, now we have the entries for the two “commits” that we want to add to our ROM. We'll start with the first one. The page may look overwhelming at first, but there are two bits that are most important to us: the Project tag and the Download tab. Here's what they look like:

4oAdKuP.png


Look at the project title. It says “AOSPA/android_packages_apps_Settings”. This tells us exactly where in our source code to apply this commit. On my system, I have AOSP downloaded to the folder ~/AOSP. I open a terminal and enter the command “cd ~/AOSP”. Replace “AOSP” with your code directory.

Now, in your terminal, type:
Code:
cd packages/apps/Settings

Now that you're in the right spot, it's time to download the commit and try to apply it. Click the download tab in your browser, then from the dropdown choose “anonymous HTTP” and choose “cherry-pick”. Here's what it looks like:

yz5Dqr9.png


o6niOzT.png


When you click the clipboard next to the “Cherry-Pick” option, it'll copy to your clipboard. Now, go back to your terminal and press CTRL + Shift + V to paste it.

Code:
git fetch https://gerrit.paranoidandroid.co/AOSPA/android_packages_apps_Settings refs/changes/39/239/14 && git cherry-pick FETCH_HEAD

Chances are, unless you're very lucky, your terminal will do some work and look like this:

BfykH1n.png


To continue, skip to post #4
 
Last edited:

jabza

Senior Member
Aug 20, 2012
521
708
Cherry-Picking a Feature from GitHub

Cherry-Picking a Feature from GitHub

To begin cherry-picking, you need to find the GitHub “commit” for what you want. A commit is a record of the changes that were made to achieve something, whether it be a new feature or a bug fix.

Today, I'm going to take pure AOSP and cherry-pick ParanoidAndroid's Halo. Because ParanoidAndroid gave up the feature, I can't take it from their GitHub. Conveniently, I have it in my own GitHub and will use that.

Note: you will only find things that have already been added to a project's code on GitHub. ParanoidAndroid gave up on Halo, so it is not added to their code. Because it is not already merged, it will not be in GitHub

First things first, you locate the commit. I know it's in my GitHub, so I'll open that in my browser at http://github.com/jabza-. I already know that Halo requires two commits, one for the settings and one for the frameworks. I'll open the projects “aospa_packages_apps_Settings” and “aospa_frameworks_base”. I'll start with the frameworks.

When you open the page, it's a little confusing. We want to see the commits, so we'll click “commits” toward the top.

hfeFUZR.png


Now, I'll have to go down the list to the Halo commit. Here's a link for reference: [2/2] Frameworks: HALO

Note: the commit name has [2/2] at the beginning, showing us that it is the 2nd commit of two. The other is in aospa_packages_apps_Settings

Note: my commit history in aospa_frameworks_base currently has two commits for Halo. The more recent one was a bug fix and I mistakenly left the commit message as it is – you want the older commit for the full change

Scroll down to the bottom of the blue commit message. Below it, there' s a list of the files and the changes made. You may use this for reference later, but it's not important now. What's important is the commit ID, which is listed at the bottom of the commit message.

wQfirpf.png


Now, we go to the terminal. I have my AOSP source in ~/AOSP, so when I open my terminal first enter
Code:
cd ~/AOSP

The project name that we are working from is aospa_frameworks_base. This tells us that the commit belongs in frameworks/base. So, to begin work:
Code:
cd frameworks/base

Now, we have to “fetch” the project so we can cherry-pick the commit.
Code:
git fetch git://github.com/jabza-/aospa_frameworks_base.git

Now that we have the commit history of aospa_frameworks_base, we can tell the terminal to cherry-pick. We must use the commit ID at the bottom that we found earlier. You can copy the commit to your clipboard, and paste it in the terminal with CTRL + Shift + V.
Code:
git cherry-pick ab72e4ab36778474593ffce89150aece01d5f9c6

Obviously, when cherry-picking anything else, replace “ab72e4ab36778474593ffce89150aece01d5f9c6” with the commit ID of that commit.

Now, your terminal will do some work, and it will say it couldn't commit it automatically. It should look something like this:

XtYoe0x.png


Now, we get to resolve the conflicts. Continue to the next post.
 
Last edited:

jabza

Senior Member
Aug 20, 2012
521
708
Resolving Conflicts from Cherry-Picking

Resolving Conflicts from Cherry-Picking

So you've found the commit you want to cherry-pick. You've gone to the right place in your source code to apply it. You've told your computer to apply the cherry-pick. It said it couldn't. Now what?

Well let's see what's wrong.

Code:
git status

Your terminal will now tell you what files have been automatically changed for you and what you need to change yourself. In green are the files that are done, and in red are the files you need to tell it what to do with. Here's what your terminal should look like after “git status”:

If you cherry-picked from gerrit with me and did [1/2] Settings: HALO, it'll look something like this:

p56v7Mr.png


If you cherry-picked from GitHub with me and did [2/2] Frameworks: HALO, it'll look something like this:

bojOffF.png


In looking at the files in red, we see two different tags.

  • deleted by us – this means that there's a file in the commit that doesn't exist on our computer
  • both modified – this means that there's a file that was supposed to be modified, but that was modified on our computer from what was expected in the commit
  • deleted by them – this is a third tag you may see, though it's not here. This means that the commit deletes a file which we stil have on our computer

So, what do we do? Let's start with the ones tagged “both modified”. The first file in red underneath the frameworks/base commit is packages/SystemUI/res/layout/status_bar_expanded_header.xml. We'll open it in our favorite text editor and see what it's all about.
Code:
gedit packages/SystemUI/res/layout/status_bar_expanded_header.xml

Now we search for what's messing with our cherry-pick. It's enclosed in the tags “<<<<<<< HEAD” and “>>>>>>> ab72e4a... [2/2] Frameworks: HALO”. Lines 78-118 look like this:

Code:
<<<<<<< HEAD
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:scaleType="center"
        android:src="@drawable/ic_notify_clear"
        android:background="@drawable/ic_notify_button_bg"
        android:contentDescription="@string/accessibility_clear_all"
        />     
=======
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginLeft="4dp"
        android:scaleType="center"
        android:src="@drawable/ic_notify_clear"
        android:background="@drawable/ic_notify_button_bg"
        android:contentDescription="@string/accessibility_clear_all"
        />

    <FrameLayout android:id="@+id/context_button_holder"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginStart="4dp"
        >
        <ImageView android:id="@+id/halo_button"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:scaleType="center"
            android:src="@drawable/ic_notify_halo"
            android:contentDescription="@string/accessibility_halo"
            />
        <ImageView android:id="@+id/edit_mode_button"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:scaleType="center"
            android:src="@drawable/ic_notify_edit_normal"
            android:background="@drawable/ic_notify_button_bg"
            android:visibility="gone"
            android:contentDescription="@string/accessibility_clear_all"
            />
    </FrameLayout>
>>>>>>> ab72e4a... [2/2] Frameworks: HALO

Between the <<<<<< HEAD and ======== is code that wasn't expected to be there. Between ====== and >>>>>> ab72e4a... [2/2] Frameworks: HALO is the code that was added in by the commit. Here is where we use our judgement to edit the code to what we need. Because I can see that the code between <<<<<< HEAD and ====== is duplicated by the commit, I can just delete that snippet altogether. We also need to delete the tags added by our cherry pick. In the end, the code looks like this:

Code:
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginLeft="4dp"
        android:scaleType="center"
        android:src="@drawable/ic_notify_clear"
        android:background="@drawable/ic_notify_button_bg"
        android:contentDescription="@string/accessibility_clear_all"
        />

    <FrameLayout android:id="@+id/context_button_holder"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginStart="4dp"
        >
        <ImageView android:id="@+id/halo_button"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:scaleType="center"
            android:src="@drawable/ic_notify_halo"
            android:contentDescription="@string/accessibility_halo"
            />
        <ImageView android:id="@+id/edit_mode_button"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:scaleType="center"
            android:src="@drawable/ic_notify_edit_normal"
            android:background="@drawable/ic_notify_button_bg"
            android:visibility="gone"
            android:contentDescription="@string/accessibility_clear_all"
            />
    </FrameLayout>

Now we can save and quit.

We've resolved the conflict (assuming that was the only one), and now we can mark it as such in the terminal. To do so, we use this command:
Code:
git add  packages/SystemUI/res/layout/status_bar_expanded_header.xml

Now, we can do “git status” again and work on the next file we need to modify.

But what about the “deleted by us” files? Well, git is smart. All we need to do is determine if we need those files (hint: unless you really know what you're doing, you do need them). If we need them, git already loaded the files up, so we just have to mark them as resolved by doing
Code:
git add res/values/pa_arrays.xml

You can replace “res/values/pa_arrays.xml” with the rest of the files labeled “deleted by us”. You can also do more than one file at once, like so:
Code:
git add res/values/pa_arrays.xml res/values/pa_strings.xml whatever/files/I/want.java

Continue until you've fixed all the issues.

Note: when you open a file in gedit, it creates a file with the same name but with a ~ added to the end. When you do “git status” these files will show up as “untracked files”. You can either delete them with the command “rm path/to/file.java~” or just ignore them.

Once you do “git status” and all the files turn up green, you have finished resolving the conflicts. Now is the best time to compile your ROM and see if your changes worked. If you're in a rush (or lazy or don't feel like waiting for a ROM to compile or you've already tested it), you can now commit your changes.
Code:
git commit

It'll take you to a screen to write your commit message. It opens it in the in-terminal editor “nano”. You can edit it to say whatever you want, and when you're done press CTRL + X to exit, and then press Y to save the changes. Then your terminal will say you've committed the changes.

Congratulations! You've successfully cherry-picked a commit.
 
Last edited:

jabza

Senior Member
Aug 20, 2012
521
708
Troubleshooting/After the Cherry-Pick

Troubleshooting/After the Cherry-Pick

Once you've finished adding a cherry-pick, a whole variety of things can happen. You might:
  • build, and it will stop with some build erros
  • build, and it will complete, but something will go wrong when you flash it
  • want to get rid of the cherry-picks altogether

Well, what do you do?

If you build, and it stops building, there will be build errors. Your terminal will tell you what's wrong. Look/scroll up, and there will be something that says:
Code:
path/to/file/problem.java:86: some sort of error ocurred
line.of(code, that causes); a problem {
                  ^

The first thing it says is a file. It will be a path relative to the part it was compiling, so you might have to look for a clue above that to see where it was working on. At the end of the file is a number (in this case 86). That number tells you what line the problem is on in that file. After that, it tells you what the error was that in ran into. Then, it'll print the line that had the error with a carat (^) underneath where it had an issue.

How do you fix it? Just open up the file with something like
Code:
gedit path/to/file/problem.java
and go to line 86 and see what the problem is. Usually it's something pretty straightforward, like mismatched parentheses or a dropped semicolon. Once you've fixed the issue, save the file and build again!

But what about if the build is successful, but it causes bugs in your build? Well, start up your phone plugged into your computer, and use this command:
Code:
adb logcat > errorlog
Once the phone becomes available, your computer will start recording the logcat to the file errorlog. Once you've captured the bug, then you can disconnect your phone and reflash something stable. You can also use CTRL + C to stop the logcat command. Now, you can open the logcat with the command
Code:
gedit errorlog

Reading logcats may take some getting used to. It will take quite a bit of scrolling, but the errors are probably marked with an E at the beginning of the line.

Now, what about if you've got some issues, and you just want to scrap the cherry-picks? Well, it's pretty straightforward. Just use
Code:
repo sync
and all committed cherry-picks will be wiped out and you'll be synced with the source that you're building from/

What if you want to do a repo sync and keep that commit, you ask? Don't worry! Git is smart. It remembers how you resolved the cherry-pick. You can do a repo sync and then cherry-pick again, and it'll automatically try to apply your previous resolution. Neat, huh?

Alternatively, you can fork the project to your own git repository (GitHub accounts are free for students!) and add that to your repo manifest. That's a whole different story, though, and will require extra research.
 
Last edited:

Walterwhite007

New member
May 27, 2014
4
0
Great guide. It really helps noobs like me xD. One question what are the repositories I should fork from paranoid android into my github to build a ROM for nexus 4. Their github have soooo many repositories like apps and settings, packages, manifest etc etc

Sent from my Nexus 4 using Tapatalk
 

jabza

Senior Member
Aug 20, 2012
521
708
You should also mention how to cherry pick multiple commits

I would like to know this too, when I try to add two commits to the same location, it wants to drop one and add the other. I want to keep both but I cant figure out how to do so. Thanks for your help!

Cherry-picking multiple commits is pretty straightforward. Once you've resolved any conflicts for one commit, you have to finish by using the command
Code:
git commit
if you want to add another cherry-pick in the same location.

Once you've committed that, you should be able to start the cherry-picking process over again exactly the same. If you have an issue, can you tell me what your terminal says, or post a screenshot?

Great guide. It really helps noobs like me xD. One question what are the repositories I should fork from paranoid android into my github to build a ROM for nexus 4. Their github have soooo many repositories like apps and settings, packages, manifest etc etc

Sent from my Nexus 4 using Tapatalk

To build ParanoidAndroid, you first have to download the source to your computer. So you'd have to make a directory and use "repo init -u http://github.com/AOSPA/manifest.git -b kitkat && repo sync" to start the download. It's a big download, so be ready to wait a couple hours. There's a good guide for building ParanoidAndroid 4+ here

However, as far as forking a repository, you only need to fork the repositories that you want to make your own changes to and keep track of. Really, you don't have to fork anything.
 

Walterwhite007

New member
May 27, 2014
4
0
I have the source code. But when I successfully cherry pick some commits and when I say gitpush it says access denied something. I want to fork pa's nexus 4 ROM sources into my git repository so that I can sync from my github and build. But what are the things I need to fork??
 

jabza

Senior Member
Aug 20, 2012
521
708
I have the source code. But when I successfully cherry pick some commits and when I say gitpush it says access denied something. I want to fork pa's nexus 4 ROM sources into my git repository so that I can sync from my github and build. But what are the things I need to fork??

Well yeah, git push tries to send your changes to the repository you took it from - in this case, PA's. For obvious reasons, you don't have permissions to push changes to the PA github. You just have to fork the repos you want to change and add them in your repo manifests. If you want the entire ROM in your git, you'll have to look at all the projects in .repo/manifest.xml and fork every single one. That's a little excessive, so just fork the repos you want to change.
 
  • Like
Reactions: Walterwhite007

Walterwhite007

New member
May 27, 2014
4
0
Well yeah, git push tries to send your changes to the repository you took it from - in this case, PA's. For obvious reasons, you don't have permissions to push changes to the PA github. You just have to fork the repos you want to change and add them in your repo manifests. If you want the entire ROM in your git, you'll have to look at all the projects in .repo/manifest.xml and fork every single one. That's a little excessive, so just fork the repos you want to change.

Thanks bro. I tried many times cherry picking halo but that always messed up. Now after following this great guide I'll give it another try !!

Say my name
 

xxLeoxx93

Senior Member
Mar 26, 2013
428
116
Very good tutorial :good:
But I've two question:
- What does the command "git commit" do? Will the rom compile without the cherry-pick without this command?
- Can I compile a flashable zip for my rom just with the cherry-pick and without compiling the whole rom again?
 

jabza

Senior Member
Aug 20, 2012
521
708
Very good tutorial :good:
But I've two question:
- What does the command "git commit" do? Will the rom compile without the cherry-pick without this command?
- Can I compile a flashable zip for my rom just with the cherry-pick and without compiling the whole rom again?
- "git commit" tells your computer it's done with editing and finishes the cherry-pick process. That is when git saves your resolution, so that if you go back and cherry-pick that commit again it can automatically apply your resolution to the problem. The ROM will compile without this command, but you won't be able to use "repo sync" to update that project or add any other cherry-picks to that location until you run "git commit" or "git cherry-pick --abort", which removes the cherry-pick altogether.

- When you rebuild the ROM, as long as you don't use "make clean" or "make clobber", it will only recompile the parts that have changed. The next build will go much faster. If you want the builds to go even faster, you should use ccache.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 76
    Hi guys. So I've had a few people PM me and ask for help cherry picking features to build a ROM from source. I've decided I might as well post a guide with what I've gathered. I'll outline the procedure for cherry-picking from both gerrit as well as GitHub, and what to do afterwards.

    Once you've completed the guide, feel free to post questions/comments/advice in the thread. If you run into any issues, I will be happy to answer them (along with other helpful members of our community). If you think I should add something to the guide or change something, also feel free to let me know. I haven't noticed any good resource concerning cherry-picking on XDA, so discussion is encouraged.

    Before we begin cherry-picking, I'm going to be making a few assumptions. I assume that:
    • you are using Ubuntu (or another Linux distribution) and you have git installed
    • you have the source code for your ROM downloaded on your PC
    • you know how to compile your ROM
    • you are somewhat comfortable using the terminal

    Let's get started!

    Table of contents:
    1. Cherry-Picking from Gerrit
    2. Cherry-Picking from GitHub
    3. Conflict Resolution
    4. Troubleshooting/After the Cherry-Pick
    55
    Resolving Conflicts from Cherry-Picking

    Resolving Conflicts from Cherry-Picking

    So you've found the commit you want to cherry-pick. You've gone to the right place in your source code to apply it. You've told your computer to apply the cherry-pick. It said it couldn't. Now what?

    Well let's see what's wrong.

    Code:
    git status

    Your terminal will now tell you what files have been automatically changed for you and what you need to change yourself. In green are the files that are done, and in red are the files you need to tell it what to do with. Here's what your terminal should look like after “git status”:

    If you cherry-picked from gerrit with me and did [1/2] Settings: HALO, it'll look something like this:

    p56v7Mr.png


    If you cherry-picked from GitHub with me and did [2/2] Frameworks: HALO, it'll look something like this:

    bojOffF.png


    In looking at the files in red, we see two different tags.

    • deleted by us – this means that there's a file in the commit that doesn't exist on our computer
    • both modified – this means that there's a file that was supposed to be modified, but that was modified on our computer from what was expected in the commit
    • deleted by them – this is a third tag you may see, though it's not here. This means that the commit deletes a file which we stil have on our computer

    So, what do we do? Let's start with the ones tagged “both modified”. The first file in red underneath the frameworks/base commit is packages/SystemUI/res/layout/status_bar_expanded_header.xml. We'll open it in our favorite text editor and see what it's all about.
    Code:
    gedit packages/SystemUI/res/layout/status_bar_expanded_header.xml

    Now we search for what's messing with our cherry-pick. It's enclosed in the tags “<<<<<<< HEAD” and “>>>>>>> ab72e4a... [2/2] Frameworks: HALO”. Lines 78-118 look like this:

    Code:
    <<<<<<< HEAD
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:scaleType="center"
            android:src="@drawable/ic_notify_clear"
            android:background="@drawable/ic_notify_button_bg"
            android:contentDescription="@string/accessibility_clear_all"
            />     
    =======
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginLeft="4dp"
            android:scaleType="center"
            android:src="@drawable/ic_notify_clear"
            android:background="@drawable/ic_notify_button_bg"
            android:contentDescription="@string/accessibility_clear_all"
            />
    
        <FrameLayout android:id="@+id/context_button_holder"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginStart="4dp"
            >
            <ImageView android:id="@+id/halo_button"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:scaleType="center"
                android:src="@drawable/ic_notify_halo"
                android:contentDescription="@string/accessibility_halo"
                />
            <ImageView android:id="@+id/edit_mode_button"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:scaleType="center"
                android:src="@drawable/ic_notify_edit_normal"
                android:background="@drawable/ic_notify_button_bg"
                android:visibility="gone"
                android:contentDescription="@string/accessibility_clear_all"
                />
        </FrameLayout>
    >>>>>>> ab72e4a... [2/2] Frameworks: HALO

    Between the <<<<<< HEAD and ======== is code that wasn't expected to be there. Between ====== and >>>>>> ab72e4a... [2/2] Frameworks: HALO is the code that was added in by the commit. Here is where we use our judgement to edit the code to what we need. Because I can see that the code between <<<<<< HEAD and ====== is duplicated by the commit, I can just delete that snippet altogether. We also need to delete the tags added by our cherry pick. In the end, the code looks like this:

    Code:
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginLeft="4dp"
            android:scaleType="center"
            android:src="@drawable/ic_notify_clear"
            android:background="@drawable/ic_notify_button_bg"
            android:contentDescription="@string/accessibility_clear_all"
            />
    
        <FrameLayout android:id="@+id/context_button_holder"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginStart="4dp"
            >
            <ImageView android:id="@+id/halo_button"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:scaleType="center"
                android:src="@drawable/ic_notify_halo"
                android:contentDescription="@string/accessibility_halo"
                />
            <ImageView android:id="@+id/edit_mode_button"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:scaleType="center"
                android:src="@drawable/ic_notify_edit_normal"
                android:background="@drawable/ic_notify_button_bg"
                android:visibility="gone"
                android:contentDescription="@string/accessibility_clear_all"
                />
        </FrameLayout>

    Now we can save and quit.

    We've resolved the conflict (assuming that was the only one), and now we can mark it as such in the terminal. To do so, we use this command:
    Code:
    git add  packages/SystemUI/res/layout/status_bar_expanded_header.xml

    Now, we can do “git status” again and work on the next file we need to modify.

    But what about the “deleted by us” files? Well, git is smart. All we need to do is determine if we need those files (hint: unless you really know what you're doing, you do need them). If we need them, git already loaded the files up, so we just have to mark them as resolved by doing
    Code:
    git add res/values/pa_arrays.xml

    You can replace “res/values/pa_arrays.xml” with the rest of the files labeled “deleted by us”. You can also do more than one file at once, like so:
    Code:
    git add res/values/pa_arrays.xml res/values/pa_strings.xml whatever/files/I/want.java

    Continue until you've fixed all the issues.

    Note: when you open a file in gedit, it creates a file with the same name but with a ~ added to the end. When you do “git status” these files will show up as “untracked files”. You can either delete them with the command “rm path/to/file.java~” or just ignore them.

    Once you do “git status” and all the files turn up green, you have finished resolving the conflicts. Now is the best time to compile your ROM and see if your changes worked. If you're in a rush (or lazy or don't feel like waiting for a ROM to compile or you've already tested it), you can now commit your changes.
    Code:
    git commit

    It'll take you to a screen to write your commit message. It opens it in the in-terminal editor “nano”. You can edit it to say whatever you want, and when you're done press CTRL + X to exit, and then press Y to save the changes. Then your terminal will say you've committed the changes.

    Congratulations! You've successfully cherry-picked a commit.
    49
    Cherry-Picking a Feature from GitHub

    Cherry-Picking a Feature from GitHub

    To begin cherry-picking, you need to find the GitHub “commit” for what you want. A commit is a record of the changes that were made to achieve something, whether it be a new feature or a bug fix.

    Today, I'm going to take pure AOSP and cherry-pick ParanoidAndroid's Halo. Because ParanoidAndroid gave up the feature, I can't take it from their GitHub. Conveniently, I have it in my own GitHub and will use that.

    Note: you will only find things that have already been added to a project's code on GitHub. ParanoidAndroid gave up on Halo, so it is not added to their code. Because it is not already merged, it will not be in GitHub

    First things first, you locate the commit. I know it's in my GitHub, so I'll open that in my browser at http://github.com/jabza-. I already know that Halo requires two commits, one for the settings and one for the frameworks. I'll open the projects “aospa_packages_apps_Settings” and “aospa_frameworks_base”. I'll start with the frameworks.

    When you open the page, it's a little confusing. We want to see the commits, so we'll click “commits” toward the top.

    hfeFUZR.png


    Now, I'll have to go down the list to the Halo commit. Here's a link for reference: [2/2] Frameworks: HALO

    Note: the commit name has [2/2] at the beginning, showing us that it is the 2nd commit of two. The other is in aospa_packages_apps_Settings

    Note: my commit history in aospa_frameworks_base currently has two commits for Halo. The more recent one was a bug fix and I mistakenly left the commit message as it is – you want the older commit for the full change

    Scroll down to the bottom of the blue commit message. Below it, there' s a list of the files and the changes made. You may use this for reference later, but it's not important now. What's important is the commit ID, which is listed at the bottom of the commit message.

    wQfirpf.png


    Now, we go to the terminal. I have my AOSP source in ~/AOSP, so when I open my terminal first enter
    Code:
    cd ~/AOSP

    The project name that we are working from is aospa_frameworks_base. This tells us that the commit belongs in frameworks/base. So, to begin work:
    Code:
    cd frameworks/base

    Now, we have to “fetch” the project so we can cherry-pick the commit.
    Code:
    git fetch git://github.com/jabza-/aospa_frameworks_base.git

    Now that we have the commit history of aospa_frameworks_base, we can tell the terminal to cherry-pick. We must use the commit ID at the bottom that we found earlier. You can copy the commit to your clipboard, and paste it in the terminal with CTRL + Shift + V.
    Code:
    git cherry-pick ab72e4ab36778474593ffce89150aece01d5f9c6

    Obviously, when cherry-picking anything else, replace “ab72e4ab36778474593ffce89150aece01d5f9c6” with the commit ID of that commit.

    Now, your terminal will do some work, and it will say it couldn't commit it automatically. It should look something like this:

    XtYoe0x.png


    Now, we get to resolve the conflicts. Continue to the next post.
    36
    Cherry-Picking from Gerrit

    Cherry Picking a feature from Gerrit

    To begin cherry-picking, you should first go to the gerrit for your desired cherry-pick and find its entry/entries. I'll cherry-pick Halo from the ParanoidAndroid gerrit into AOSP.

    Because I want Halo, I'll open go to ParanoidAndroid gerrit at http://gerrit.paranoidandroid.co and find the Halo entries. This is what it looks like:

    etbBbb4.png


    You'll notice there are two Halo entries, one titled [1/2] Settings: HALO, and one titled [2/2] Frameworks: HALO. To get this feature, I'll need both, hence the tags 1/2 and 2/2 at the beginning. Here are the links for reference:

    [1/2] Settings: HALO
    [2/2] Frameworks: HALO

    Great, now we have the entries for the two “commits” that we want to add to our ROM. We'll start with the first one. The page may look overwhelming at first, but there are two bits that are most important to us: the Project tag and the Download tab. Here's what they look like:

    4oAdKuP.png


    Look at the project title. It says “AOSPA/android_packages_apps_Settings”. This tells us exactly where in our source code to apply this commit. On my system, I have AOSP downloaded to the folder ~/AOSP. I open a terminal and enter the command “cd ~/AOSP”. Replace “AOSP” with your code directory.

    Now, in your terminal, type:
    Code:
    cd packages/apps/Settings

    Now that you're in the right spot, it's time to download the commit and try to apply it. Click the download tab in your browser, then from the dropdown choose “anonymous HTTP” and choose “cherry-pick”. Here's what it looks like:

    yz5Dqr9.png


    o6niOzT.png


    When you click the clipboard next to the “Cherry-Pick” option, it'll copy to your clipboard. Now, go back to your terminal and press CTRL + Shift + V to paste it.

    Code:
    git fetch https://gerrit.paranoidandroid.co/AOSPA/android_packages_apps_Settings refs/changes/39/239/14 && git cherry-pick FETCH_HEAD

    Chances are, unless you're very lucky, your terminal will do some work and look like this:

    BfykH1n.png


    To continue, skip to post #4
    34
    Troubleshooting/After the Cherry-Pick

    Troubleshooting/After the Cherry-Pick

    Once you've finished adding a cherry-pick, a whole variety of things can happen. You might:
    • build, and it will stop with some build erros
    • build, and it will complete, but something will go wrong when you flash it
    • want to get rid of the cherry-picks altogether

    Well, what do you do?

    If you build, and it stops building, there will be build errors. Your terminal will tell you what's wrong. Look/scroll up, and there will be something that says:
    Code:
    path/to/file/problem.java:86: some sort of error ocurred
    line.of(code, that causes); a problem {
                      ^

    The first thing it says is a file. It will be a path relative to the part it was compiling, so you might have to look for a clue above that to see where it was working on. At the end of the file is a number (in this case 86). That number tells you what line the problem is on in that file. After that, it tells you what the error was that in ran into. Then, it'll print the line that had the error with a carat (^) underneath where it had an issue.

    How do you fix it? Just open up the file with something like
    Code:
    gedit path/to/file/problem.java
    and go to line 86 and see what the problem is. Usually it's something pretty straightforward, like mismatched parentheses or a dropped semicolon. Once you've fixed the issue, save the file and build again!

    But what about if the build is successful, but it causes bugs in your build? Well, start up your phone plugged into your computer, and use this command:
    Code:
    adb logcat > errorlog
    Once the phone becomes available, your computer will start recording the logcat to the file errorlog. Once you've captured the bug, then you can disconnect your phone and reflash something stable. You can also use CTRL + C to stop the logcat command. Now, you can open the logcat with the command
    Code:
    gedit errorlog

    Reading logcats may take some getting used to. It will take quite a bit of scrolling, but the errors are probably marked with an E at the beginning of the line.

    Now, what about if you've got some issues, and you just want to scrap the cherry-picks? Well, it's pretty straightforward. Just use
    Code:
    repo sync
    and all committed cherry-picks will be wiped out and you'll be synced with the source that you're building from/

    What if you want to do a repo sync and keep that commit, you ask? Don't worry! Git is smart. It remembers how you resolved the cherry-pick. You can do a repo sync and then cherry-pick again, and it'll automatically try to apply your previous resolution. Neat, huh?

    Alternatively, you can fork the project to your own git repository (GitHub accounts are free for students!) and add that to your repo manifest. That's a whole different story, though, and will require extra research.