ubuntu20.04源码安装apollo 9.0.0

注意:以下教程amd64计算机可使用!!!

一、安装基础软件

1. 安装 Ubuntu Linux

安装 Ubuntu 18.04+ 的步骤,参见 官方安装指南。

完成安装后更新相关软件:

sudo apt-get update
sudo apt-get upgrade

2. 安装 Docker Engine

Apollo 依赖于 Docker 19.03+。安装 Docker 引擎,可用鱼香ROS一键安装。将下列代码输入到终端。然后选择8,即可安装。

wget http://fishros.com/install -O fishros && . fishros 

还可以者通过 Apollo 提供的安装脚本直接安装:

wget http://apollo-pkg-beta.bj.bcebos.com/docker_install.sh

bash docker_install.sh

这个过程可能会运行多次脚本,根据脚本提示执行即可。

二、Nvidia显卡驱动以及Nvidia container toolkit

Apollo某些模块需要GPU的支持才能够编译、运行(例如感知模块),如果需要使用此类模块,需要安装Nvidia显卡驱动以及Nvidia container toolkit以获取GPU支持。如果仅使用apollo的NPC模块,则可以无视这一步骤。虚拟机选手请跳过!!!

1.安装驱动

打开终端输入

ubuntu-drivers devices

查看显卡推荐,如下图所示,driver后带有recommended字样的即为推荐驱动(无视server、open等字眼,只需要关注版本号即可)。

 然后使用以下命令安装显卡驱动(以下nvidia-535为我个人的显卡驱动),然后重启电脑

sudo apt-get install nvidia-535

2. 安装 Nvidia container toolkit

为了在容器内获得 GPU 支持,在安装完 docker 后需要安装 NVIDIA Container Toolkit。 运行以下指令安装 NVIDIA Container Toolkit:

distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get -y update
sudo apt-get install -y nvidia-docker2

安装完毕后,需要手动重启下docker:

sudo systemctl restart docker

三、下载安装 Apollo 源码

1. 克隆 Apollo 源码

执行以下命令克隆 Apollo 源码:

# SSH 方式
git clone [email protected]:ApolloAuto/apollo.git
 
# HTTPS 方式
git clone https://github.com/ApolloAuto/apollo.git

也可将以下网址直接复制到浏览器,下载apollo-9.0.0,解压至home目录下,并重命名为apollo

https://github.com/ApolloAuto/apollo/tree/v9.0.0

2. 启动 Apollo 环境容器

在 apollo 目录下输入以下命令来启动环境容器

cd apollo
bash docker/scripts/dev_start.sh

操作成功后您将会看到如下样式的提示输出

[ OK ] Congratulations! You have successfully finished setting up Apollo Dev Environment.
[ OK ] To login into the newly created apollo_dev_michael container, please run the following command:
[ OK ]   bash docker/scripts/dev_into.sh
[ OK ] Enjoy!

3. 进入 Apollo 环境容器

在 apollo 目录下输入以下命令进入容器

bash docker/scripts/dev_into.sh

4. 编译

在容器内的 /apollo 目录下输出以下命令编译整个工程

./apollo.sh build

若需要开启编译优化,则通过以下命令进行编译

./apollo.sh build_opt

5. 启动 Apollo

启动 Dreamview+

bash scripts/bootstrap.sh start_plus

启动 Dreamview+ 之后,在浏览器输入 localhost:8888 进入 Dreamview+ 界面。

三、遇到的错误

1.rules_java下载超时

