如何解决 Flutter 调试问题? (Unix,ubuntu)

How to solve Flutter debuging problems ? (Unix, ubuntu)

我正在使用visual studio并且我已经在上面安装了flutter和dart,当我测试调试时很长时间后出现错误。 我正在使用 Ubuntu:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:    20.04
Codename:   focal

当我 运行 flutter doctor 我得到了:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.1, on Linux, locale en_US.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2020.3)
[✓] Connected device (1 available)

! Doctor found issues in 2 categories.

我得到的错误:

Installing Android SDK Platform 30 in /home/mea/Android/Sdk/platforms/android-30
"Install Android SDK Platform 30 (revision: 3)" complete.
"Install Android SDK Platform 30 (revision: 3)" finished.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not download x86_debug-1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718.jar (io.flutter:x86_debug:1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718)
      > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718/x86_debug-1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718.jar'.
         > Could not GET 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718/x86_debug-1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718.jar'.
            > Connect to storage.googleapis.com:443 [storage.googleapis.com/142.250.200.112, storage.googleapis.com/172.217.17.16, storage.googleapis.com/142.250.201.80, storage.googleapis.com/172.217.168.176, storage.googleapis.com/142.250.200.80, storage.googleapis.com/216.58.215.176, storage.googleapis.com/216.58.215.144, storage.googleapis.com/142.250.184.16, storage.googleapis.com/216.58.209.80, storage.googleapis.com/142.250.185.16, storage.googleapis.com/142.250.200.144, storage.googleapis.com/142.250.184.176, storage.googleapis.com/2a00:1450:4003:80a:0:0:0:2010, storage.googleapis.com/2a00:1450:4003:80c:0:0:0:2010, storage.googleapis.com/2a00:1450:4003:802:0:0:0:2010, storage.googleapis.com/2a00:1450:4003:801:0:0:0:2010] failed: Network is unreachable (connect failed)
   > Could not download x86_64_debug-1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718.jar (io.flutter:x86_64_debug:1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718)
      > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_debug/1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718/x86_64_debug-1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718.jar'.
         > Could not GET 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_debug/1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718/x86_64_debug-1.0.0-0fdb562ac8068ce3dda6b69aca3f355f4d1d2718.jar'.
            > Connect to storage.googleapis.com:443 [storage.googleapis.com/142.250.200.112, storage.googleapis.com/172.217.17.16, storage.googleapis.com/142.250.201.80, storage.googleapis.com/172.217.168.176, storage.googleapis.com/142.250.200.80, storage.googleapis.com/216.58.215.176, storage.googleapis.com/216.58.215.144, storage.googleapis.com/142.250.184.16, storage.googleapis.com/216.58.209.80, storage.googleapis.com/142.250.185.16, storage.googleapis.com/142.250.200.144, storage.googleapis.com/142.250.184.176, storage.googleapis.com/2a00:1450:4003:80a:0:0:0:2010, storage.googleapis.com/2a00:1450:4003:80c:0:0:0:2010, storage.googleapis.com/2a00:1450:4003:802:0:0:0:2010, storage.googleapis.com/2a00:1450:4003:801:0:0:0:2010] failed: Network is unreachable (connect failed)

* 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 9m 30s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

我接受了许可证,但它不起作用。

运行 在终端中输入并按几次 y 接受所有选项。

flutter doctor --android-licenses

我找到了解决方案(针对使用 java11 的 ubuntu 20.04 用户)

java11 在 android 开发中无法正常工作,所以我通过删除 java 存储库将其卸载(因为 Java 11 已删除 Java EE)在这里阅读:JDK 11: End of the road for Java EE modules

卸载java11

如果不确定安装位置运行 查找命令:

sudo find / -type d -name jdk-17

删除它:

sudo rm -r jdk-17/

然后从 /usr/bin/ 目录中删除 java 和 javac

PC-NAME1:/usr/bin$ sudo rm java javac

安装java8

运行 快照命令:

sudo apt install -y openjdk-8-jdk

if java -version 不起作用,输出看起来像:

$java --version

Command 'java' not found, but can be installed with:

sudo apt install default-jre              # version 2:1.11-72, or
sudo apt install openjdk-11-jre-headless  # version 11.0.11+9-0ubuntu2~20.04
sudo apt install openjdk-16-jre-headless  # version 16.0.1+9-1~20.04
sudo apt install openjdk-8-jre-headless   # version 8u292-b10-0ubuntu1~20.04
sudo apt install openjdk-13-jre-headless  # version 13.0.7+5-0ubuntu1~20.04
sudo apt install openjdk-17-jre-headless  # version 17+35-1~20.04

在这种情况下,您必须通过 运行ning java 配置命令切换 jdk:

sudo update-alternatives --config java

[sudo] password for mea: 
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode

并通过将每个 java 更改为 javac 来为 javac 做同样的事情。

然后安装 cmdline-tools :

安装命令行工具

运行 /home/machine_name/Android/Sdk/tools/bin/sdkmanager --install "cmdline-tools;latest"

接受android许可

最后 运行 知道接受许可的命令:

flutter doctor --android-licenses

按 y 直到结束。