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

Search This thread

atharwaqas

Senior Member
Dec 7, 2007
158
39
Vernon
So i am working on CM 13 and trying to add Halo to the build. Following your guide i used gerrit to download both framework and settings package and proceed as you have said but when i do a git status i get this

both modified: core/java/com/android/internal/logging/MetricsLogger.java
both modified: packages/SystemUI/proguard.flags
both modified: packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
both modified: packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
both modified: services/core/java/com/android/server/notification/NotificationManagerService.java
both modified: services/core/java/com/android/server/notification/RankingConfig.java
both modified: services/core/java/com/android/server/notification/RankingHelper.java
 

HaoZeke

Senior Member
Aug 16, 2009
860
655
Kanpur
rgoswami.me
Redmi Note 10 Pro
So i am working on CM 13 and trying to add Halo to the build. Following your guide i used gerrit to download both framework and settings package and proceed as you have said but when i do a git status i get this

both modified: core/java/com/android/internal/logging/MetricsLogger.java
both modified: packages/SystemUI/proguard.flags
both modified: packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
both modified: packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
both modified: services/core/java/com/android/server/notification/NotificationManagerService.java
both modified: services/core/java/com/android/server/notification/RankingConfig.java
both modified: services/core/java/com/android/server/notification/RankingHelper.java
You need to resolve each files errors and add them each with git add file name.
Then you can do git cherry-pick continue.
Halo is probably not the easiest thing to start with... Try a smaller feature maybe?

---------- Post added at 11:37 AM ---------- Previous post was at 11:36 AM ----------

Hey so I have a problem / question.
I forked a repo and made a new branch...
I cloned said branch on my computer and added some cherry picks.. How do I make these changes reflect online?
 

alphamale

Senior Member
Mar 24, 2011
716
224
Massillion
Is it possible to cherry pick this to a different device using this tutorial. Or would I have to clone and or fork
 

Attachments

  • Screenshot_20170216-185440.jpg
    Screenshot_20170216-185440.jpg
    165.1 KB · Views: 207

DSA

Senior Member
May 15, 2011
4,740
5,777
if I want to bring emotionROM ROM control to LineageOS ROM for Tmobile. Is it possible to do this? There are like 100's of commit for the EmotionROM control, so I am not sure which one I should pick?

Start at the oldest/beginning. Its likely they will be the ones that are the actual rom control implementation, and the ones after will be modifications of various sorts (Of which its up to you to decide what you want).

Got a link?
 

Equals_Android

Senior Member
Mar 4, 2015
257
19
Auckland
Hi guys how would i find a commit/feature to add. For example, if i want to add the status bar ticker or something how do i search for the commit? Thanks!
 

Equals_Android

Senior Member
Mar 4, 2015
257
19
Auckland
Try using keyword searches. As long as the repo you are searching is not forked search will not work on forked git repos

Hey, where about is the search function? I've tried looking for one on gerrit and github but still not sure how to find it lol since im still very new to this.

EDIT: i've kinda of figured a way to find commits and stuff on gerrit on search bar just type "message: eg/Lockscreen chargining info"
 
Last edited:

fhem

Senior Member
Nov 4, 2013
880
1,573
Pittsburgh, PA
Hey, where about is the search function? I've tried looking for one on gerrit and github but still not sure how to find it lol since im still very new to this.

EDIT: i've kinda of figured a way to find commits and stuff on gerrit on search bar just type "message: eg/Lockscreen chargining info"

Sounds like you got gerrit --- for git you need an account and the search bar is located top middle "This repository" search.
 
  • Like
Reactions: Equals_Android

alphamale

Senior Member
Mar 24, 2011
716
224
Massillion
Wondering if someone can help. Trying to cherry pick commit i get this error.
frameworks/base/core/res/res/values/config.xml:2961: error: Resource entry config_uiBlurEnabled is already defined.
frameworks/base/core/res/res/values/config.xml:2939: Originally defined here.

Aidl: framework <= frameworks/base/core/java/android/net/IConnectivityManager.aidl
build/core/package_internal.mk:389: recipe for target '/home/android/rr/out/target/common/obj/APPS/framework-res_intermediates/package-export.apk' failed
make: *** [/home/android/rr/out/target/common/obj/APPS/framework-res_intermediates/package-export.apk] Error 1
make: *** Deleting file '/home/android/rr/out/target/common/obj/APPS/framework-res_intermediates/package-export.apk'
make: *** Waiting for unfinished jobs....
make: Leaving directory '/home/android/rr'
 

fhem

Senior Member
Nov 4, 2013
880
1,573
Pittsburgh, PA
Wondering if someone can help. Trying to cherry pick commit i get this error.
frameworks/base/core/res/res/values/config.xml:2961: error: Resource entry config_uiBlurEnabled is already defined.
frameworks/base/core/res/res/values/config.xml:2939: Originally defined here.

Aidl: framework <= frameworks/base/core/java/android/net/IConnectivityManager.aidl
build/core/package_internal.mk:389: recipe for target '/home/android/rr/out/target/common/obj/APPS/framework-res_intermediates/package-export.apk' failed
make: *** [/home/android/rr/out/target/common/obj/APPS/framework-res_intermediates/package-export.apk] Error 1
make: *** Deleting file '/home/android/rr/out/target/common/obj/APPS/framework-res_intermediates/package-export.apk'
make: *** Waiting for unfinished jobs....
make: Leaving directory '/home/android/rr'

Looks like you got "config_uiBlurEnabled" defined twice. Look at lines 2929 and 2961 of frameworks/base/core/res/res/values/config.xml then look at history of that file "config.xml"
 
  • Like
Reactions: alphamale

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.