Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,809,924 Members 45,285 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
jabza
Old
(Last edited by jabza; 27th May 2014 at 11:12 PM.)
#1  
Senior Member - OP
Thanks Meter 531
Posts: 512
Join Date: Aug 2012

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

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
Nexus 5: Personal Paranoid Android nightly build
HTC One: Paranoid Android official beta
Samsung Infuse 4g: Beanstalk
====================================
My personal nightly builds from Paranoid Android source

With Halo: Nightly folder
Without Halo: Nightly folder

Also, you can check out the thread for updates and info.
Donate Bitcoins
The Following 28 Users Say Thank You to jabza For This Useful Post: [ Click to Expand ]
 
jabza
Old
(Last edited by jabza; 28th May 2014 at 03:55 AM.)
#2  
Senior Member - OP
Thanks Meter 531
Posts: 512
Join Date: Aug 2012

 
DONATE TO ME
Default 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:



You'll notice there are two Halo entries, one titled [b][1/2] Settings: HALO[b], 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:



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:





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:



To continue, skip to post #4
Nexus 5: Personal Paranoid Android nightly build
HTC One: Paranoid Android official beta
Samsung Infuse 4g: Beanstalk
====================================
My personal nightly builds from Paranoid Android source

With Halo: Nightly folder
Without Halo: Nightly folder

Also, you can check out the thread for updates and info.
Donate Bitcoins
The Following 10 Users Say Thank You to jabza For This Useful Post: [ Click to Expand ]
 
jabza
Old
(Last edited by jabza; 26th May 2014 at 04:26 AM.)
#3  
Senior Member - OP
Thanks Meter 531
Posts: 512
Join Date: Aug 2012

 
DONATE TO ME
Default 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.



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.



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:



Now, we get to resolve the conflicts. Continue to the next post.
Nexus 5: Personal Paranoid Android nightly build
HTC One: Paranoid Android official beta
Samsung Infuse 4g: Beanstalk
====================================
My personal nightly builds from Paranoid Android source

With Halo: Nightly folder
Without Halo: Nightly folder

Also, you can check out the thread for updates and info.
Donate Bitcoins
The Following 13 Users Say Thank You to jabza For This Useful Post: [ Click to Expand ]
 
jabza
Old
(Last edited by jabza; 26th May 2014 at 04:27 AM.)
#4  
Senior Member - OP
Thanks Meter 531
Posts: 512
Join Date: Aug 2012

 
DONATE TO ME
Default 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:



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



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.
Nexus 5: Personal Paranoid Android nightly build
HTC One: Paranoid Android official beta
Samsung Infuse 4g: Beanstalk
====================================
My personal nightly builds from Paranoid Android source

With Halo: Nightly folder
Without Halo: Nightly folder

Also, you can check out the thread for updates and info.
Donate Bitcoins
The Following 16 Users Say Thank You to jabza For This Useful Post: [ Click to Expand ]
 
jabza
Old
(Last edited by jabza; 26th May 2014 at 04:42 AM.)
#5  
Senior Member - OP
Thanks Meter 531
Posts: 512
Join Date: Aug 2012

 
DONATE TO ME
Default 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.
Nexus 5: Personal Paranoid Android nightly build
HTC One: Paranoid Android official beta
Samsung Infuse 4g: Beanstalk
====================================
My personal nightly builds from Paranoid Android source

With Halo: Nightly folder
Without Halo: Nightly folder

Also, you can check out the thread for updates and info.
Donate Bitcoins
The Following 7 Users Say Thank You to jabza For This Useful Post: [ Click to Expand ]
 
Grarak
Old
#6  
Grarak's Avatar
Recognized Contributor / Developer
Thanks Meter 7,231
Posts: 2,447
Join Date: Jan 2012
Location: Vienna

 
DONATE TO ME
You should also mention how to cherry pick multiple commits
 
skull47
Old
#7  
Senior Member
Thanks Meter 143
Posts: 192
Join Date: Aug 2012
Location: Chennai
was looking for a guide like this for modding my build...gr8 guide...
AWSM !!
Device : Sony Xperia Live with Walkman (WT19i/coconut)

Current ROMs : Self Compiled PACman 4.4 ALPHA-1 and BeanStalk-4.4+ builds ....m loving 'em ...

My Beanstalk Builds for Xperia 2011 MDPI*
-------------------------------------------------------------------------------------------
PRESS THANKS IF SOMEONE HELPED U....
 
karanrajpal14
Old
#8  
Senior Member
Thanks Meter 320
Posts: 982
Join Date: Feb 2011
Location: Bangalore
Just when I decided to make some personal builds, this shows up. Thank you so much! You're awesome!

Sent from my Nexus 7 using Tapatalk
 
SleepyS40
Old
#9  
Senior Member
Thanks Meter 14
Posts: 139
Join Date: May 2010
Quote:
Originally Posted by Grarak View Post
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!
 
Walterwhite007
Old
#10  
Junior Member
Thanks Meter 0
Posts: 4
Join Date: May 2014
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

Tags
cherry pick, cherry picks, cherry-pick, gerrit, github
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes