Paranoid RPG (Repo Pleb Guide) - General Paranoid Android Discussion

This should act as a basic guide for improving your workflow while using repo/git
This takes into consideration that you already have the repo tool installed, initialized and synced.
You are still encouraged to read up on how Git actually works as this attempts to keep simple layman terms
Useful guide - http://source.android.com/source/developing.html
Basic terms
HEAD - A pointer to the current active commit (top commit of the current branch)
Branch - Alternate working path, keeps it's own history and modifications
Unstaged - Git keeps track of all file changes regardless of if they are committed or not.
This allows you to select which changes you want to commit without having to first revert your changes.
To stage a change, you'll need to execute the command git add
Staged - Once you perform git add on a modified file, it's now staged and ready for committing.
Note:
You can build and test modified files without actually staging or committing them
You however, cannot push upstream changes without first committing those changes
Basic commands:
repo start (used to create a new branch with one or more projects)
Code:
repo start branchName projectPath projectPath2 ...
git add (used to stage modified/new files)
Code:
git add pathAndFileName
git add .
git add pathAndFileName stages only the named file, while git add . will stage all unstaged files
Click to expand...
Click to collapse
git rm (used to stage deleted files)
Code:
git rm pathAndFileName
git add -u
git rm pathAndFileName stages only the named file (to be deleted), while git add -u will stage all unstaged files that are to be deleted
Click to expand...
Click to collapse
git diff (used to compare file changes, shows the diff between HEAD and the current project state)
Code:
git diff
git diff fileName
When diff is executed, if a file is not specified, it shows the difference between all files changed
The file being compared is shown at the top of the analysis, followed by it's differences
Example: diff --git a/AndroidManifest.xml b/AndroidManifest.xml
Click to expand...
Click to collapse
Deleted lines start with a minus (-) sign
New lines start with a plus (+) sign
Lines starting with @@ are simply line numbers within the file
Example: changing one line in AndroidManifest.xml
Code:
[B]diff --git a/AndroidManifest.xml b/AndroidManifest.xml[/B]
index e5ce889..5b8c41e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
[COLOR="RoyalBlue"]@@ -1581,7 +1581,7 @@[/COLOR]
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.app.action.START_ENCRYPTION" />
[COLOR="Red"]- <category android:name="android.intent.category.DEFAULT" /> />[/COLOR]
[COLOR="SeaGreen"]+ <category android:name="android.intent.category.DEFAULT" />[/COLOR]
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
git status (shows the status of modified files, staged or unstaged)
Code:
git status -s
git commit (commits your staged files to the working directory)
Code:
git commit -a
git commit -m [message]
git commit --amend
commit -a
This should be your standard for creating commit messages. Allows for multi-line entry for well formatted commit messages
commit -m 'commitMessage'
This is essentially a short-cut that allows you to enter a quick commit message
commit --amend
Allows you to amend the commit. It can be used simply to update the commit message or to include new files in a previous commit instead of creating a brand new commit.
Click to expand...
Click to collapse
git remote (create a link to another repository for easy referrence)
Code:
git remote add remoteAlias remotePath
Example: git remote add Google [url]https://android.googlesource.com/platform/frameworks/base.git[/url]
git fetch (update your local copy of a remote branch, does not affect your working directory)
Code:
git fetch remoteAlias -branch
git pull (brings your repository up to date with a remote repository. Updates your working directory)
Code:
git pull remoteAlias - branch
git cherry-pick (fetches and merges files from a remote repository into your local repository)
Code:
git cherry-pick SHA
git log (lists all commits/commit history on your current branch)
Code:
git log
Recommended workflow
- repo sync
- Create branch (repo start) <or use previously created branch>
- Do some programming/cherry-picking
- git status to see what changed
- git diff [file] to see exactly what was modified
- git add [all or selected] file(s)
- git commit -a | -m [message] | --amend to commit
Click to expand...
Click to collapse
Notes on repo syncing
Repo sync pulls in all changes from the remote repository defined in your local manifest
and update your working directory to match the state of said repository.
Firstly, git will not overwrite any commit, so don't worry about that.
However, there are two ways that repo sync handles the upstream updates.
If you work on an unnamed or non-tracking branch, repo sync leaves your HEAD and switches to the tip of the branch specified in the manifest. This makes it appear as though your changes were deleted.
If you are on a tracking branch, repo sync will rebase your commits on top of the branch tip, after updating your working directory.
(i.e., re-apply your changes after the upstream updates so you now have updated remote files plus your own commits)
Recommendation: you should create a tracking branch before committing. This does not mean every time you want to commit you should start a new branch, but, for better workflow you should have at least one main tracked branch. For testing various new features/cherry-picks its best to branch first before committing.
repo start my_branch frameworks/base
Notes on repo start
- You are automatically switched to the new branch (for the specified projects only) once repo start branch is executed.
- New branches are created based on the HEAD of the remote repo in your manifest.
- Projects not specified for the new branch (in the repo start command) will remain on their current branch.
Example: You have commits on branch 1 and you decide to create branch 2
branch1 contains
ProjectA
ProjectB
ProjectC
repo start branch2 ProjectA ProjectC
Your build environment will now contain
branch2/ProjectA
branch1/ProjectB
branch2/ProjectC
Click to expand...
Click to collapse
This is important to note because if changes present in branch1/ProjectB depend on code in branch1/ProjectA or branch1/ProjectC you will run into errors if branch2/(projectA or ProjectC) does not contain those required changes. To avoid this, simply repo start branch2/ProjectB as well, even if you don't intend to make changes to this project on your new branch. Of course, if there are no dependencies, there is no need to branch additional projects.
- Other projects can be added to an existing branch by simply running repo start again and using the existing branch name
- If you create a tracking branch, repo sync will rebase it automatically. So you don't have to do it by hand.
Notes on cherry-picking
Manual
git fetch remoteBranch
git cherry-pick commit_SHA
Automatic
login to gerrit
click the downloads tab
copy & paste cherry-pick link into the appropriate project path in terminal
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Regardless of the method used, cherry-picking a commit will not always result in a clean merge.
If there is a conflict you will see a message similar to Prerecorded image for...
A bad merge does not mean bad code. It simply means your working directory is not at the same point
as the working directory used for the commit you are attempting to pick. This may be because you are
picking a commit from one ROM to another or the working directory was updated since the commit was
uploaded to gerrit
Conflicts must be cleared manually.
The simplest conflicts would present as merge tags
<<<<<<HEAD
=========
>>>>>>> commitMessage
Click to expand...
Click to collapse
This is not the only thing you should look out for however, there may also be
-- Duplicated or deleted lines of code/resources
-- Unnecessary resources
-- Missing resources
Use git diff to see which files conflict and again to see the changes in those files. Of course you have to actually open those files and make your edits/fixes. Once edidted, simply commit the changes to the existing cherry-picked commit
git status
git add <changed files>
git commit (Opens the cherry-pick commit message)
Save ... and you're done
Click to expand...
Click to collapse

Reserved

Reserved...

Thanks a lot! could you elaborate on the git diff function? as I am trying to build PA4+ w/ halo and cherry picking the 1st and 2nd part i figured out but the git diff function shows some syntaxes I don't follow as I have no background in coding but I want to learn!

steijn0 said:
Thanks a lot! could you elaborate on the git diff function? as I am trying to build PA4+ w/ halo and cherry picking the 1st and 2nd part i figured out but the git diff function shows some syntaxes I don't follow as I have no background in coding but I want to learn!
Click to expand...
Click to collapse
I've modified the OP with a few more details on diff.

Thanks for this! Looking forward, someday I will use this.

Related

[GUIDE][ICS] Compile Cyanogenmod 9 on Mac OS X Lion

