Manifest是用于描述Android項(xiàng)目或庫(kù)的文件。它包含有關(guān)項(xiàng)目的信息,如包名、權(quán)限要求和組件(如活動(dòng)、服務(wù)和廣播接收器)。
Repo是用于管理Git倉(cāng)庫(kù)的工具。它是由Google開(kāi)發(fā)的,用于管理Android源代碼庫(kù)。Repo允許用戶(hù)將多個(gè)Git倉(cāng)庫(kù)組合在一起,并在這些倉(cāng)庫(kù)之間進(jìn)行協(xié)作。
1、git
git的詳細(xì)使用方法這里不介紹,這里只要知道git服務(wù)器端建立git倉(cāng)庫(kù)的命令:
git init --bare [倉(cāng)庫(kù)名].git
而客戶(hù)端創(chuàng)建工程、關(guān)聯(lián)遠(yuǎn)程倉(cāng)庫(kù)、第一次提交的方法是:
創(chuàng)建工程:
git init
關(guān)聯(lián)遠(yuǎn)程倉(cāng)庫(kù):
git remote add origin [遠(yuǎn)程倉(cāng)庫(kù)地址]
第一次提交:
git push -u origin master
2、repo
repo的詳細(xì)使用方法這里也不介紹,repo要用到的命令有:
repo init -u [manifest倉(cāng)庫(kù)地址] -b [branch]
初始化repo工程,會(huì)把manifest.git倉(cāng)庫(kù)拖下來(lái)。
我們搭建好自己的repo服務(wù)器后,也可以使用此命令拖下來(lái)自己的repo倉(cāng)庫(kù)。
repo sync
同步代碼。
搭建好自己的服務(wù)器后,用此命令同步時(shí)將會(huì)從自己的repo倉(cāng)庫(kù)同步代碼。
3、manifest.xml文件
這個(gè)文件要好好介紹一下,我們將會(huì)對(duì)這個(gè)文件進(jìn)行解析,解析出各個(gè)git倉(cāng)庫(kù)的服務(wù)器地址、本地路徑,并根據(jù)解析的結(jié)果創(chuàng)建和同步這些git倉(cāng)庫(kù)代碼。
1、開(kāi)頭會(huì)定義remote
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="aosp" fetch=".." review="https://android-review.googlesource.com/" />
可以設(shè)置多個(gè)remote地址,用后面的name區(qū)分。
后面可以選擇使用哪一個(gè)remote地址。
2、指定默認(rèn)參數(shù)
<default revision="master-kernel-build-2022" remote="aosp" sync-j="4" />
remote=”” 來(lái)指定使用哪一個(gè)remote地址。
revision 指定分支,從remote地址拖工程時(shí)指定拖哪個(gè)分支
sync -j 指定同步線程數(shù)
3、后面一大堆內(nèi)容都是指定遠(yuǎn)程工程路徑,以及拖下來(lái)的位置
<project path="build/kernel" name="kernel/build" >
<linkfile src="kleaf/bazel.sh" dest="tools/bazel" />
<linkfile src="kleaf/bazel.WORKSPACE" dest="WORKSPACE" />
<linkfile src="build.sh" dest="build/build.sh" />
<linkfile src="build_abi.sh" dest="build/build_abi.sh" />
<linkfile src="build_test.sh" dest="build/build_test.sh" />
<linkfile src="build_utils.sh" dest="build/build_utils.sh" />
<linkfile src="config.sh" dest="build/config.sh" />
<linkfile src="envsetup.sh" dest="build/envsetup.sh" />
<linkfile src="_setup_env.sh" dest="build/_setup_env.sh" />
<linkfile src="multi-switcher.sh" dest="build/multi-switcher.sh" />
<linkfile src="abi" dest="build/abi" />
<linkfile src="static_analysis" dest="build/static_analysis" />
</project>
<project path="common" name="kernel/common" revision="android13-5.15" >
<linkfile src="." dest=".source_date_epoch_dir" />
</project>
<project path="kernel/tests" name="kernel/tests" />
<project path="kernel/configs" name="kernel/configs" />
<project path="common-modules/virtual-device" name="kernel/common-modules/virtual-device" revision="android13-5.15" />
<project path="prebuilts/clang/host/linux-x86" name="platform/prebuilts/clang/host/linux-x86" clone-depth="1" />
<project path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8" clone-depth="1" />
<project path="prebuilts/boot-artifacts" name="platform/prebuilts/boot-artifacts" />
<project path="prebuilts/build-tools" name="platform/prebuilts/build-tools" clone-depth="1" />
<project path="prebuilts/kernel-build-tools" name="kernel/prebuilts/build-tools" clone-depth="1" />
<project path="tools/mkbootimg" name="platform/system/tools/mkbootimg" />
<project path="prebuilts/bazel/linux-x86_64" name="platform/prebuilts/bazel/linux-x86_64" clone-depth="1" />
<project path="prebuilts/jdk/jdk11" name="platform/prebuilts/jdk/jdk11" clone-depth="1" />
<project path="prebuilts/ndk-r23" name="toolchain/prebuilts/ndk/r23" clone-depth="1" />
<project path="external/bazel-skylib" name="platform/external/bazel-skylib" />
<project path="build/bazel_common_rules" name="platform/build/bazel_common_rules" />
<project path="external/stardoc" name="platform/external/stardoc" />
<project path="external/python/absl-py" name="platform/external/python/absl-py" />
</manifest>
path:本地相對(duì)路徑,可以不指定,不指定的話表示和name相同。
name:遠(yuǎn)程相對(duì)與remote地址的路徑。
version:指的是此git sync下來(lái)的branch。
groups:指定了該git存儲(chǔ)庫(kù)所屬的組
linkfile: 指定應(yīng)從 common 目錄中的文件創(chuàng)建一個(gè)名為 .source_date_epoch_dir 的目標(biāo)文件的符號(hào)鏈接。
這里的每個(gè)name就代表一個(gè)git子工程,整個(gè)android工程有很多個(gè)git子工程組成,這里指定了各個(gè)子工程相對(duì)于remote的路徑、版本、拖下來(lái)后的本地路徑。
4、總結(jié)
remote元素
設(shè)置遠(yuǎn)程git服務(wù)器的屬性,包括下面的屬性:
- name: 遠(yuǎn)程git服務(wù)器的名字,直接用于git fetch, git remote 等操作
- alias: 遠(yuǎn)程git服務(wù)器的別名,如果指定了,則會(huì)覆蓋name的設(shè)定。在一個(gè)manifest中, name不 能重名,但alias可以重名。
- fetch: 所有projects的git URL 前綴
- review: 指定Gerrit的服務(wù)器名,用于repo upload操作。如果沒(méi)有指定,則repo upload沒(méi)有效果。
一個(gè)manifest文件中可以配置多個(gè)remote元素,用于配置不同的project默認(rèn)下載指向。
default元素
設(shè)定所有projects的默認(rèn)屬性值,如果在project元素里沒(méi)有指定一個(gè)屬性,則使用default元素的屬性值。
- remote: 之前定義的某一個(gè)remote元素中name屬性值,用于指定使用哪一個(gè)遠(yuǎn)程git服務(wù)器。
- revision: git分支的名字,例如master或者refs/heads/master
- sync_j: 在repo sync中默認(rèn)并行的數(shù)目。
- sync_c: 如果設(shè)置為true,則只同步指定的分支(revision 屬性指定),而不是所有的ref內(nèi)容。
- sync_s: 如果設(shè)置為true,則會(huì)同步git的子項(xiàng)目
Example:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-730182.html
<default revision="master-kernel-build-2022" remote="aosp" sync-j="4" />
project元素
指定一個(gè)需要clone的git倉(cāng)庫(kù)。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-730182.html
- name: 唯一的名字標(biāo)識(shí)project,同時(shí)也用于生成git倉(cāng)庫(kù)的URL。格式如下:
r e m o t e f e t c h / {remote_fetch}/ remotef?etch/{project_name}.git - path: 可選的路徑。指定git clone出來(lái)的代碼存放在本地的子目錄。如果沒(méi)有指定,則以name作為子目錄名。
- remote: 指定之前在某個(gè)remote元素中的name。
- revision: 指定需要獲取的git提交點(diǎn),可以是master, refs/heads/master, tag或者SHA-1值。如果不設(shè)置的話,默認(rèn)下載當(dāng)前project,當(dāng)前分支上的最新代碼。
- groups: 列出project所屬的組,以空格或者逗號(hào)分隔多個(gè)組名。所有的project都自動(dòng)屬于"all"組。每一個(gè)project自動(dòng)屬于name:‘name’ 和path:'path’組。
例如,它自動(dòng)屬于default, name:monkeys, and path:barrel-of組。如果一個(gè)project屬于notdefault組,則,repo sync時(shí)不會(huì)下載。
sync_c: 如果設(shè)置為true,則只同步指定的分支(revision 屬性指定),而不是所有的ref內(nèi)容。 - sync_s: 如果設(shè)置為true,則會(huì)同步git的子項(xiàng)目。
- upstream: 在哪個(gè)git分支可以找到一個(gè)SHA1。用于同步revision鎖定的manifest(-c 模式)。該模式可以避免同步整個(gè)ref空間。
- annotation: 可以有多個(gè)annotation,格式為name-value pair。在repo forall 命令中這些值會(huì)導(dǎo)入到環(huán)境變量中。
- remove-project: 從內(nèi)部的manifest表中刪除指定的project。經(jīng)常用于本地的manifest文件,用戶(hù)可以替換一個(gè)project的定義。
- 子元素
到了這里,關(guān)于【Android】Manifest和Repo詳解的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!