I've just cloned the Android kernel (via git clone) repository but for some reason, none of the source files are there. Instead there is just a massive .git folder, which I think has the kernel source code in it. How do I 'unpack' that git repository so I can get a workable source tree?
The exact command I've used was git clone git://android.git.kernel.org/kernel/common.git android-kernel.
git config core.bare returns false
git branch returns * master
git checkout master returns Already on 'master
The files seem to be there but they are packed. I really don't care about preserving integrity of the repository, I just want the source tree, without any of that stupid git crap.
In android they use their own tooling which uses git under the hood:
I am not sure how to get a kernel built working if you directly clone git repo, for their own tooling here are the docs:
http://source.android.com/source/downloading.html
Old question, but - The answer above is, indeed, incorrect. You have to cd to the directory you've cloned, then run git branch -a, and checkout the relevant one:
bash-3.2# git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/android-2.6.39
remotes/origin/android-3.0
remotes/origin/android-3.3
remotes/origin/android-3.4
remotes/origin/android-3.4-compat
remotes/origin/coupled-cpuidle
remotes/origin/experimental/android-3.8
remotes/origin/experimental/android-3.9-rc2
remotes/origin/linux-bcm43xx-2.6.39
remotes/origin/master
Then:
bash-3.2# git checkout android-3.4
Checking out files: 100% (38819/38819), done.
Branch android-3.4 set up to track remote branch android-3.4 from origin.
Switched to a new branch 'android-3.4'
Then, at last:
bash-3.2# ls
.git Documentation README drivers ipc samples usr
.gitignore Kbuild REPORTING-BUGS firmware kernel scripts virt
.mailmap Kconfig arch fs lib security
COPYING MAINTAINERS block include mm sound
CREDITS Makefile crypto init net tools
Related
Is there a way to build an Android system app from AOSP without having to clone the entire code tree and having to build the entire OS?
Just being able to build the unmodified app from a Linux shell is sufficient, with any toolchain that will do the job. Being able to make modifications in an IDE (Eclipse or Android Studio) is not a requirement (a text editor will do for making changes).
The app in question is CarrierConfig. Most of the app is just assets, the code consists of just one single Java class (~400 lines of code), but with four internal dependencies not exposed through the SDK API:
android.annotation.Nullable
android.os.PersistableBundle.restoreFromXml(XmlPullParser)
android.telephony.TelephonyManager.from(Context)
android.telephony.TelephonyManager#getCarrierIdFromMccMnc(String)
These are what prevents me from simple adding a generic build.gradle and running it through the gradle toolchain. The build artifact is a simple APK file, with which I would then patch the system image.
So how would I build this app without needing the entire AOSP source code (just the actual dependencies, and dependencies of dependencies etc.)?
Not a complete answer (yet), but some snippets I was able to find out so far:
Downloading just individual projects from the source tree
This is what I have been able to piece together from various instructions—untested so far:
mkdir <dir>
cd <dir>
repo init -u <url> -b <branch>
repo sync <project-list>
Where
<dir> is a dir on your system where you are going to keep the source
<url> is the URL for your build, e.g.:
AOSP: https://android.googlesource.com/platform/manifest
LineageOS: https://github.com/LineageOS/android.git
<branch> is the branch to check out (omit -b to check out the master branch)
AOSP branches are found at https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds
LineageOS branches are found at https://github.com/LineageOS/android/branches
<project-list> is a list of projects to fetch (if omitted, repo sync will fetch the entire source tree). Projects can be indicated either by their name or by their path within the source tree, separated with spaces.
(source 1, source 2, source 3, source 4)
Figuring out which repos you need can get tricky, and if your dependencies have further dependencies, this can become a time-comsuming process.
Also I haven’t figured out if the next step actually works with a source tree stripped down in this manner.
Building individual projects
If you just need to build a single project, you can use mmm for that:
. build/envsetup.sh
lunch
mmm path/to/the/project/
(source)
I have used this command to archive a git source code:
git archive --format=tgz -o ~/myproj-20180402.tgz --prefix=myproj/ master
Are there same/similar way to archive a AOSP repo branch or tag. How to do ? Any help would be greatly appreciated.
AOSP code is not a single git project, it's actually many more (hundreds). So there is not a git command per-se.
What you could do is use repo this way:
repo forall -j16 "<your-git-command-1; your-git-command-2>"
So for the exact git command you proposed it would be:
repo forall -j16 "git archive --format=tgz -o ~/myproj-20180402.tgz --prefix=myproj/ master"
But keep in mind there is not a single git project, so you will end up with hundreds of archives, each inside it's root dir. Check the manifest you sync for a full list of projects and it's location locally.
I executed these commands on intranet server (initialized empty Git repository in /home/git/project/):
mkdir project
cd project
git init --bare
Then I executed these commands on client:
git clone git#server:project
Then copied android source code (directory: alps/) to project
git status
git add .
git commit -m "xxx"
git push origin master
When this operation was done, I deleted the project and cloned it from server again. Some files were lost (e.g.:some .mk files in alps/external/chromium_org)
Why did it happen?
Most probably you've got the .mk extension in your .gitignore file. The file is in the project root directory. It may be hidden.
If you're sure that you want .mk files under source control, find a line with it in the .gitignore and delete that line.
Then:
git add .gitignore
git commit -m'removed .mk from .gitignore'
git add --all
git commit -m'tracked .mk files'
By the way, a good sample of .gitignore for Android can be found in GitHub default .gitignore files.
The Android source is a large hierarchy of git repositories. They are managed by a custom script called repo. Repo determines which git repositories to manage using a manifest.xml. The manifest.xml of Android is hosted in a git repository along with all the other git repositories.
How is this repository managed in Android? Specifically how are the different branches and the different files hosted in each branch organised?
First, repo init creates the .repo directory, clones the git repository https://android.googlesource.com/tools/repo to .repo/repo, and the git repository specified with the -u option to a bare repository at .repo/manifests.git. After that, it creates the .repo/manifests directory, converts it into a git repository through creating symbolic links from .repo/manifests/.git to .repo/manifests.git. It then checks out the branch specified in -b, and creates a symbolic link .repo/manifest.xml pointing to the specified file (-m option) in .repo/manifests, by default .repo/manifests/default.xml.
Roughly as follows:
repo init -u $URL -b $BRANCH -m $MANIFEST
--------------------
mkdir .repo; cd .repo
git clone https://android.googlesource.com/tools/repo
git clone --bare $URL manifests.git
mkdir -p manifests/.git; cd manifests/.git
for i in ../../manifests.git/*; do ln -s $ı .; done
cd ..
git checkout $BRANCH -- .
cd ..
ln -s manifests/$MANIFEST manifest.xml
You can trace what really happens with repo --trace init ...
Then, repo sync clones git repositories to .repo/projects for each project in manifest.xml and local_manifest.xml, creates working directories with .git having symlinks to the corresponding bare repository, checks out the branch specified in the manifest, and updates .repo/project.list. The case where the projects are already there is slightly different, essentially performing a git pull --rebase.
At the root of the repo is a hidden directory named ".repo". Inside you will find a git project named "manifests" which usually contains a file named "default.xml". This file contains information about all the projects and where their associated git repositories are located. This file is also versioned thus when you use the "repo init -b XYZ" command it will be reverted and you can back to older branches that may have added/removed git projects compared to the head.
Here is a link to the git repo document describing the manifest format:
https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.md
I have downloaded Android source code but I don't find the "Kernel Directory" in the top level directory of the source code tree. Is it ok? Or is it missing?
/mydroid$ find . -name kernel
./bionic/libc/kernel
./vendor/htc/sapphire-open/kernel
./vendor/htc/dream-open/kernel
./dalvik/libcore/luni-kernel/src/test/java/tests/api/org/apache/harmony/kernel
./dalvik/libcore/luni-kernel/src/main/java/org/apache/harmony/kernel
./prebuilt/android-arm/kernel
./prebuilt/android-x86/kernel
./device/htc/passion/kernel
default.xml in https://android.googlesource.com/platform/manifest does not point to the kernel, so repo would not automatically download it. Most kernel trees are specific to machines anyway.
See http://elinux.org/Android_Kernel_Download for information on getting the right kernel.
git clone https://android.googlesource.com/kernel/common.git kernel