There are a lot of toturials for building CM9 on ubuntu or CM7 on Mac but I couldn't find a decent toturial for building CM9 on Mac (specially Lion). Development in AOSP/CM land is rapid and guides frequently need updating. I had to spend a little time to figure everything out and I decided to share it here.
This tutorial is for building CM9 (ICS) for Galaxy Nexus GSM (maguro) on Mac OS X Lion 10.7.3 using Xcode 4.3 and homebrew . You can easily make the instructions work for most other cm9 devices, but I wouldn't know anything about that.
DISCLAIMER: I'm not responsible if you blow yourself up, blah blah blah
However, I've tried to make this as noob friendly as possible because, well I'm a noob myself
Instrunctions:
UPADTE (MAY 29TH) : The Xcode 4.3 default compiler (llvm-gcc) used to be incompatible with CM9. Thanks to jocelyn and topprospect, the LLVM compatibility patches from mainline AOSP are now merged into CM9. Therefore, you can now use Xcode 4.3 and its command line tools without installing another compiler. However, since GCC is still the only officially supported compiler, incompatibilites with llvm-gcc could still be introduced with future updates. Therefore, if your build fails, it might be worth it to try installing and compiling with GCC 4.2. See the Troubleshooting section for more info.
Now that we have Xcode 4.3 and Xcode command line tools (CLT) installed, let's continue.
Open Terminal and run
Code:
java
if you don't have Java, you will get a prompt asking you to download and install Java. Go ahead and install it.
If you don't have adb and fastboot working, download the android-sdk from google (version r18 as of now) and put it in /usr/local/ and rename the folder to "android-sdk".
Install the homebrew package manager
Code:
/usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
To make sure that homebrew and android-sdk executables are in $PATH:
Code:
touch ~/.bash_profile && echo "PATH=/usr/local/bin:/usr/local/sbin:$PATH:/usr/local/android-sdk/tools:/usr/local/android-sdk/platform-tools" >> ~/.bash_profile
Relaunch Terminal for the change to take effect.
At this point you can run
Code:
brew doctor
to detect any problems there might be (Homebrew may instruct you to use the xcode-select utility to select the xcode installation path). Hopefully, your system is raring to brew
Now we have to install a bunch of packages:
Code:
brew install git coreutils findutils gnu-sed gnupg pngcrush repo
We now need to create a couple of symlinks so that the gnu versions of 'sed' and 'find' are used rather than the osx provided versions :
Code:
ln -s /usr/local/bin/gfind /usr/local/bin/find && ln -s /usr/local/bin/gsed /usr/local/bin/sed && ln -s /usr/local/bin/gstat /usr/local/bin/stat
It's time to create a case sensitive image which will hold our working directory:
Code:
hdiutil create -type SPARSE -fs "Case-sensitive Journaled HFS+" -size 40g -volname "android" -attach ~/Desktop/Android
Now we have a disk image in ~/Desktop/Android. Mount it if it's not mounted already. (Don't be picky about the size, the image will only take as much as space as its contents).
Now we need to create a working directory inside the mounted volume:
Code:
cd /Volumes/android && mkdir cm9 && cd cm9
We can initialize and download the source now:
Code:
repo init -u git://github.com/CyanogenMod/android.git -b ics && repo sync && say 'finished'
Now we need to get the required proprietry files for our device. We can get these from the device itself. Connect your phone (make sure USB Debugging is enabled) and run the following (for maguro):
Code:
cd /Volumes/android/cm9/device/samsung/maguro/ && ./extract-files.sh
[If you see errors in the output from extract-files.sh, see the Troubleshooting section below]
For Google devices,we can also get them directly from google. For maguro, download the 3 files and extract them to /Volumes/android/cm9. Then,
Code:
cd /Volumes/android/cm9
/Volumes/android/cm9/extract-broadcom-maguro.sh
/Volumes/android/cm9/extract-imgtec-maguro.sh
/Volumes/android/cm9/extract-samsung-maguro.sh
We also need the prebuilts (like ROM manager and Term.apk):
Code:
/Volumes/android/cm9/vendor/cm/get-prebuilts
You can optionally tell the build to use the ccache tool. CCache acts as a compiler cache that can be used to speed-up rebuilds :
Code:
export USE_CCACHE=1 && /Volumes/android/cm9/prebuilt/darwin-x86/ccache/ccache -M 20G
Default is 1GB. Anything between 20GB-50GB should be fine.
Before starting the build, we need to workaround an issue with Lion and compiling the QEMU emulator.
[This step doesn't seem to be needed anymore. QEMU is automatically ignored on OS X/Darwin]
If you build now, you're probably gonna get kernel build errors regarding the missing elf.h header (this error might be device specific). Fortunately, we already have this file downloaded, so we only need to copy it to /usr/local/include:
Code:
cp /Volumes/android/cm9/external/elfutils/libelf/elf.h /usr/local/include
FINALLY, we are ready to build:
Code:
cd /Volumes/android/cm9 && source build/envsetup.sh && brunch
Pick your device from the list and enter the number. For maguro, you could use "brunch maguro" instead and skip the menu. Depending on your system, this will take 30min-4hours.
You should now see a beautiful zip file waiting to be flashed:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
​Troubleshooting:
The extract script for maguro seems to be a little outdated, as it doesn't pull the gps proprietary blob. You can either use the google provided scripts, or add koush's git repository for your device to your local_manifest.xml.
As explained above, the CM9 source is currently compatible with llvm-gcc. In the future, if llvm-gcc fails to build correctly, you should try installing and compiling using GCC4.2 (the Xcode 3 compiler). You can install apple-gcc4.2 from homebrew:
Code:
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb
This version of gcc can happily coexist with Xcode 4.x .
So now you have GCC 4.2 installed, but it won't be used unless we update the corresposing environment variables:
Code:
export CC=/usr/local/bin/gcc-4.2 && export CXX=/usr/local/bin/g++-4.2
Notice that using the export command is temporary. If you relaunch Terminal, you will need to set these again. However, this is a good thing, because changing these values permanently (by putting them in ~/.bash_profile) can interfere with other builds.
If you use this method, the build might fail while compiling "external/zlib/x86/adler32.c". It appears that a recent change in zlib has introduced an incompatibility with gcc 4.2. you have to revert the following 2 commits:
Code:
cd external/zlib
git revert dd6786cae3f4493faa6661d5f74db587932f15d7
git revert 13bf40af68236c961542bdee1d4b7c0176bf15a0
Alternatively, you can add topprospect's zlib on github (which has those commits reverted) to your local_manifast.xml. Simply run:
Code:
nano /Volumes/android/cm9/.repo/local_manifest.xml
and add the following line
Code:
<project name="dferg/android_external_zlib" path="external/zlib" remote="github" />
If you get a build error, and your error is not covered here, copy the last 20-30 lines of the build output AND the output from the following command into pastebin and post the link. Hopefully me or someone else will help you.
Code:
echo -e "\nENV:\n$(env)\n\nWHICH GCC\n:$(which gcc)\n\nWHICH G++:\n$(which g++)\n\nWHICH CC:\n$(which cc)\n\nWHICH C++:\n$(which c++)\n\nBREW DOCTOR:\n$(brew doctor)\n\nBREW LIST:\n$(brew list)\n\n/USR/BIN:\n$(ls -l /usr/bin | grep gcc)\n\n/USR/LOCAL/BIN:\n$(ls -l /usr/local/bin | grep gcc)\n\n"
​Notes/Extras:
To quickly setup your environment, add an alias like the following to ~/.bash_profile:
Code:
alias cm9env="hdiutil attach PATH-TO-DISK-IMAGE -mountpoint /Volumes/android && cd /Volumes/android/cm9 && source ./build/envsetup.sh && export USE_CCACHE=1"
alias cm9build="cm9env && make clobber && reposync && brunch maguro"
Now you can save time by using "cm9env" to get your environment setup or "cm9build" to compile a clean updated build.
To clear your output directory for a new build, run "make clobber". You probably don't need this if you've only changed a few lines of code.
To cherry pick yet-to-be-merged changes from the gerrit instance:
1. Pick an open commit from CM Gerrit
2. Under list of Patch Sets pick the latest and open cherry-pick tab
3. Check what Git repository the url is pointing e.g. http://review.cyanog...frameworks_base
4. In your CM9 working tree go to the corresponding directory, which in this case is something like ~/your-working-directory/frameworks/base/
5. Now simply paste the whole line seen in CM Gerrit cherry-pick tab e.g. "git fetch http://review.cyanog....rameworks_base refs/changes/00/13100/4 && git cherry-pick FETCH_HEAD"
It should be now included in your next compiled build. When doing repo sync again, cherry picks will be lost.[CREDIT Fihlvein from xda]
Click to expand...
Click to collapse
Enjoy your custom built CM9!
I updated OP with some updated info about Xcode 4.3.
Nice work man. Very helpful.
conantroutman said:
Nice work man. Very helpful.
Click to expand...
Click to collapse
thanks! I'll try to keep this topic updated as issues with mac are introduced/resolved.
Nice write up. Thanks.
Before I start again from scratch I have a question. Does this guide apply to previous versions of mac os x (mine is 10.6.8)? I used the official android initializing build environment page & cm7 wiki page for the instructions to setup my build environment.
Also, any tips to switch from macports to homebrew?
In the past I've had to cherry pick to get my OS X build environment set up for CM9. The compile from source fails because I started with macports instead of homebrew (bad idea). I tried to switch to homebrew without success. Any tips to switch from macports to homebrew?
For the sake of keeping this page on topic a pm response is ok if that is what you prefer.
Hi thanks for this !! Helpful one question what do i change so i can do AOSP instead of cm9??
grad061980 said:
Nice write up. Thanks.
Before I start again from scratch I have a question. Does this guide apply to previous versions of mac os x (mine is 10.6.8)? I used the official android initializing build environment page & cm7 wiki page for the instructions to setup my build environment.
Also, any tips to switch from macports to homebrew?
In the past I've had to cherry pick to get my OS X build environment set up for CM9. The compile from source fails because I started with macports instead of homebrew (bad idea). I tried to switch to homebrew without success. Any tips to switch from macports to homebrew?
For the sake of keeping this page on topic a pm response is ok if that is what you prefer.
Click to expand...
Click to collapse
Yes, this guide should work fine on Snow Leopard. It mostly depends on your Xcode version. If you have Xcode 3, you can skip step 1 entirely, since you already have gcc4.2 as part of Xcode.
If you have access to Xcode 4.2 and above, you will need to install gcc4.2 separately, as explained in the guide.
Now regarding Macports, I strongly suggest that you completely uninstall Macports before installing homebrew. Instructions are here: http://guide.macports.org/chunked/installing.macports.uninstalling.html
WonkyYew said:
Hi thanks for this !! Helpful one question what do i change so i can do AOSP instead of cm9??
Click to expand...
Click to collapse
Full instructions are available on android.com : http://source.android.com/source/initializing.html
If you are using this guide, you need to change the repo initialization command to :
Code:
repo init -u https://android.googlesource.com/platform/manifest
and then do repo sync. You can setup ccache as usual. I don't think AOSP has the "brunch command", so you have to use launch and then make.
Run "lunch" and select an option from the menu. You can find more info about the options here: http://source.android.com/source/building.html. For maguro, you should use "full_maguro-userdebug".
To start the build, use
Code:
make -j$(sysctl -n hw.ncpu)
@ArmanUV. Sounds good & thanks for the input. I'll give the link to macports uninstall a go.
Im a real noob, whats the advantage of compiling from source?
Thanks for the help man !
Hi, thanks for your guide, setting up the repo was no problem at all!
But: I'm getting the following error when building.
Code:
external/zlib/x86/adler32.c: In function ‘adler32_MMX’:
external/zlib/x86/adler32.c:747: error: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
external/zlib/x86/adler32.c:747: error: ‘asm’ operand has impossible constraints
make: *** [out/host/darwin-x86/obj/STATIC_LIBRARIES/libz_intermediates/adler32.o] Error 1
make: *** Waiting for unfinished jobs....
Seems to be a problem with the compiler, but I'm on xcode 4.3 and I've installed gcc-4.2 and set the env vars. Any help?
ArmanUV,
Thanks so much for posting this guide. Very helpful!
Are you having any trouble with errors like this?
Code:
external/zlib/x86/adler32.c: In function ‘adler32_MMX’:
external/zlib/x86/adler32.c:747: error: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
external/zlib/x86/adler32.c:747: error: ‘asm’ operand has impossible constraints
Googling for this error implies that the fix is to use a version of GCC > 4.2. But there does not seem to be a GCC 4.4 in Homebrew.
Thanks again for the guide!
EDIT: Sorry for the double post with empyyy. Seems like there is someone else having my same issue!
topprospect said:
ArmanUV,
Thanks so much for posting this guide. Very helpful!
Are you having any trouble with errors like this?
Code:
external/zlib/x86/adler32.c: In function ‘adler32_MMX’:
external/zlib/x86/adler32.c:747: error: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
external/zlib/x86/adler32.c:747: error: ‘asm’ operand has impossible constraints
Googling for this error implies that the fix is to use a version of GCC > 4.2. But there does not seem to be a GCC 4.4 in Homebrew.
Thanks again for the guide!
EDIT: Sorry for the double post with empyyy. Seems like there is someone else having my same issue!
Click to expand...
Click to collapse
empyyy said:
Hi, thanks for your guide, setting up the repo was no problem at all!
But: I'm getting the following error when building.
Code:
external/zlib/x86/adler32.c: In function ‘adler32_MMX’:
external/zlib/x86/adler32.c:747: error: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
external/zlib/x86/adler32.c:747: error: ‘asm’ operand has impossible constraints
make: *** [out/host/darwin-x86/obj/STATIC_LIBRARIES/libz_intermediates/adler32.o] Error 1
make: *** Waiting for unfinished jobs....
Seems to be a problem with the compiler, but I'm on xcode 4.3 and I've installed gcc-4.2 and set the env vars. Any help?
Click to expand...
Click to collapse
You guys seem to have the same issue. What sort of Xcode configuration are you using? Can you post the output from "which gcc","which g++", "gcc -v", "g++ -v" and "cc -v"?
ArmanUV said:
You guys seem to have the same issue. What sort of Xcode configuration are you using? Can you post the output from "which gcc","which g++", "gcc -v", "g++ -v" and "cc -v"?
Click to expand...
Click to collapse
I am on Lion 10.7.4 with Xcode 4.3.2. Here is the output that you asked for:
Code:
# echo -n "which gcc: "; which gcc; echo -n "which g++: "; which g++; echo ""; echo "gcc -v:"; gcc -v; echo ""; echo "g++ -v:"; g++ -v; echo ""; echo "cc -v:"; cc -v
which gcc: /usr/bin/gcc
which g++: /usr/bin/g++
gcc -v:
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)
g++ -v:
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)
cc -v:
Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.3.0
Thread model: posix
They are pointing to LLVM, but my CC and CXX variables point to:
Code:
env|grep 4.2
CXX=/usr/local/bin/g++-4.2
CC=/usr/local/bin/gcc-4.2
Do I need to add something to PATH? I'm sure I just missed something obvious in your instructions.. Thanks for helping!
topprospect said:
I am on Lion 10.7.4 with Xcode 4.3.2. Here is the output that you asked for:
Do I need to add something to PATH? I'm sure I just missed something obvious in your instructions.. Thanks for helping!
Click to expand...
Click to collapse
Everything checks out. I'm away from my main machine so I can't run a test build, but I suspect that a recent change is causing problems.
Now, regarding the compiler, Setting CC/CXX *should* take care of everything, but I am currently not 100% sure that somewhere in a makefile, these environment variables aren't being ignored. Since I wrote the guide, I noticed a lot of clang warnings in the build, which means that CC/CXX is not honored and /usr/bin/cc and /usr/bin/c++ is being used.
A more robust method of making sure gcc-4.2 is being used is creating symlinks to gcc-4.2 and g++-4.2 :
Code:
ln -s /usr/local/bin/gcc-4.2 /usr/local/bin/gcc
ln -s /usr/local/bin/gcc-4.2 /usr/local/bin/cc
ln -s /usr/local/bin/g++-4.2 /usr/local/bin/c++
ln -s /usr/local/bin/g++-4.2 /usr/local/bin/g++
Obviousely, a systemic method like this has its downsides but it may be the only choice without having to change CM code (especially since I lack the knowledge to do so )
[I recently found out that master aosp is no longer using CC/CXX to find the compiler (see ./build/core/combo/). Instead, it uses "gcc" and "g++" directly, which means that llvm-gcc will be used no matter what env variable you have. Fortunately, unlike cm9, master aosp is supposed to build fine with llvm-gcc (except for qemu, which doesn't matter for device images). ]
ArmanUV said:
Everything checks out. I'm away from my main machine so I can't run a test build, but I suspect that a recent change is causing problems.
Now, regarding the compiler, Setting CC/CXX *should* take care of everything, but I am currently not 100% sure that somewhere in a makefile, these environment variables aren't being ignored. Since I wrote the guide, I noticed a lot of clang warnings in the build, which means that CC/CXX is not honored and /usr/bin/cc and /usr/bin/c++ is being used.
A more robust method of making sure gcc-4.2 is being used is creating symlinks to gcc-4.2 and g++-4.2 :
Code:
ln -s /usr/local/bin/gcc-4.2 /usr/local/bin/gcc
ln -s /usr/local/bin/gcc-4.2 /usr/local/bin/cc
ln -s /usr/local/bin/g++-4.2 /usr/local/bin/c++
ln -s /usr/local/bin/g++-4.2 /usr/local/bin/g++
Click to expand...
Click to collapse
Okay, just tried this. I created a new dir (/Volumes/Android/bin) that simply houses those softlinks you recommended. Then I put /Volumes/Android/bin at the beginning of my PATH. That should fix it without breaking the rest of the system, e.g. homebrew.
The GENERAL_REGS problem still exists though. Pretty sure b/c gcc 4.2.1 doesn't understand this construct properly (need a newer version of gcc).
So I backed out the change that introduced this adler32.c.
https://github.com/CyanogenMod/android_external_zlib/commit/13bf40af68236c961542bdee1d4b7c0176bf15a0
The compile is getting farther now. I have to run to work so I'll post later if it succeeds.
The weird thing is: This change was made back in December. Why would it have worked for you?
topprospect said:
The compile is getting farther now. I have to run to work so I'll post later if it succeeds.
Click to expand...
Click to collapse
Build works (and boots!) with the following:
Code:
cd external/zlib
git revert dd6786cae3f4493faa6661d5f74db587932f15d7
git revert 13bf40af68236c961542bdee1d4b7c0176bf15a0
Note the 1st revert is just to avoid massive conflicts seen when reverting the 2nd one by itself. The 2nd revert is the one that really matters here.
So this isn't really a solution.. Seems like we need to move to a newer version of gcc or figure out a patch to adler32.c that makes it gcc 4.2 compatible.
topprospect said:
Build works (and boots!) with the following:
Code:
cd external/zlib
git revert dd6786cae3f4493faa6661d5f74db587932f15d7
git revert 13bf40af68236c961542bdee1d4b7c0176bf15a0
Click to expand...
Click to collapse
The first revert works fine, however the second one gives me the following error:
Code:
$ git revert 13bf40af68236c961542bdee1d4b7c0176bf15a0
error: could not revert 13bf40a... Implement vectorized adler32 and optimized slhash
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
error: Could not parse conflict hunks in zlib.h
empyyy said:
The first revert works fine, however the second one gives me the following error:
Code:
$ git revert 13bf40af68236c961542bdee1d4b7c0176bf15a0
error: could not revert 13bf40a... Implement vectorized adler32 and optimized slhash
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
error: Could not parse conflict hunks in zlib.h
Click to expand...
Click to collapse
Well, run git status. You'll see that the only conflict is in the comments in zlib.h. So, you can just ignore it.
topprospect said:
Okay, just tried this. I created a new dir (/Volumes/Android/bin) that simply houses those softlinks you recommended. Then I put /Volumes/Android/bin at the beginning of my PATH. That should fix it without breaking the rest of the system, e.g. homebrew.
The GENERAL_REGS problem still exists though. Pretty sure b/c gcc 4.2.1 doesn't understand this construct properly (need a newer version of gcc).
So I backed out the change that introduced this adler32.c.
https://github.com/CyanogenMod/android_external_zlib/commit/13bf40af68236c961542bdee1d4b7c0176bf15a0
The compile is getting farther now. I have to run to work so I'll post later if it succeeds.
The weird thing is: This change was made back in December. Why would it have worked for you?
Click to expand...
Click to collapse
topprospect said:
Build works (and boots!) with the following:
Code:
cd external/zlib
git revert dd6786cae3f4493faa6661d5f74db587932f15d7
git revert 13bf40af68236c961542bdee1d4b7c0176bf15a0
Note the 1st revert is just to avoid massive conflicts seen when reverting the 2nd one by itself. The 2nd revert is the one that really matters here.
So this isn't really a solution.. Seems like we need to move to a newer version of gcc or figure out a patch to adler32.c that makes it gcc 4.2 compatible.
Click to expand...
Click to collapse
Nice find. I tried to compile this morning and I ran into the same issue. This is what I don't understand: I did a couple of builds about a week ago without running into this issue. But, the latest commits on zlib are from 2 months ago.
Amazingly, the Xcode 4.3 toolchain (clang and llvm-gcc) builds this external/zlib/adler32.c just fine.
An alternative to this problem is to install an up to date gcc 4.7 :
Code:
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/gcc.rb
and then create symlinks to gcc-4.7/g++-4.7. I have not tested this yet.

Using Git in an unusual workflow

Hi people, this is my first post here, I think is the best place where I can discuss my programming issues. If this post isn't in the correct place, please move it and forgive my dumbness.
I'm working in some personal projects, android apps, in my house. There I have my PC with Eclipse and Git, at the end of the weekend I'm always commiting changes and uploading them to GitHub. When I go to my office, sometimes I have some spare time and I open Eclipse to start working, but of course I synchronize the GitHub repository data with my local data (in order to work with the latest changes I've made in my house), but I'm always having troubles with this action: I don't know how to discard my local old files, keep the files that haven't been modified and download the latest version of my modified files. I always end deleting the folder and cloning the repo again because I mess the files... I'm sure there is a better way.
So, I'd be delighted if you could assist me on how should I work with this feature of Git. I'd like too to take advice to improve my workflow. I've checked lots of sites and tutorials about Git but I haven't been able to get useful info to match with my workflow...
Thank you in advance
kyomuga said:
Hi people, this is my first post here, I think is the best place where I can discuss my programming issues. If this post isn't in the correct place, please move it and forgive my dumbness.
I'm working in some personal projects, android apps, in my house. There I have my PC with Eclipse and Git, at the end of the weekend I'm always commiting changes and uploading them to GitHub. When I go to my office, sometimes I have some spare time and I open Eclipse to start working, but of course I synchronize the GitHub repository data with my local data (in order to work with the latest changes I've made in my house), but I'm always having troubles with this action: I don't know how to discard my local old files, keep the files that haven't been modified and download the latest version of my modified files. I always end deleting the folder and cloning the repo again because I mess the files... I'm sure there is a better way.
So, I'd be delighted if you could assist me on how should I work with this feature of Git. I'd like too to take advice to improve my workflow. I've checked lots of sites and tutorials about Git but I haven't been able to get useful info to match with my workflow...
Thank you in advance
Click to expand...
Click to collapse
Hi, this should be the right section for talking git, don't worry
My understanding is that you have some local (uncommited) changes on your machine at work, and you want to pull the latest commits from your distant repository while avoiding merge conflicts, is that correct ?
If it is, then you have several solutions at your disposal:
The easiest and cleanest way is to stash your local changes, pull the new commits and then pop the stashed changes to commit them over the up-to-date repo later on:
(replace <remote> and <branch> with your actual remote and target branch, for example git pull origin master)
Code:
git stash
git pull <remote> <branch>
git stash pop
The branch is now up to date and your local changes are still there for you to commit or to continue modifying.
If instead you decide that you don't need the local changes you stashed anymore, instead of popping them you can clear the stash:
Code:
git stash clear
If you want to fetch remote changes for all the branches, replace the git pull with:
Code:
git fetch <remote>
If all you want is to get rid of your local changes and sync with upstream repo, you can use:
Code:
git checkout .
git pull <remote> <branch>
Hope this helps, let me know if you need further help, or if I didn't understand your question properly :silly:
Androguide.fr said:
If all you want is to get rid of your local changes and sync with upstream repo, you can use:
Code:
git checkout .
git pull <remote> <branch>
Click to expand...
Click to collapse
Thank you very much. This is what I need, or at least what fits best with my workflow, as I'm always starting programming from the point i've stopped working in another place, being like this:
When I get to work:
Code:
git checkout .
git pull <remote> <branch>
So I'm getting my updated code as I stopped programming at home
Minutes after going home:
Code:
git add .
git commit -m "another day, another commit"
git push origin master
When I get home:
Code:
git checkout .
git pull <remote> <branch>
So I'm getting my updated code as I stopped programming at work
Minutes after going to bed:
Code:
git add .
git commit -m "another day, another commit"
git push origin master
This is a correct workflow? or I'm misusing the benefits of Git?
kyomuga said:
Thank you very much. This is what I need, or at least what fits best with my workflow, as I'm always starting programming from the point i've stopped working in another place, being like this:
When I get to work:
Code:
git checkout .
git pull <remote> <branch>
So I'm getting my updated code as I stopped programming at home
Minutes after going home:
Code:
git add .
git commit -m "another day, another commit"
git push origin master
When I get home:
Code:
git checkout .
git pull <remote> <branch>
So I'm getting my updated code as I stopped programming at work
Minutes after going to bed:
Code:
git add .
git commit -m "another day, another commit"
git push origin master
This is a correct workflow? or I'm misusing the benefits of Git?
Click to expand...
Click to collapse
Yeah, this looks correct, as long as you don't need your local changes this is probably the best way.

[Guide][9/3/2015] Building CM12 for the Nexus 6 Shamu

Building CM12 from source for the Nexus 6 Shamu!
Thanks goes to @scrosler and @GROGG88 and @sykopompos for their amazing guide
[Guide][1/19/2015] Buulding AOSP for the Nexus 6!​
This guide will walk you through, how to build CM12 for the Nexus 6 from source. To complete this, you will need a PC with either virtual box setup and Ubuntu or duel boot Windows and Ubuntu. I recommend duel booting as it gets better results.​
Ideally your PC will need a minimum of an I5 processor and 8GB of ram. I won't go into too much detail on how to setup Ubuntu on your PC. For this guide, you do need to know the basic commands and how to use Ubuntu.
This guide is very similar in process to @scrosler and @GROGG88 and @sykopompos amazing guide here: [Guide][1/19/2015] Building AOSP for the Nexus 6! Through the use of their guide and asking a lot of questions on their thread, I was able to learn how to build AOSP from source. My guide is to complement their guide and show you how to build CM12, I found switching from AOSP to CM12 fairly easy, but there were a few changes in the process.
For my guide I will be using CM12 build guide as reference for the commands. How To Build CyanogenMod Android for Google Nexus 6 ("shamu") Even their guide is not 100% up to date, so I had to make a few changes.
Disclaimer:
I am not responsible for any damage done to your device, thermal nuclear war etc. Please use at your own risk. Your warranty may be affected if you install a custom rom. I am also not responsible if you go over your payment plan when downloading the source code. It is large over 16gb so be careful!
Click to expand...
Click to collapse
So assuming you have Ubuntu 14.* set up, you will need to now set up your build environment:
First on their guide it talks about installing the SDK tools. You do not need these to build the ROM. You only really need ADB commands. I installed fastboot as well.
Install ADB command
Code:
sudo apt-get install android-tools-adb
Install Fastboot command
Code:
sudo apt-get install android-tools-fastboot
Install Java
Code:
sudo apt-get install openjdk-7-jdk
Setting up the build enviroment
Code:
bison build-essential curl flex git gnupg gperf libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 libxml2-utils lzop openjdk-6-jdk openjdk-6-jre pngcrush schedtool squashfs-tools xsltproc zip zlib1g-dev
If you have a 64bit PC install the following:
Code:
g++-multilib gcc-multilib lib32ncurses5-dev lib32readline-gplv2-dev lib32z1-dev
Setting your build directory - This can be any folder you want. for my example I will use android as my root folder. Remember that Ubuntu is case sensitive when switching folders.
Code:
mkdir -p ~/bin
mkdir -p ~/android
Install Repo
Code:
curl [URL]https://storage.googleapis.com/git-repo-downloads/repo[/URL] > ~/bin/repo
chmod a+x ~/bin/repo
Put the ~/bin directory in your path of execution - In recent versions of Ubuntu, ~/bin should already be in your PATH. You can check this by opening ~/.profile with a text editor and verifying the following code exists (add it if it is missing):
Code:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
Now for the good bit! We are about to download the source for cm12. Warning: The download is large and will take a long time to download. I have a 38mb fiber connection and unlimited data plan, so it is ok for me to download. I believe the download is 16gb+ in size, so you will have to take this into consideration. Note: I will not be held responsible if you go over your payment plan with your service provider. This is were I have had to start changing the guide a bit as CM's document is for building CM11. It has not been updated to CM12 yet.
Identify Yourself to the Repo
Code:
git config --global user.email "[email protected]"
git config --global user.name "yourpreferredusername"
Initialize the CyanogenMod source repository
Code:
cd ~/android [B]- this is your root folder[/B]
repo init -u [URL]https://github.com/CyanogenMod/android.git[/URL] -b cm-12.0
Download the source code - Note this will take a while, as mentioned it is over 16gb in size. Even with my connection it takes about an hour and a half to download, so time for coffee!
Code:
repo sync
If repo sync errors and stops during download, don't worry you can simply run the command again and it will pick up were it left off. If you get a lot of errors during download, I recommend using
Code:
repo sync -j1
This seems to download the source better. When you have completed the download run it again, to make sure it completes with out any errors. This way you know you have downloaded the full source code.
Backup your home directory
Also at this point, what I do is make a backup using the inbuilt backup software in ubuntu. This backs up my entire home directory to a secondary hard drive I have set up in my PC. This way if I have any issues and need to start from scratch, I can simply delete my android directory, then restore from backup. I then have a fresh working copy and don't have to spend time downloading source from CM12 again. I would also recommend this as part of scrosler's guide as well, when you have finished downloading AOSP source.
Vendor and device specific files
Now this is were the cm12 guide starts to differ a bit from AOSP. AOSP you have to download the vendor files and extract them and then add in missing ones as well. CM12 differs here. At this point I would recommend having CM12 on your Nexus 6. It uses ADB to pull files from your phone and set up the device specific files and the vendor files. I found having CM12 on the phone made life easier at this point. You can use my ROM as an example here: [ROM][5.0.2][CM12 - Android L][LRX22G] Version 1.0.0 - [8/03/2015] - Native LED's
Code:
cd ~/android
source build/envsetup.sh
breakfast shamu
Extract proprietary blobs
Now ensure that your Nexus 6 is connected to your computer via the USB cable and that you are in the ~/android/device/moto/shamu directory, then run the extract-files.sh script
Code:
cd ~/android/device/moto/shamu
./extract-files.sh
Turn on caching to speed up build
You can speed up subsequent builds by adding: the following command to your to your .bashrc file To do this close your terminal window and then reopen and type ./.bashrc - A text editor will open. Add this line to the bottom of the page.
Code:
export USE_CCACHE=1
Close the text editor and save the file
Then in the command window type the following. CM12 recommend 50GB, but you can change to what ever you want.
Code:
prebuilts/misc/linux-x86/ccache/ccache -M 50G
Building CM12!!!!
Now you are all set to start building CM12. You have everything you need. So run the following commands:
Code:
cd ~\android
source build/envsetup.sh
brunch shamu
Thats it! CM12 is now building. This will take some time to build. I do recommend a duel boot PC as it works better than in Virtual Box. Even in my PC it takes about an hour and a half to do a fresh build and about 15 minutes to do a dirty build.
So once the build finishes you now have a flash-able version of CM12 from their latest source that you can flash on your Nexus 6 - Congratulations - you are now among the elite who can build their own ROM from source
The zip file is stored in the following directory:
Code:
cd ~/android/out/target/product/shamu/cm-12-20150308-UNOFFICIAL-shamu.zip
The file name will depend on the day you build the ROM, so it may be slightly different.
Here is an example output of a successful build of CM12!
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
​ Note of caution here:
Now that you have built CM12 as in AOSP I would not recommend flashing at this stage, it will make the following changes to your phone:
Install stock recovery
Encrypt your phone
To get around these we will need to make the following changes. See post 2 on how to make the changes.
As mentioned in post 1, after building CM12 you dont really want to flash it yet. It will:
Install stock recovery
Encrypt your phone - This is optional you can leave it to encrypt, but it is best to give the user the choice to do so or not.
In this post, I will also show you how to make other changes, eg: changing default wallpaper etc. I have a GitHub setup for this and all you need to do, is cherry-pick the commands into your folder, then compile the rom. My main source for all my changes are located here: https://github.com/StephenRJ - you are free to use these changes, but please give credit if you do.
Disable recovery.
Code:
cd ~/android/system/core/rootdir
git init
git fetch https://github.com/StephenRJ/cm12_system_core_rootdir.git
git cherry-pick f413ac907961c07f07f767ceb568deb4881e9f57
This next cherry-pick command will all the user the option of setting encryption on the phone, rather than it being automaticly encrypted.
Disable encryption
Code:
cd ~/android/device/moto/shamu
git init
git fetch https://github.com/StephenRJ/cm12_device_moto_shamu.git
git cherry-pick 7459b0d54102fbee27f363e7612b83f614a0f8c4
Now you have both of these disabled, you will need to do a fresh build again. To do this, I simply delete the out folder. Open file manager and go to android - then delete the folder out. This will let you make a full build again.
Close your terminal window and reopen.
Start a fresh build
Code:
cd ~/android
source build/envsetup.sh
brunch shamu
Now you can flash CM12 on your Nexus 6 Shamu Congratulations!!!!!
I will continue to add more fixes here has I find them.
Here are a couple of video tutorials I have found on setting up a basic Ubuntu enviroment.
Virtual Box: https://www.virtualbox.org/wiki/Downloads
Ubuntu ISO: http://www.ubuntu.com/download/desktop
Tutorial on setting up Virtual box on Windows 7 / 8
Duel boot Windows 8 and Ubuntu - Prefered method
Disclaimer
I am not responsable for anything that happens to your PC during the install of Ubuntu. I recommend taking a full backup first before installing a second operating system. Do this at your own risk. If your are not sure about installing different oprating systems, use the first method as it is safer
Click to expand...
Click to collapse
Change Log
Version 1.0.0
- Initial release
Please feel free to share here and help each other. I hope this guide is as useful to users as scrosler's has been. With out his help and guide, I would have never have been able to learn how to build AOSP for this amazing phone. I hope this guide gives more users the chance to build CM12 as well.
Using this guide, I have built and released a ROM. Please have a look here: [ROM][5.0.2][CM12 - Android L][LRX22G] Version 1.0.0 - [8/03/2015] - Native LED's
Please feel free to try it and report back!
I would suggest using a local manifest and getting your vendor files from TheMuppets repo. That way you stay up to date on any changes that are made.
Thanks for the tip. Could you explain a bit more on how to do that? I had installed an existing stock CM12 rom on the phone and then used the commands to remotely pull the files from it.
Stephen said:
Thanks for the tip. Could you explain a bit more on how to do that? I had installed an existing stock CM12 rom on the phone and then used the commands to remotely pull the files from it.
Click to expand...
Click to collapse
CM's wiki has a pretty good guide.
http://wiki.cyanogenmod.org/w/Doc:_Using_manifests#The_local_manifest
Also, not sure the recovery thing mentioned is an issue. I've been building CM for this device for nearly 2 months and have had no issues with TWRP being replaced.
Excellent guide! Now I just need a Nexus 6... :silly:
I love seeing useful tutorials being posted. That's why I got involved in @scrosler's thread. Nice job!!
akellar said:
Also, not sure the recovery thing mentioned is an issue. I've been building CM for this device for nearly 2 months and have had no issues with TWRP being replaced.
Click to expand...
Click to collapse
Agreed. I was just about to post that too. Most custom ROMs remove the stock recovery so custom recoveries don't get overwritten.
Very cool ill try this tomorrow! Can you maybe add a section on how to find and add nice cherrypicks?
Regarding the recovery I added that in on the safe side. I know if you download the full stock cm12 from their website it does change the recovery and encrypt the device.
I will be adding a few more cherry picks at some stage, I am working on something rather cool at the minute.
Thanks for doing this. I've followed a few guides but every one wasn't quite correct. I can't wait to test this out soon.
- Aaron
Very well done Stephen! I read as many of these as I can and always learn something new. This is very well written and I hope all of us can add and help each other as we progress with the N6!:good:
Hey,
I have built AOSP for Nexus devices for a long time, but have yet to run into this issue.
When I run "brunch shamu", it fails, referancing generic "goldfish"? is that just a generic device name?
Here is the build process:
[email protected]:~/android$ source build/envsetup.sh
including device/moto/shamu/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-mips/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including vendor/cm/vendorsetup.sh
including sdk/bash_completion/adb.bash
including vendor/cm/bash_completion/git.bash
including vendor/cm/bash_completion/repo.bash
[email protected]:~/android$ brunch shamu
including vendor/cm/vendorsetup.sh
Looking for dependencies
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=5.0.2
CM_VERSION=12-20150315-UNOFFICIAL-shamu
TARGET_PRODUCT=cm_shamu
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=krait
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.16.0-31-generic-x86_64-with-Ubuntu-14.10-utopic
HOST_BUILD_TYPE=release
BUILD_ID=LRX22G
OUT_DIR=/home/npjohnson/android/out
============================================
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=5.0.2
CM_VERSION=12-20150315-UNOFFICIAL-shamu
TARGET_PRODUCT=cm_shamu
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=krait
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.16.0-31-generic-x86_64-with-Ubuntu-14.10-utopic
HOST_BUILD_TYPE=release
BUILD_ID=LRX22G
OUT_DIR=/home/npjohnson/android/out
============================================
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
find: `src': No such file or directory
"ebtables is disabled on this build"
find: `dummy': No such file or directory
build/core/base_rules.mk:154: *** system/device/generic/goldfish/audio: MODULE.TARGET.SHARED_LIBRARIES.audio.primary.goldfish already defined by device/generic/goldfish/audio. Stop.
Not sure, haven't seen that error before. Have you added any extra mods into the rom? One of those could be causing the issue. It could also be an issue with CM12 its self. Some times they do add code in and it can cause errors.
I would try downloading source again and see if there is any difference.
Stephen said:
Not sure, haven't seen that error before. Have you added any extra mods into the rom? One of those could be causing the issue. It could also be an issue with CM12 its self. Some times they do add code in and it can cause errors.
I would try downloading source again and see if there is any difference.
Click to expand...
Click to collapse
Will do. I am building on Ubuntu 14.10. That should be OK to use correct? Fresh install, then followed steps in the OP.
npjohnson said:
Will do. I am building on Ubuntu 14.10. That should be OK to use correct? Fresh install, then followed steps in the OP.
Click to expand...
Click to collapse
Yes. Oh what setup are you using. Virtual Box or duel boot. I did have problems with Virtual box and switched to duel boot. Found it to be more stable.
Stephen said:
Yes. Oh what setup are you using. Virtual Box or duel boot. I did have problems with Virtual box and switched to duel boot. Found it to be more stable.
Click to expand...
Click to collapse
Dual boot.
Any idea why my builds come in at around 387MB but the official nightlies are ~443MB?

Guide - Introduction to Rom building/development

Hello everyone.
I’ve decided to build this tutorial in order to assist all developers and builders into the ROM and kernel development. I’ve felt motivating into writing this small post because I feel that the current information available is confusing and also do not provide the set of skills and information to help someone in the first steps.
This tutorial will be divided on:
The Machine Configuration
The tools of development
The Source
Hardware
Software
What to do to be able to Innovate
The Machine Configuration
In order to have a good machine configuration you should select your distro based on the packages which are provided to developers. In my opinion the best distros are Fedora and Ubuntu. It is important to learn a bit how Linux works in order to fully understand what we are editing as Android is nothing more than equivalent Linux system where you run java on a virtual machine. In other words, you’ll understand with time that many parts which are used on Linux Operating system it is also used on Android Operating System (example: bionic, kernel libs).
After you installed your Linux system you’ll need to prepare your machine for building. For that you’ll need to install the following packages:
Code:
sudo apt-get install git ccache automake lzop bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 g++-multilib python-networkx libxml2-utils bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev squashfs-tools pngcrush schedtool dpkg-dev liblz4-tool make optipng maven
sudo apt-get install openjdk-7-jdk
Code:
sudo apt-get install android androidsdk-uiautomatorviewer android-copyright android-src-vendor android-emulator android-tools-adb android-headers android-tools-adbd androidsdk-ddms android-tools-fastboot androidsdk-hierarchyviewer android-tools-fsutils androidsdk-traceview
After you have the basic packages installed we are going to add the repo instructions to you git in your machine. Basically this will interpret the source information when you are syncing new code from google repos and we’ll add to the folder /bin/repo.
To do that we’ll run.
Code:
[B]mkdir -p ~/bin
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo[/B]
And run the /.profile. Basically this command will reload information of the new settings for your profile, where it’ll read the folder ~/bin/repo information for all situations. In the future only makes sense to load again in case you have added a new repo instruction.
Code:
[B]. ~/.profile[/B]
Now we are going to sync the source code. I’ll use here as an example CyanogenMod as I believe to be the easiest for anyone which is starting. Lets imagine we are going to put all the source on a folder named cm, you’ll have to just run the following commands.
Code:
[B]mkdir ~/cm
cd ~/cm
repo init -u git://github.com/CyanogenMod/android.git -b cm-13.0[/B]
So in order to explain what we’ve done here by steps. The repo init –u basically is a command instructing to go to the GitHub on that specific location and extract what is available on the cm-13.0 branch regarding to manifests. So basically it’ll automatically push the file which has all CyanogenMod source to .repo/ folder with the name manifest.xml
After you have loaded this command you’ll run the repo sync , basically this command consists on downloading all the code into your building folder (in this case cm folder).
After the repo sync is complete you’ll have interest on having a local_manifests. Basically on this local_manifests.xml , where some developers prefer to name it as roomservice.xml it is where you’ll add the changes to the manifest.xml or even sources which you wish to add to your building folder. This is a solution to you never edit the manifest.xml.
Usually it is added on the local_manifests the folders related to your device tree. I’ll give in this example how to build for the OnePlus One (bacon).
A device tree consists on configurations where you set information related to your device. Example if is qualcom, usually is android_device_qcom_common (where is the general settings) together with android_device_oneplus_bacon (where are the specific settings). When I say settings, for you to understand is like compile with the folder hardware/qcom/display for the display. You should take some time to explore to understand what is in it.
So you’ll add your local_manifests.xml this way.
Code:
[B]
mkdir .repo/local_manifests
nano .repo/local_manifests/local_manifests.xm[/B]l
You now add:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<project name="CyanogenMod/android_device_oneplus_bacon" path="device/oneplus/bacon" remote="github" revision="cm-13.0" />
<project name="CyanogenMod/android_device_oppo_common" revision="cm-13.0" remote="github" path="device/oppo/common"/>
<project name="CyanogenMod/android_device_qcom_common" path="device/qcom/common" remote="github" revision="cm-13.0" />
<project name="CyanogenMod/android_kernel_oneplus_msm8974" path="kernel/oneplus/msm8974" remote="github" revision="cm-13.0" />
<project name="TheMuppets/proprietary_vendor_oneplus" path="vendor/oneplus" remote="github" revision="cm-13.0" />
</manifest>
Now you need to run the repo sync command again.
This has to do separately the first time or it won’t sync all the files you need. In case the repo sync fails with an error saying you need to do –force-sync just run repo sync –force-sync (this happens only when you change common git sources with your manifest.
After the sync is done you are ready to build!
To start building you’ll need to run the .envsetup.sh , which will load all the source code into memory. After that breakfast bacon userdebug (in case it is for the OnePlus One device), then later make bacon (the word bacon it is to be used on all devices , here it is just a coincidence with OnePlus One)
Code:
[B]. build/envsetup.sh
breakfast bacon
make bacon[/B]
After it compiled your rom will be located at /cm/out/target/product/bacon/
Easy until here? I hope so.
Possible errors :
Q: Receive error: fatal: duplicate path xxx/xxx in ~/cm/.repo/manifest.xml
A: edit .repo/local_manifests/local_manifests.xml to remove the item which matches the item located in bold.
Q: How big is the repo?
A: 50GB just source code and around 10GB when built per device. Therefore you should aim to have about 60GB free on your system.
The tools of development
Git
Probably many of you question about what it is git, read about it on the github manuals etc and still cannot figure out how to work (I took two weeks to understand that it is really simple). So imagine that you have a diary, but instead of being separated by dates it is separated by titles, which we call commits. And what is a commit? Basically it is a portion of code. So when you make a change and want to record that change, you create a commit and in the end it’ll be a portion of code. This portion of code, known as commit, can be easily ported between different sources.
Here is an example:
https://github.com/jgcaaprom/androi...mmit/9f16b3cd79ad7bb8c821a518ca73725f19c38478
The commit number is: 9f16b3cd79ad7bb8c821a518ca73725f19c38478
This commit has recorded a change of IZAT_DEBUG_LEVEL = 2 .
Now how to bring other commits from different sources into our source.
The process comes in 3 phases:
First we’ll have to add the source where the commits that interests us are with git add source_name link
Second we’ll download that source by using git fetch source command
Thirdly we’ll cherry-pick (bring the portion of code recorded in the commit) into our source in order to make the changes automatically.
So lets see a real scenario. Imagin you are interested on cherry-picking this source:
https://github.com/CyanogenMod/android_device_oneplus_bacon
What you’ll have to do is.
Step one: git add cm https://github.com/CyanogenMod/android_device_oneplus_bacon.git
Step two: git fetch cm
Step three: (imagine this is the commit you want:
https://github.com/CyanogenMod/andr...mmit/58027fcbea4dd9fbb5aaeb8ae5f6e32bdf613573 )
The commit number is: 58027fcbea4dd9fbb5aaeb8ae5f6e32bdf613573
So you’ll git cherry-pick 58027fcbea4dd9fbb5aaeb8ae5f6e32bdf613573
And voila! You’ve done your cherry-pick . Now it is important to have in mind how the cherry-pick process works which I’ll explain on the next step.
Cherry-picking
Cherry-picking is a process of importing code from one source to another. So the process that git does basically is, compares your present files in the source with the files that was on the source you are cherry-picking and if everything is a match it’ll change the code automatically for you.
Now lets pick up the example above and imagine that the changes you are doing instead of being exactly the same as described here:
https://github.com/CyanogenMod/andr...mmit/58027fcbea4dd9fbb5aaeb8ae5f6e32bdf613573
Your source has a difference which doesn’t have this line:
32 private static String CONTROL_PATH = "/proc/touchpanel/keypad_enable";
You’ll notice that it’ll give a conflict. The reason for that is because the git when comparing understood that there was no match between the sources. When that happens means basically that there might be changes you should do in order for the code to be compatible, so you’ll have to review that code.
Now the review process is very simple. For you to see which files are in conflict you’ll have to run git status ( basically this command informs you of the situation of the commits which are being cherry-picked and the changes which you’ve done. )
You’ll notice that the files which need to be edited/review are in red. In case it appears files in green, means that there was a perfect match and doesn’t need a review.
Pretty useful right?
After you finish editing all the code you’ll do git add . and for this exercise do git status again just for you to see what happened . Everything is green. To finish the cherry-pick you’ll now do git commit and done!
How to record my own changes and create a commit with it.
Basically this process is exatly the same as the previous one, the only difference is that after you made the changes, you can make git status, then git add filename in case you want to commit only one file or git add . in case you wish to commit all the files and to record the commit you write git commit, or git commit –m “commit message”.
Congratulations! You’ve just recorded your commit!
Git push/pull
There will be moments where we just wish that we could be lazy and cherry-pick everything all at once. Well there are some scenarios where you can actually do that, but remember it is not perfect. Lets imagine we are using the source above, and CyanogenMod uploaded like 20 different commits, your source is not exactly like CM source but you wish to keep your changes and also have all changes from CM what to do?
1) You can cherry-pick one on one. And waste a lot of time…
2) You can make a new source based on cm and include your changes there
3) You can git pull
Git pull basically will update your source with CM source by merging all the commits. You do that with:
git pull cm cm-13.0 (in case your rom is Marshmallow)
The git pull should only be used when the sources are very similar and you are using as a base. Basically it’ll warn you that’ll merge the code and voila done! 20 commits added to the source.
Now when on the situation that the sources are slight different or very different it’ll create a conflict. Again the git will do comparisons between the entire sources, check which commits are missing, compare the files just like with cherry-picking. And when you do git status, it’ll appear on red all files where you need to review your code.
After you finish, same as before
Code:
[B]git add .
git commit[/B]
Done.
I hope you are understanding everything until here.
git reset HEAD~n
This command is rarely used but is super usefull. Basically you are saying to git that you with to remove n commits you've reated/cherry-picked. For you guys to understand how it works, basically imagin you have just written/cherry-picked 10 commits, and you do git reset HEAD~3 , he'll basically remove from records 3 commits. But... That doesn't mean he reverted the code! In case you wish reset the code you need to do git reset --hard.
Also it is very usefull to help rewrite the history. Lets think the example I given before. When you do a git reset HEAD~3 , basically on a history of A B C D E F G H I J commits, the git will remove only the recorded commits H I J. If you do after a git status, you'll understand that the code is still there, which means the changes you done on H I J will still be there. So you can create a new commit with H I J all together . Simple!
Another way to create a unique commit with H I J is by using git rebase -i HEAD~3 , where you basically are instructing the git that you wish to rebase the source with an interactive selection. You'll see that it'll appear a commit list where you can remove other commits from history. But since you wish to create a unique commit you'll wish to change the instruction from pick with the letter s (without capslock term for squash) . Example:
Code:
[B]pick d0c49f4 UsbDeviceManager: Remove charging from persisted function composition
s 2c755a6 SystemUI: fix NFC tile sometimes hiding
s e39d1d7 Revert "base: start nfc service prior to systemui"
pick 9164274 DocumentsUI : Hide advanced menu option when in forced mode
pick 5f8d3f8 Themes: Expose Power Dialogs
pick 9153396 SysUI: Don't let rogue themes ruin notifications
pick 226797c Revert "Only show keyguard panel if on lockscreen + no activity on top"
pick e843aaf Fix NPE in DocumentsUI when rotate UI before format as internal
pick 26079d3 SystemUI: detect rotation and resize mKeyguardBlur accordingly
pick 80b060d Automatic translation import
pick 4282864 Automatic translation import
pick d442df6 wifi: Enable WiFi IpReachabilityMonitor by default
pick 9cf937f SystemUI: Add margin in qs_tile_top between instruction text and add button[/B]
Cool right?
And I believe I've covered with some examples the git. As you can see, once you get used to git you'll be able to use it easily.
Toolchains
There has been a big debate from many developers on which toolchains to use. Many prefer sabermod, others prefer uber, others google toolchain, etc. It is in fact debatable. If you ask me which one to use, I would say google or uber (very similer to google) and the gcc used by stock on the source. The reason is simple, the code is optimized for a certain gcc version, if you start using a gcc version which is not prepared to be used on the code, it won't translate correctly your instruction.
The source
When you start building roms, you should at least know a little about how the source of android is organized, what language it is used, etc. On android it is used C, C++, Java, Assembly. Withing the following folders inside the source it is used:
Java
Frameworks
Packages
external (some packages)
C++
ART
bionic
hardware
C
kernel
hardware
Assembly
bionic
some of the kernel libs
This is important for you to navigate easily within it. Some of you ask yourselfs what is one thing or another. I'll represent that to the following image which is published on the google developers page.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Now I believe you wish to know which parts should be used in order to put a rom working for a certain device. Those parts are:
Hardware
Kernel
device tree
Vendor blobs
These parts are the "base" of your build to put a certain device in a working, since on these parts is where lies the instructions for the device to understand what to do.
The build folder is where you specify instructions of the building process. For example : Certain optimization, which GCC to use, where will the compiler find the apps to compile.
frameworks, system, packages and some of the folders within the external folder are the packages of what you will have inside the rom which is general and can be present on any rom.
external folder has present different things, compilers such as proguard, jemalloc. external software used by the rom such as sqlite.
prebuilts folder has present everything related to stuff which is already compiled, in this case clang, gcc toolchains.
I've done a very summarize version of the source in order for you to understand how that google built things, so I hope it is simple to understand these basics.
(to continue)
reserve1
reserve2
reserve3
Another great contribution bro. Thanks for your work and for your help. Starting read right now
Edit: Amazing guide
Just one request, please bold when you write a command. I think it becomes more eligible.
@jgcaap I think this is useful
For those already have JDK8 installed, they can use it by adding this code to $HOME/.bashrc
Code:
EXPERIMENTAL_USE_JAVA8=true
You just have to source ~/.bashrc before make bacon
There's nothing better than learning something from a professional who you know has done such a great work. Thanks a million!! @jgcaap
Very useful.. Thanks for sharing =D>
Sent from my A0001 using XDA-Developers mobile app
FSadino said:
@jgcaap I think this is useful
For those already have JDK8 installed, they can use it by adding this code to $HOME/.bashrc
Code:
EXPERIMENTAL_USE_JAVA8=true
You just have to source ~/.bashrc before make bacon
Click to expand...
Click to collapse
I'll speak about different custom GCC and also other compilers, but it'll be on another section. I'll continue writing this on wednesday (exam tomorow). I believe that my guide will help understand all the basics.
If I speak about that mode, I believe it'll give the idea that it is a feature of linux and it isn't. It is something you can change inside the source in many different ways.
jgcaap said:
I'll speak about different custom GCC and also other compilers, but it'll be on another section. I'll continue writing this on wednesday (exam tomorow). I believe that my guide will help understand all the basics.
If I speak about that mode, I believe it'll give the idea that it is a feature of linux and it isn't. It is something you can change inside the source in many different ways.
Click to expand...
Click to collapse
This might sound a little stupid but which JDK version is recommended? 7 or 8? Seems like 7 cause you have to enable "Experimental Use" for 8.
Great guide! Can you, if you have time, also post a guide only focusing on kernel building?
abhibnl said:
Great guide! Can you, if you have time, also post a guide only focusing on kernel building?
Click to expand...
Click to collapse
The guide is incomplete, will write more on wednesday. I'll cover everything in a very simple waywith praticle solutions.
thank you , that what was looking to develop on my tablet , I can use basic as this tutorial for other devices.
continue with tutorial , as many want to learn, but has no simple guide to base
you must wrote revision="cm-13.0" /> instead of revision=”cm-13.0” /> 'cause it give you an error that you can't be able to repo sync
fafa77140 said:
you must wrote revision="cm-13.0" /> instead of revision=”cm-13.0” /> 'cause it give you an error that you can't be able to repo sync
Click to expand...
Click to collapse
i literally stared at this for like 1h and didn't find any difference could you please elaborate more...
baconxda said:
i literally stared at this for like 1h and didn't find any difference could you please elaborate more...
Click to expand...
Click to collapse
The quotation marks surrounding cm-13.0 in first post are not the right ones. So you need to replace those quotation marks if you copied and pasted the code in your manifest. Just delete the quotation marks and type them again.
joshuous said:
The quotation marks surrounding cm-13.0 in first post are not the right ones. So you need to replace those quotation marks if you copied and pasted the code in your manifest. Just delete the quotation marks and type them again.
Click to expand...
Click to collapse
ohhhkayyy.........:good:
fafa77140 said:
you must wrote revision="cm-13.0" /> instead of revision=”cm-13.0” /> 'cause it give you an error that you can't be able to repo sync
Click to expand...
Click to collapse
good catch. I never thought the keyboard would be writting differently when not on the terminal. Thanks
jgcaap said:
good catch. I never thought the keyboard would be writting differently when not on the terminal. Thanks
Click to expand...
Click to collapse
No problems
fafa77140 said:
No problems
Click to expand...
Click to collapse
updated more stuff today.

[GUIDE][2018]All you need to know to build Android from scratch!

Introduction​So, I will start off by telling a little bit about myself. I got interested in Android building in November 2017. I found most of the guides "inadequate" for pure newbies like me.
This is my second guide and the first one for No-Knowledge newbies so please do correct me . I will also add some humor so you don't get bored
The guide will be divided into a few parts-
Using linux and enjoying it(No offense to GNU/Linux enthusiasts. please don't start a debate, its just my personal opinion)
Basic git for complete newbies
Compiling your first ROM(Lineage)
Compiling your first non-Lineage ROM
Choosing a Programming lanugage
Basics to resolving conflicts
Compiling AOSP-based roms for CAF devices(For which I couldn't find a guide)
It will probably take a while for you to read this but its must to read everything carefully. Lets start off right away
Using Linux and Enjoying it!
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
There are more than adequate guides for using Linux. I will just help you choose the distro and recommend some guides
Personally, I used Linux wayyyy before I started building android(~2013) I didn't do much at first so I got most of my Linux experience in 2016-2018
Some distros I recommend-
Ubuntu 16.04 or 18.04 (Probably the best for newbies imo) - https://www.ubuntu.com/download/desktop
Arch Linux(Could be problematic to install for newbies so I recommend you install Antergos first - https://Antergos.com/try-it/ )
Linux Mint - https://linuxmint.com/download.php (Newbie friendly)
Debian GNU/Linux (Easier than Arch imo, slightly(very slightly) harder than Ubuntu) - https://www.debian.org/
You absolutely MUST live boot them and feel them. I highly recommend you to install them on a small partition(~40GB) to get the best experience. Please don't use linux on a server at first!
I personally started with Ubuntu 12.04 for a month or so, 14.04 as well for a few months. I became a daily user when 16.04 came out.
Currently, I am using Antergos. However, for building I liked Arch as it had everything "bleeding edge"(Search it if you don't know what this means xD)
Here are some absolutely noob friendly guides-
https://www.youtube.com/watch?v=opBKvGi77cU
For Ubuntu (Long guide but indepth!)
https://www.youtube.com/watch?v=G0AFuhVSvEk
For Linux Mint (Again, Long but indepth!)
Use them for atleast a week or two before you even jump into android building! A month of daily usage is recommended so you know how to tackle basic problems. Youtube will always be your friend and so will be google. You can't hate Linux once you know how to use it! The only reason why I use Windows is because of gaming and applications such as Photoshop and Illustrator(I know there are alternatives, again just my personal opinion!)
See you after a week! No? Seriously use linux for atleast a week!
Using Linux will also hone your google skills(Not even kidding)
Basic git for complete newbies
Personally, I myself don't do advanced stuff with git myself and here are the subcommands you will be using the most with git -
clone
cherry-pick
revert
merge
commit
push
I will give a brief explanation of each and link some guides! Why brief? Because I expect you to have a thinking like a linux user now . Also, you can switch to a server now!
Here is a playlist by github -
https://www.youtube.com/watch?v=noZnOSpcjYY&list=PLg7s6cbtAD15G8lNyoaYDuKZSKyJrgwB-
If you are not satisfied(I wasn't) you can search youtube for a specifc command as well! (i.e cherry-pick)
clone -
Simply clones the repository including its commit history!
Usage-
Code:
git clone <repo> -b <branch> <directory>
If you don't specify a branch, it will clone from the default branch.
If you don't specify a directory, it will make a folder with the name of the repo
Example -
Code:
git clone https://github.com/ChimeraKernelProject/chimera_land-current -b lineage-16.0 chimera
(Shameless self advertising xD)
cherry-pick-
Generates a diff from a commit and applies it to the local repo
Usage-
Code:
git cherry-pick sha
You do need to fetch the repository from which you are picking a commit
Using-
Code:
git fetch <repo> <branch>
If the branch isn't specified, it fetches the default branch instead
Cherry-picking multiple commits-
Code:
git cherry-pick sha1^..sha2
This picks all the commits from sha1 to sha2(i.e the commits between sha1 and sha2, including sha1 and sha2)
You may or may not get a conflict for which I will have a seperate section.
Example-
Code:
git fetch https://github.com/ChimeraKernelProject/chimera_land-current lineage-16.0
git cherry-pick 9e8a821ba64f5b498843b025d1804e3818dda480^..8e80e52915492328e80378f7ecff0cb44fdc1344
(Try figuring out what I did )
What is SHA you ask? You don't have to know what it actually is so just consider it to be an identifier for a commit.
revert
Generates a diff of the commit and reverses it(pretty much the opposite of cherry-pick)
The usage is same as cherry-pick.
merge
Kind of like cherry-picking multiple commits but it compares the history of the local and the remote and then generates a common diff for the commits that are not in local
Also, you do need to fetch before merging.
Usage-
Code:
git merge <remote>
Example-
Code:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git v3.18.125
git merge FETCH_HEAD
(The example here is of upstreaming the kernel )
commit and push
Generates a commit for staged files
Usage-
Code:
git commit -m "some message" -m "sub-message"
some optional parameters-
--signoff
--author="name <author email>
If you forgot to add a file to the commit, you can -
Code:
git commit --ammend
Again, you can use the optional parameter.
how to stage files you ask?
you simply use-
Code:
git add <filepath>
If you did your linux lessons correctly, you might know that, you can use "." and ".." in filepath(redo them if you don't know xD)
finally, to "push" your changes to a remote repo-
Code:
git push -u <repolink>
It will ask for authentication. You use your github(or whatever you prefer) account for that.
After using -u once, you won't have to pass the parameter again.
Lets end this with an example-
Code:
git add .
git commit -m "add 69 hour battery life" -m "best" --signoff --author="someone <[email protected]>"
git push -u https://github.com/ChimeraKernelProject/chimera_land-current
(Also please don't use a stupid commit message like the one I showed xD. This one was just for the lulz)
This one was big. oof. Took me a while to write and probably will take a while for you to read too .
You might ask why did I tell you to search xyz in this one so much! Simple reason- I want you to get used to searching your problems!
Mastering git takes alot of time! I am not any good myself and I search alot of stuff on google myself! (Sometimes even problems related to merging and checking out!)
Compiling your first ROM(LineageOS)
I bet you have been getting restless by now! The previous guides were to build the excitement to build your first ROM!
Why Lineage? Simple. Its one of the easiest ROM to build. Pretty well documented and most importantly, alot of video guides to check if you are confused at any point!
It is highly recommended to use a server at this point as you will be pulling alot of data and you will require alot of processing power.
You can build locally if you have good internet.
Here are the minimum requirements(imo)-
i3 6100 or equivalent
8 GB RAM
300GB HDD(500 GB+ is highly recommended)
Lets start off by the dependencies. I am assuming you are on Ubuntu or Linux Mint. These are the dependencies you need to install -
Code:
openjdk-8-jdk
git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev libgl1-mesa-dev libxml2-utils xsltproc unzip
You know how to install them don't you now
Lets install Repo now-
Code:
mkdir ~/bin
edit your .bashrc in the home directory with your preffered file editor(I use nano) and add this line to the bottom (Hint - hold pgdwn to jump to the bottom quickly)-
Code:
PATH=~/bin:$PATH
Then execute these commands-
Code:
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
Code:
chmod a+x ~/bin/repo
Lets sync Lineage now shall we
First add your github account to the git config using-
Code:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Here, you should use your github email! (See https://help.github.com/articles/about-commit-email-addresses/ if you don't want to use personal email)
Make a dir in which you will do the rom stuff and cd to it
Before we initialize and sync LineageOS, you have to decide which branch you are choosing as well
You can check your device forum and see what Android versions does the device have. PS- You might wanna check the LineageOS thread. The developer must have provided a link to their kernel source(If they didn't, report the thread to mods kek). Click and navigate through their github. you will find a repo named- android_device_(vendor)_(devicecodename) . you probably know the vendor and the codename from the forum don't you?For example its- android_device_xiaomi_land for my device(Yea right I have an old as hecc device pls no laugh ). Check the branch of the ROM. It will probably something like lineage-16.0 or 15.1 etc. Also if you have an official device, you can check its branch at- https://github.com/LineageOS .
Welp now you know the branch, lets start!
Code:
repo init -u git://github.com/LineageOS/android.git -b <branch>
repo sync
To sync a little bit faster, here's a better command I got from StatiXOS git -
Code:
repo sync -c -f --force-sync --no-tag --no-clone-bundle -j$(nproc --all) --optimized-fetch --prune
Also, if your sync stopped midway because of your ISP(BSNL :'( ), you can just start the sync again.
If you are on another distro such as arch, you might have to do some extra steps- https://wiki.archlinux.org/index.php/android#Building
Now that you have synced, You may choose one of the 2 paths-
If you have official LineageOS, choose me!
Setup the environmental Variables with-
Code:
source bu*/e*
Clone your vendor blobs from TheMuppets repo - http://github.com/TheMuppets
or, from your preferred developer.
The usual repo name is proprietary_vendor_(vendorname). For example, in my case its proprietary_vendor_xiaomi . It should have a folder with your device codename
If not, try changing the branch!
You should be cloning them to vendor/(vendorname)
start bulding right away with-
Code:
brunch lineage_<codename>-<buildtype>
here, codename is your device codename and buildtype is one of these-
user, userdebug, eng .
I recommend userdebug at first. user builds are pretty much as limited as your stock rom. eng builds are actually the one you should use for debugging the rom. These are not secure for daily usage.
This will start the build and you probably won't get an error as its official. If you do, you can just search it up on google. Once the build is done, you will get filepath in the command output. Generally, the build is in
<workingdir>/out/target/product/<codename>/xyz-UNOFFICIAL.zip .
If you have unofficial Lineage, choose me!
I am assuming you are in the working directory
Welp, lets start off by searching for the required trees.
Here's what you need-
Device Tree
Kernel Source
Vendor Blobs
Usually I find them by checking the post of the unofficial Lineage thread and click the kernel source link(Again, if they didn't post it, you should report the thread ). Go to the dev's profile and check his repositories. Here are the usual naming schemes for each one of them-
Device tree - android_device_(vendorname)_(devicecodename)
Kernel Source - android_kernel_(vendorname)_(devicecodename) or! android_kernel_(vendorname)_(soccodename)
Vendor Blobs - proprietary_vendor_(vendorname) or, proprietary_vendor_(vendorname)_(devicecodename)
Device tree should be obvious. It should be cloned to - device/(vendorname)/(devicecodename)
As for kernel tree, soccodename menas the codename of the SoC you have in the device. The thread should have it already as the kernel is licensed in GPL v2(GNU Public License V2, for more info check - https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html ). To know where you need to clone the kernel tree, check the "BoardConfig.mk" of your Device tree and check the "TARGET_KERNEL_SOURCE" line. It tells where you need to clone the kernel
vendor name should be obvious as well now. If your vendor name doesn't have the codename, it should be cloned to vendor/<vendorname>
if it has the devicecodename, it may or may not be the device tree and still be like this-
If it doesn't look like this, it should be cloned to vendor/<vendorname>/<devicecodename>
Here's the repo list of an ideal dev-
Setup environmental variables-
Code:
source bu*/e*
Start the build! -
Code:
brunch lineage_<codename>-<buildtype>
here, codename is your device codename and buildtype is one of these-
user, userdebug, eng .
I recommend userdebug at first. user builds are pretty much as limited as your stock rom. eng builds are actually the one you should use for debugging the rom. These are not secure for daily usage.
Now since you are using an unofficial tree, it is likely that you might hit an error. One of the most common error is when brunch is unable to find your target device. a simple fix for that is to navigate to your device tree and make a file called "vendorsetup.sh"
It should have this line in it-
Code:
add_lunch_combo lineage_<codename>-userdebug
where(you guessed it), codename is your device codename. Run the environmental variable setup again and you should be ready to build.
You might hit errors. Google is always your friend. If you are absolutely sure that you can't find it on google, check the help group section in the thread!
Once the ROM is ready, you will find the filepath in the command ouput. Generally its in out/target/product/<codename>/xyz-UNOFFICIAL.zip
Uploading files to google drive
There's a really nice guide availabe here- http://olivermarshall.net/how-to-upload-a-file-to-google-drive-from-the-command-line
Congratulations! You just made your first rom. If you find this hard, this is just the beginning! There's a very rough road ahead.
Compiling your first Non-Lineage ROM
PS. - The ROM has to be "Lineage-based".
thee aren't eft f'r aosp bas'd roms!
I will be using XenonHD as an example as it is pretty easy to build and it was pretty much one of the first roms i ever built.
Building a Lineage-based rom is as easy as building Lineage!
You go to the rom's git(I usually google search or check it in one of the rom's thread for any device) and check the repo manifest. The usual naming scheme for a repo is-
android_manifest
platform_manifest
manifest
android
etc.
In xenonHD's case, its platform_manifest(and all other repo names will start with platform prefix)
A proper ROM source should have the syncing instructions and building instructions. Lets check the XenonHD's example
make a working dir for the rom in which you will do your rom stuff.
Initialize and sync it. The initializing and syncing part is always the same across the ROMs. (You know which branch to use now. Don't you?)
Again, clone all the required trees!
Now now now, don't get excited yet! Before you start brunching, there is some stuff you need to change.
Usually you can refer to one of the official trees in the ROM organization. For example, https://github.com/TeamHorizon/android_device_xiaomi_kenzo has proper commits. You should be looking at the "Initial XenonHD" commit. You can obviously ignore commits like https://github.com/TeamHorizon/andr...mmit/c076f8c7199d0cddbe6a1e0d05bf3ffc63080d1d as they are device specific. The basics are always the same-
Rename lineage.mk to (romname).mk . refer to the device tree if you are unsure about the romname
edit the (romname).mk and change all the lineage instances to (romname). refer to the commit if unsure.
rename lineage.dependencies to (romname).dependencies .
Renaming the kernel defconfig isn't really necessary so you can ignore that.
Setup the environmental variables(Same across all the roms)-
Code:
source bu*/e*
start the build using the supported command given by the ROM devs.
Code:
brunch codename-<buildtype>
in XenonHD's case. However its different across most of the roms so never forget to read manifests!
You are more likely to hit errors with these spinoffs. Google is your friend(I can't remember how many times I have repeated this) and so is LineageOS repo! You have alot of references if the error is not device specific. Learn to fix derps! Check the help groups sections and ask if its absolutely necessary! Again, the command output will have the filepath of the final ROM zip!
You aren't ready yet. You need to gain alot more experience in compiling ROMs and here are some ROMs that you should be able to build at this point- Resurrection Remix, DotOS etc. Most of the lineage based roms support brunch. (Be careful tho, as a few AOSP based roms support it too. You might have a hard time compiling those!)
Choosing a programming language
At this point, it is highly suggested to learn a programming language if you want to escape the Buildbot stage. I am not forcing you, but you will have alot of trouble in doing advanced stuff.
There are several beginner friendly languages-
bash (the easiest)
Python (Recommended)
Kotlin (Android App development, quite easy)
Harder, recomended to learn after the easy langages-
Java (Gotta learn java if you want to make your own custom ROM at some point :3 )
C/C++ (Other than System UI, most of the other stuff for Android is written in C or C++)
Anything else you like! Once you get the basics, its not hard to learn another language .
The reason why I recommend Python is because it was the first language I learnt! Its pretty easy(Though, the OOP, Object Oriented Programming part is slightly advanced). It has wide applications and THE preferred language for Machine Learning and AI stuff, Period(OMG BUZZWORDS).
Kotlin is also fairely easy. I haven't programmed much in kotlin though I know basic syntaxes. If you learn it first, you won't have much trouble with learning Java. Probably. You can learn Java at first as well but you might have trouble! C is a must learn if you want to modify the Kernel and C++ is a must if you want to modify other code like HALs!
Python takes a day or two to learn! Not even kidding. I recommend this nice playlist by CSDojo - https://www.youtube.com/watch?v=Z1Yd7upQsXY&list=PLBZBJbE_rGRWeh5mIBhD-hhDwSEDxogDg
If you are interested in programming Machine learning, I recommend this playlist- https://www.youtube.com/playlist?list=PLOU2XLYxmsIIuiBfYad6rFYQU_jL2ryal
I learnt Kotlin basics from this Video - https://www.youtube.com/watch?v=H_oGi8uuDpA but there are more advanced videos as well.
I can't link Java tutorials as I haven't learnt it and nor do I plan to anytime soon. You can of course check youtube .
I learnt C from books and The C programming language by Dennis Ritchie and Brian W Keringhan is a must read! I quite liked "Programming in ANSI C" by E. Balagurusamy as well. You can of course, learn it on youtube.
Getting into programming takes a while and you might not like it at first but if you do, you will always enjoy it!
Basics To Conflict Resolution
It is assumed that you have a mind of a programmer and thus the guide will have alot less spoon feeding!
Lets get back to git and discuss about Conflict resolution. From time to time, you might want to cherry-pick something or perform a merge and you might get a "conflict".
Here's a basic idea!
The code between <<< HEAD and ===== is your previous code and the code between ====== and >>>> (commit SHA) is the new code from the commit. You get this if a part of the file in the commit is not the same as your local file.
There are 3 possibilities -
The code between <<<< HEAD and ===== is not required, thus you can delete that (Mostly)
The code between ===== and >>>>> is not required, thus the new change is not required (Rarely)
Both the old code and the new code is required (Pretty common!)
How do you decide between the three? You actually check the commit you are picking. In case of a merge, you can just view the history of a file and check the changes on github. Mostly, that should be enough for a decision. In case of a conflict while upstreaming my kernel, I usually refer to android-linux-stable project - http://github.com/android-linux-stable . Other times, I actually use my brain and figure out the option myself!
Compiling AOSP-based roms for CAF devices
Welp, I took alot of your time! You surely learnt plenty. Its the final part of this guide Took me a while to write all this ;_; .
I am assuming that you are fairly experienced now and you have atleast basic programming knowledge and plenty experience with git.
For starters, I recommend you to try AOSIP! It is highly compatible with Lineage trees and it shouldn't be much trouble to modify your device tree for it.
No spoon feeding at this point . Lets revise the basic idea! -
Find the rom source
Find the appropriate branch
Check the manifest for syncing and building instructions
Refer to another device tree(Possibly a tree of a similar device) and modify your device tree! (The hard part as its different from lineage based roms)
Environment setup
Start the build
Most of the AOSP-based roms use these commands-
Code:
lunch <codename>-<buildtype>
Code:
mka bacon
The lunch part is always there in Maximum AOSP based ROMs and the building command maybe different(i.e
Code:
time mka kronic
in AOSIP)
Another part I want to mention is about "HALs" . Usually most of the ROMs (even AOSP-based) ship with CAF HALs and support project pathmaps. However, some ROMs don't. Probably because they are not intended for CAF devices or the sources aren't properly complete yet! To build these ROM succesfully, I clone the CAF HALs from the lineage repo. These are- display-caf, media-caf, audio-caf, bt-caf and wlan-caf.
The first 3 HALs are usually platform specific so do check the branch on LineageOS! (for example, its lineage-16.0-caf-8996 branch for 821 series family SoCs for pie). The next step is to remove project pathmpas from both the device tree and the HALs. You can refer to the changes done by PedroKalil -
https://github.com/KAOSP/platform_hardware_qcom_display-caf/commits/aosp-8.1-8996
https://github.com/KAOSP/platform_hardware_qcom_media-caf/commits/aosp-8.1-8996
https://github.com/KAOSP/platform_hardware_qcom_audio-caf/commits/aosp-8.1-8937
Don't be lazy. Don't clone these HALs as these are outdated! Refer to them and do the appropriate changes on the latest Lineage HALs. the libbfqio changes may not be required as alot of AOSP-based roms have started to ship with it.
As for the Changes required in Device tree, you can refer to -
https://github.com/rupansh/pie_device_xiaomi_land/commit/c118701ba20a70fd59e32833417adeb7b08ab1d0 (The custom Audio policy is probably already enabled so no need to do that)
and https://github.com/rupansh/pie_device_xiaomi_land/commit/23215a2d8d5f1976657190f2a8f19f3fd111c250 (Depends on the path you cloned your HAL to)
You should now be able to compile any AOSP-based ROM! Experience is the key. Some other AOSP-based roms I recommend - NitrogenOS, AEX, AOSCP, Pixel Experience(Fairly easy), Pixel Dust(One of the hard), AOSPA( teach me when you fix the cneserver error lulz) .
Thats all you need to know to build AOSP-based ROMs for CAF devices .
If you wish to get into Android and Linux Kernel Development, Learning C is a must! I recommend this guide by nathanchance if you are ready! - https://forum.xda-developers.com/an...erence-how-to-compile-android-kernel-t3627297
Groups for help
https://t.me/AndroidBuildersHelp
https://t.me/LinuxKernelNewbies (Linux Kernel only)
Your device groups
Let me know if you want your group here
Credits
@tanish2k09 and @Swapnil Soni ( For guiding me even though I had 0 knowledge, co-operating with my idiotic requests)
ABH (Helping me realise that you can fix most of the errors by just searching properly)
@nathanchance (for his awesome kernel guides)
@KalilDev (For helping me with building AOSP based roms)
@ZeroInfinity (For machine learning tutorials kek)
@riteshsaxena (Bess sources for reference xD, Helping me with pie bringup which caused rapid progress for me)
You, the reader
I hope you learnt plenty of stuff from the guide. It took me a while to type this you see :3 .
​
awesome sir
rupanshji said:
@KalilDev (For helping me with building AOSP based roms)
Click to expand...
Click to collapse
This is one of the best or the most helpful guide I've ever read! I'll Recommend this for anyone who wants to join the ROM building club.
10/10 tutorial, thanx dev.
Thank you for this, OP
any guide like this for mtk devices?

Categories

Resources