laohoo@laohoo-Inspiron-7559:~/Desktop$ flutter doctor -v Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! Running "flutter pub get"in flutter_tools... 4.9s [✓] Flutter (Channel stable, 3.3.4, on Linux Mint 21 5.15.0-48-generic, locale en_US.UTF-8) • Flutter version 3.3.4 on channel stable at /home/laohoo/AppData/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision eb6d86ee27 (3 days ago), 2022-10-04 22:31:45 -0700 • Engine revision c08d7d5efc • Dart version 2.18.2 • DevTools version 2.15.0 • Pub download mirror https://pub.flutter-io.cn • Flutter download mirror https://storage.flutter-io.cn
[✗] 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 • Ubuntu clang version 14.0.0-1ubuntu1 • cmake version 3.22.1 • ninja version 1.10.1 • pkg-config version 0.29.2 ✗ 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).
[✓] VS Code (version 1.72.0) • VS Code at /usr/share/code • Flutter extension version 3.50.0
[✓] Connected device (1 available) • Linux (desktop) • linux • linux-x64 • Linux Mint 21 5.15.0-48-generic
[✓] HTTP Host Availability • All required HTTP hosts are available
laohoo@laohoo-Inspiron-7559:~/Desktop$ sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev Reading package lists... Done Building dependency tree... Done Reading state information... Done liblzma-dev is already the newest version (5.2.5-2ubuntu1). pkg-config is already the newest version (0.29.2-1ubuntu3). clang is already the newest version (1:14.0-55~exp2). ninja-build is already the newest version (1.10.1-1). cmake is already the newest version (3.22.1-1ubuntu1.22.04.1).
Launching lib/main.dart on Linux in debug mode... CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message): The C++ compiler
laohoo@laohoo-Inspiron-7559:~/Desktop$ flutter doctor -v Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! [✓] Flutter (Channel stable, 3.3.4, on Linux Mint 21 5.15.0-48-generic, locale en_US.UTF-8) • Flutter version 3.3.4 on channel stable at /home/laohoo/AppData/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision eb6d86ee27 (3 days ago), 2022-10-04 22:31:45 -0700 • Engine revision c08d7d5efc • Dart version 2.18.2 • DevTools version 2.15.0 • Pub download mirror https://pub.flutter-io.cn • Flutter download mirror https://storage.flutter-io.cn
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /home/laohoo/AppData/android_sdk • Platform android-33, build-tools 31.0.0 • ANDROID_HOME = /home/laohoo/AppData/android_sdk • Java binary at: /usr/bin/java • Java version OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu122.04) ! 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 • 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).
[✓] VS Code (version 1.72.0) • VS Code at /usr/share/code • Flutter extension version 3.50.0
[✓] Connected device (1 available) • Linux (desktop) • linux • linux-x64 • Linux Mint 21 5.15.0-48-generic
[✓] HTTP Host Availability • All required HTTP hosts are available
! Doctor found issues in 3 categories.
Android 工具链变成感叹号, 表示还没有完全解决问题
1 2 3 4 5 6 7
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /home/laohoo/AppData/android_sdk • Platform android-33, build-tools 31.0.0 • ANDROID_HOME = /home/laohoo/AppData/android_sdk • Java binary at: /usr/bin/java • Java version OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu122.04) ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses: 还没有接受 Andorid 的协议, 执行命令: flutter doctor --android-licenses
laohoo@laohoo-Inspiron-7559:~/Desktop$ flutter doctor --android-licenses Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! 5 of 6 SDK package licenses not accepted. 100% Computing updates... Review licenses that have not been accepted (y/N)? y
laohoo@laohoo-Inspiron-7559:~/Desktop$ flutter doctor -v Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! [✓] Flutter (Channel stable, 3.3.4, on Linux Mint 21 5.15.0-48-generic, locale en_US.UTF-8) • Flutter version 3.3.4 on channel stable at /home/laohoo/AppData/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision eb6d86ee27 (3 days ago), 2022-10-04 22:31:45 -0700 • Engine revision c08d7d5efc • Dart version 2.18.2 • DevTools version 2.15.0 • Pub download mirror https://pub.flutter-io.cn • Flutter download mirror https://storage.flutter-io.cn
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /home/laohoo/AppData/android_sdk • Platform android-33, build-tools 31.0.0 • ANDROID_HOME = /home/laohoo/AppData/android_sdk • Java binary at: /usr/bin/java • Java version OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu122.04) • All Android licenses accepted.
[✗] 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 • 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).
[✓] VS Code (version 1.72.0) • VS Code at /usr/share/code • Flutter extension version 3.50.0
[✓] Connected device (1 available) • Linux (desktop) • linux • linux-x64 • Linux Mint 21 5.15.0-48-generic
[✓] HTTP Host Availability • All required HTTP hosts are available
laohoo@laohoo-Inspiron-7559:~/Desktop$ sudo apt install cpu-checker [sudo] password for laohoo: Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: msr-tools The following NEW packages will be installed: cpu-checker msr-tools 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 17.1 kB of archives. After this operation, 67.6 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://mirrors.aliyun.com/ubuntu jammy/main amd64 msr-tools amd64 1.3-4 [10.3 kB] Get:2 http://mirrors.aliyun.com/ubuntu jammy/main amd64 cpu-checker amd64 0.7-1.3build1 [6,800 B] Fetched 17.1 kB in 0s (187 kB/s) Selecting previously unselected package msr-tools. (Reading database ... 295693 files and directories currently installed.) Preparing to unpack .../msr-tools_1.3-4_amd64.deb ... Unpacking msr-tools (1.3-4) ... Selecting previously unselected package cpu-checker. Preparing to unpack .../cpu-checker_0.7-1.3build1_amd64.deb ... Unpacking cpu-checker (0.7-1.3build1) ... Setting up msr-tools (1.3-4) ... Setting up cpu-checker (0.7-1.3build1) ... Processing triggers for man-db (2.10.2-1) ...
laohoo@laohoo-Inspiron-7559:~/Desktop$ avdmanager create avd -n huawei -k "system-images;android-31;default;x86_64" Auto-selecting single ABI x86_64========] 100% Fetch remote repository... Do you wish to create a custom hardware profile? [no]
此处为方便回答 no, yes 的选项太多了, 回答了70几项还没有结束, 最关键是还看不懂.
huawei 是模拟器的名字
"system-images;android-31;default;x86_64" 是模拟器镜像名
启动模拟器
查看当前已经建好的模拟器: avdmanager list avd, 命令执行结果如下:
1 2 3 4 5 6 7
aohoo@laohoo-Inspiron-7559:~/Desktop$ avdmanager list avd Available Android Virtual Devices: Name: huawei Path: /home/laohoo/.android/avd/huawei.avd Target: Default Android System Image Based on: Android 12.0 (S) Tag/ABI: default/x86_64 Sdcard: 512 MB
laohoo@laohoo-Inspiron-7559:~/Desktop$ emulator -avd huawei INFO | Android emulator version 31.3.11.0 (build_id 9058569) (CL:N/A) emulator: INFO: Found systemPath /home/laohoo/AppData/android_sdk/system-images/android-31/default/x86_64/ INFO | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag. WARNING | unexpected system image feature string, emulator might not function correctly, please try updating the emulator. WARNING | cannot add library /home/laohoo/AppData/android_sdk/emulator/qemu/linux-x86_64/lib64/vulkan/libvulkan.so: failed INFO | added library /home/laohoo/AppData/android_sdk/emulator/lib64/vulkan/libvulkan.so MESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0
INFO | configAndStartRenderer: setting vsync to 60 hz INFO | Sending adb public key [QAAAACPLTUN1QxgyNvTke2ABrlB0HlUVCDlT/YFb/fooM9bItTYvgmZ9+lCSgqgYyQxmkF+TOiBom0UMQ8iidd9qr0yLKd+12SVI5GxZLch4gE7KY+Dm/7MRLso5k6XsMWu4wusaWXIsShzHkMh86Tx16H1OB+GqPaJA5EIjcVHiovK2mRHBz8swQ5+2xJ5fqN4oOEzCRq71se4U5ykFBLmGRSY+BGwGgfqtRAWBZFhZCzL7Jy8ten9Q1cIkOyzLOvOFAZFqdEdMmtTPjBeug1VtTUcL16wGm+PH0MsO0rOH7M7Y7WxjsETt5qXw7BnY80eAyBNCURzxXMoAtX0YBxk9NL3dAuyZmYRz+btLQ7tpYOqpO535s31I+YvQLiXW0bS23lHCBl5CTyV7COZ90BZ2tQp2N37/65nE+jplU7U4NDvA45/+uHCCeFiMR6jegepNi3YUrl9pb6ti/O2+mD3s/YP9pQ/7TokunOG9h5IXVjtdela4jKyLJer3o70PDMNFZtiebQ/8QGT/m5NGp/1wrHMyeGDCYLc5qaEexjD9QzZQyM9xOfiMK/78RBqo7FX0ihL5uMfKAQ2FFD2IQsd8FsYgIS7kzSVZuS0l/8HyBYrsgCt0mBq2A54PvPTCK/UcMdrzj2SpM5yifdEJ/PAGWtD6kwEWa9o9siYu8dBb7Zibw4mnBAEAAQA= laohoo@unknown] INFO | injectedQemuChannel! INFO | Informing listeners of injection. INFO | Rootcanal has been activated. WARNING | *** No gRPC protection active, consider launching with the -grpc-use-jwt flag.*** INFO | Started GRPC server at 127.0.0.1:8554, security: Local, auth: none INFO | Advertising in: /run/user/1000/avd/running/pid_17579.ini INFO | setDisplayConfigs w 320 h 640 dpiX 160 dpiY 160 INFO | Wait for emulator (pid 17579) 20 seconds to shutdown gracefully before kill;you can set environment variable ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL(in seconds) to change the default value (20 seconds)
INFO | Info: Sandboxing disabled by user. ((null):0, (null))
INFO | Closing down rootcanal.
创建 Flutter 项目
创建Flutter项目的命令格式: flutter create <项目名称>
项目名称 由多个单词组成时, 单词之间用下划线_分隔, 不能使用短横线 -
创建项目的命令执行过程如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
laohoo@laohoo-Inspiron-7559:~/Sources/flutter_repos$ flutter create my_store_app Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! Creating project my_store_app... Running "flutter pub get"in my_store_app... 1,992ms Wrote 127 files.
All done! In order to run your application, type:
$ cd my_store_app $ flutter run
Your application code is in my_store_app/lib/main.dart.
laohoo@laohoo-Inspiron-7559:~/Sources/flutter_repos/my_store_app$ flutter run Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! Using hardware rendering with device Android SDK built for x86 64. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering". Launching lib/main.dart on Android SDK built for x86 64 in debug mode...
FAILURE: Build failed with an exception.
* What went wrong: Execution failed for task ':app:compileDebugKotlin'. > Could not resolve all dependencies for configuration ':app:kotlinCompilerClasspath'. > Could not load module metadata from /home/laohoo/.gradle/caches/modules-2/metadata-2.97/descriptors/org.jetbrains.kotlin/kotlin-script-runtime/1.6.10/a8be1fe3b3911d3d3425fe720cf42835/descriptor.bin
* Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s Running Gradle task 'assembleDebug'... 2,548ms Exception: Gradle task assembleDebug failed with exit code 1
laohoo@laohoo-Inspiron-7559:~/Sources/flutter_repos/my_store_app$ flutter run Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! Using hardware rendering with device Android SDK built for x86 64. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering". Launching lib/main.dart on Android SDK built for x86 64 in debug mode... Running Gradle task 'assembleDebug'... 93.9s ✓ Built build/app/outputs/flutter-apk/app-debug.apk. Installing build/app/outputs/flutter-apk/app.apk... 1,034ms Syncing files to device Android SDK built for x86 64... 211ms
Flutter run key commands. r Hot reload. 🔥🔥🔥 R Hot restart. h List all available interactive commands. d Detach (terminate "flutter run" but leave application running). c Clear the screen q Quit (terminate the application on the device).
💪 Running with sound null safety 💪
An Observatory debugger and profiler on Android SDK built for x86 64 is available at: http://127.0.0.1:42339/XnPsnajGgW8=/ The Flutter DevTools debugger and profiler on Android SDK built for x86 64 is available at: http://127.0.0.1:9101?uri=http://127.0.0.1:42339/XnPsnajGgW8=/