INFO] Apollo Environment Settings:
[INFO]     APOLLO_ROOT_DIR: /apollo
[INFO]     APOLLO_CACHE_DIR: /apollo/.cache
[INFO]     APOLLO_IN_DOCKER: true
[INFO]     APOLLO_VERSION: predtr-2021-12-28-463fb82f9e
[INFO]     DOCKER_IMG: 
[INFO]     APOLLO_ENV:  STAGE=dev USE_ESD_CAN=false
[INFO]     USE_GPU: USE_GPU_HOST= USE_GPU_TARGET=1
[ OK ] Running GPU build on x86_64 platform.
[WARNING] ESD CAN library supplied by ESD Electronics doesn't exist.
[WARNING] If you need ESD CAN, please refer to:
[WARNING]   third_party/can_card_library/esd_can/README.md
[INFO] Build Overview: 
[INFO]     USE_GPU: 1  [ 0 for CPU, 1 for GPU ]
[INFO]     Bazel Options: --config=gpu
[INFO]     Build Targets: //modules/... union //cyber/...
[INFO]     Disabled:      except //modules/drivers/canbus/can_client/esd/...
Starting local Bazel server and connecting to it...
WARNING: ignoring LD_PRELOAD in environment.
(00:29:33) INFO: Invocation ID: 40695d7b-c7dd-416c-b7ae-de72a1612dec
(00:29:33) INFO: Current date is 2022-01-28
(00:30:32) INFO: Repository build_bazel_rules_swift instantiated at:
  /apollo/WORKSPACE:68:16: in <toplevel>
  /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/com_github_grpc_grpc/bazel/grpc_extra_deps.bzl:38:29: in grpc_extra_deps
  /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/build_bazel_rules_apple/apple/repositories.bzl:117:11: in apple_rules_dependencies
  /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/build_bazel_rules_apple/apple/repositories.bzl:84:14: in _maybe
Repository rule http_archive defined at:
  /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
(00:30:32) INFO: Repository rules_java instantiated at:
  /apollo/WORKSPACE:68:16: in <toplevel>
  /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/com_github_grpc_grpc/bazel/grpc_extra_deps.bzl:29:18: in grpc_extra_deps
  /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/com_google_protobuf/protobuf_deps.bzl:44:21: in protobuf_deps
Repository rule http_archive defined at:
  /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
(00:30:32) WARNING: Download from https://github.com/bazelbuild/rules_java/archive/981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz failed: class java.io.IOException connect timed out
(00:30:32) ERROR: An error occurred during the fetch of repository 'rules_java':
   Traceback (most recent call last):
	File "/apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/bazel_tools/tools/build_defs/repo/http.bzl", line 111, column 45, in _http_archive_impl
		download_info = ctx.download_and_extract(
Error in download_and_extract: java.io.IOException: Error downloading [https://github.com/bazelbuild/rules_java/archive/981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz] to /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/rules_java/temp14011213055655260428/981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz: connect timed out
(00:30:32) ERROR: While resolving toolchains for target //modules/v2x/v2x_proxy/os_interface:os_interface_cpplint: invalid registered toolchain '@bazel_tools//tools/jdk:all': while parsing '@bazel_tools//tools/jdk:all': no such package '@rules_java//java': java.io.IOException: Error downloading [https://github.com/bazelbuild/rules_java/archive/981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz] to /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/rules_java/temp14011213055655260428/981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz: connect timed out
(00:30:32) ERROR: Analysis of target '//modules/v2x/v2x_proxy/os_interface:os_interface_cpplint' failed; build aborted: invalid registered toolchain '@bazel_tools//tools/jdk:all': while parsing '@bazel_tools//tools/jdk:all': no such package '@rules_java//java': java.io.IOException: Error downloading [https://github.com/bazelbuild/rules_java/archive/981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz] to /apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/rules_java/temp14011213055655260428/981f06c3d2bd10225e85209904090eb7b5fb26bd.tar.gz: connect timed out
(00:30:32) INFO: Elapsed time: 59.517s
(00:30:32) INFO: 0 processes.
(00:30:32) FAILED: Build did NOT complete successfully (595 packages loaded, 6242 targets configured)
    currently loading: @bazel_tools//tools/jdk ... (3 packages)

这个错误出现在代码编译过程。原因是docker内无法连接到这个下载地址。解决办法是更改rules_java的下载路径。首先将下面网址复制到浏览器。

https://github.com/protocolbuffers/protobuf/blob/main/protobuf_deps.bzl

找到对应的下载信息,并复制。

然后打开apollo中的索引文件,路径为~/apollo/.cache/bazel/540135163923dd7d5820f3ee4b306b32/external/com_google_protobuf/protobuf_deps.bzl,打开并找到对应的下载信息,更换为先前复制的下载信息。

(本办法可以编译通过,但无法确定对使用apollo有没有影响)

以上教程可以使apollo通过编译,由于对apollo接触的不多,所以难免会有错误,若发现错误,各位可以在评论区提出。