参考文档:
基础环境配置
安装 JDK
从官网下载 jdk 安装包
安装 JDK
1
2sudo mkdir -p /usr/local/java
sudo tar xf jdk-11.0.18_linux-x64_bin.tar.gz -C /usr/local/java/配置环境变量
1
2
3
4
5
6
7
8
9sudo cat > /etc/profile.d/java.sh <<EOF
#!/bin/bash
export JAVA_HOME=/usr/local/java/jdk-11.0.18
export CLASSPATH=\$CLASSPATH:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
source /etc/profile.d/java.sh验证 java 版本
1
2
3
4$ java -version
java version "11.0.18" 2023-01-17 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.18+9-LTS-195)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.18+9-LTS-195, mixed mode)
安装依赖
执行以下命令安装命令行工具
1
sudo apt-get install git curl unzip zip xz-utils file
安装 libglu1-mesa 公共库
1
2sudo apt-get install libglu1-mesa
sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev
安装 Flutter
下载 flutter SDK
1
wget https://storage.flutter-io.cn/flutter_infra_release/releases/stable/linux/flutter_linux_3.7.12-stable.tar.xz
解压 flutter SDK
1
2mkdir ~/development
tar -xf flutter_linux_3.7.12-stable.tar.xz -C ~/development配置环境变量
1
2
3
4
5
6
7
8cat > ~/.bash_profile <<EOF
#!/bin/bash
export FLUTTER_HOME=\$HOME/development/flutter
export PATH=\$PATH:\$FLUTTER_HOME/bin
export FLUTTER_STORAGE_BASE_URL=https://mirrors.tuna.tsinghua.edu.cn/flutter
export PUB_HOSTED_URL=https://mirrors.tuna.tsinghua.edu.cn/dart-pub
EOF运行
flutter doctor
命令查看是否还有缺失的依赖需要安装,根据结果安装这些依赖以完成设置1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45$ flutter doctor -v
Flutter assets will be downloaded from https://mirrors.tuna.tsinghua.edu.cn/flutter. Make sure you trust this source!
[✓] Flutter (Channel stable, 3.7.12, on Ubuntu 22.04.2 LTS 5.15.0-71-generic, locale C.UTF-8)
• Flutter version 3.7.12 on channel stable at /home/deployer/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 4d9e56e694 (8 days ago), 2023-04-17 21:47:46 -0400
• Engine revision 1a65d409c7
• Dart version 2.19.6
• DevTools version 2.20.1
• Pub download mirror https://mirrors.tuna.tsinghua.edu.cn/dart-pub
• Flutter download mirror https://mirrors.tuna.tsinghua.edu.cn/flutter
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✗] Linux toolchain - develop for Linux desktop
✗ clang++ is required for Linux development.
It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from https://releases.llvm.org/
✗ CMake is required for Linux development.
It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from https://cmake.org/download/
✗ ninja is required for Linux development.
It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from https://github.com/ninja-build/ninja/releases
✗ pkg-config is required for Linux development.
It is likely available from your distribution (e.g.: apt install pkg-config), or can be downloaded from https://www.freedesktop.org/wiki/Software/pkg-config/
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
[✓] Connected device (1 available)
• Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.2 LTS 5.15.0-71-generic
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 4 categories.
安装 Android 工具链
从 Android Studio 下载页面中下载最新的
command line tools only
软件包将下载的压缩包解压到
~/development/android_sdk
目录中1
2mkdir -p ~/development/android_sdk
unzip commandlinetools-linux-9477386_latest.zip -d ~/development/android_sdk/在解压缩的
cmdline-tools
目录中,创建一个名为latest
的子目录,将原始cmdline-tools
目录内容(包括 lib 目录、bin 目录、NOTICE.txt 文件和 source.properties 文件)移动到新创建的 latest 目录中。现在,您就可以从这个位置使用命令行工具了。配置环境变量
1
2
3
4
5
6cat >> ~/.bash_profile <<EOF
export ANDROID_HOME=\$HOME/development/android_sdk
export PATH=\$PATH:\$ANDROID_HOME/cmdline-tools/latest/bin
EOF查看 已安装的包 和 有效的包, 命令格式:
sdkmanager --list
1
2
3
4
5
6
7
8
9
10
11sdkmanager --list
[=======================================] 100% Computing updates...
Available Packages:
Path | Version | Description
------- | ------- | -------
add-ons;addon-google_apis-google-15 | 3 | Google APIs
add-ons;addon-google_apis-google-16 | 4 | Google APIs
add-ons;addon-google_apis-google-17 | 4 | Google APIs
add-ons;addon-google_apis-google-18 | 4 | Google APIs
... 省略 N 行 ...安装 Android SDK 软件包,这里至少需要安装三个包: platform-tools、 build-tools、 platforms
1
sdkmanager "platform-tools" "build-tools;30.0.3" "platforms;android-33"
- 查看已安装的包
1
2
3
4
5
6
7
8
9
10$ sdkmanager --list_installed
[=======================================] 100% Fetch remote repository...
Installed packages:
Path | Version | Description | Location
------- | ------- | ------- | -------
build-tools;30.0.3 | 30.0.3 | Android SDK Build-Tools 30.0.3 | build-tools/30.0.3
emulator | 32.1.12 | Android Emulator | emulator
patcher;v4 | 1 | SDK Patch Applier v4 | patcher/v4
platform-tools | 34.0.1 | Android SDK Platform-Tools | platform-tools
platforms;android-33 | 2 | Android SDK Platform 33 | platforms/android-33- sdk 以及编译工具存放目录如下
1
2
3
4
5
6
7
8
9
10
11
12
13$ tree -L 2 development/
development/
└── android_sdk
├── build-tools
├── cmdline-tools
├── emulator
├── licenses
├── patcher
├── platforms
├── platform-tools
└── tools
9 directories, 0 files检查 flutter 环境
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44$ flutter doctor -v
Flutter assets will be downloaded from https://mirrors.tuna.tsinghua.edu.cn/flutter. Make sure you trust this source!
[✓] Flutter (Channel stable, 3.7.12, on CentOS Linux 7 (Core) 3.10.0-1062.el7.x86_64, locale en_US.UTF-8)
• Flutter version 3.7.12 on channel stable at /usr/local/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 4d9e56e694 (5 days ago), 2023-04-17 21:47:46 -0400
• Engine revision 1a65d409c7
• Dart version 2.19.6
• DevTools version 2.20.1
• Pub download mirror https://mirrors.tuna.tsinghua.edu.cn/dart-pub
• Flutter download mirror https://mirrors.tuna.tsinghua.edu.cn/flutter
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /home/deployer/development/android_sdk
• Platform android-33, build-tools 30.0.3
• ANDROID_HOME = /home/deployer/development/android_sdk
• Java binary at: /usr/local/java/jdk-11.0.18/bin/java
• Java version Java(TM) SE Runtime Environment 18.9 (build 11.0.18+9-LTS-195)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✗] Linux toolchain - develop for Linux desktop
✗ clang++ is required for Linux development.
It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from https://releases.llvm.org/
✗ CMake is required for Linux development.
It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from https://cmake.org/download/
✗ ninja is required for Linux development.
It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from https://github.com/ninja-build/ninja/releases
• pkg-config version 0.27.1
✗ pkg-config 0.29.0 or later is required.
✗ GTK 3.0 development libraries are required for Linux development.
They are likely available from your distribution (e.g.: apt install libgtk-3-dev)
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
[✓] Connected device (1 available)
• Linux (desktop) • linux • linux-x64 • CentOS Linux 7 (Core) 3.10.0-1062.el7.x86_64
[✓] HTTP Host Availability
• All required HTTP hosts are available- 运行以下命令同意 Android licenses
1
flutter doctor --android-licenses
安装 Chrome
下载 deb 文件
1
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
安装 deb 文件
1
sudo apt install ./google-chrome-stable_current_amd64.deb
查看安装版本
1
google-chrome-stable
安装 Linux 工具链
运行以下命令进行安装其他 Linux 需要的内容
1
sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev
再次检查 flutter 状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41$ flutter doctor -v
Flutter assets will be downloaded from https://mirrors.tuna.tsinghua.edu.cn/flutter. Make sure you trust this source!
[✓] Flutter (Channel stable, 3.7.12, on Ubuntu 22.04.2 LTS 5.15.0-71-generic, locale C.UTF-8)
• Flutter version 3.7.12 on channel stable at /home/deployer/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 4d9e56e694 (8 days ago), 2023-04-17 21:47:46 -0400
• Engine revision 1a65d409c7
• Dart version 2.19.6
• DevTools version 2.20.1
• Pub download mirror https://mirrors.tuna.tsinghua.edu.cn/dart-pub
• Flutter download mirror https://mirrors.tuna.tsinghua.edu.cn/flutter
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /home/deployer/development/android_sdk
• Platform android-33, build-tools 30.0.3
• ANDROID_HOME = /home/deployer/development/android_sdk
• Java binary at: /usr/local/java/jdk-11.0.18/bin/java
• Java version Java(TM) SE Runtime Environment 18.9 (build 11.0.18+9-LTS-195)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop
• Ubuntu clang version 14.0.0-1ubuntu1
• cmake version 3.22.1
• ninja version 1.10.1
• pkg-config version 0.29.2
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
[✓] Connected device (2 available)
• Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.2 LTS 5.15.0-71-generic
• Chrome (web) • chrome • web-javascript • Google Chrome 112.0.5615.165
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 1 category.编译环境不需要安装 Android Studio 工具,所以可以忽略该警告