MacOS 系统 Flutter开发Android 环境配置

上节我们已经把 开发工具准备齐全,并可以进行Flutter的web开发,本节将做安卓开发环境进行详细说明

  • 接上节这里先说下,系统环境  MacOS14 (Sonoma) 芯片 Apple M3

执行命令:flutter doctor  提示如下:

[!] Flutter (Channel stable, 3.13.9, on macOS 14.1.1 23B2082 darwin-arm64, locale en-CN)
    ✗ Downloaded executables cannot execute on host.
      See https://github.com/flutter/flutter/issues/6207 for more information.
      Flutter requires the Rosetta translation environment on ARM Macs. Try running:
        sudo softwareupdate --install-rosetta --agree-to-license
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[!] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your
        plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install see https://guides.cocoapods.org/using/getting-started.html#installation for
      instructions.

这里需要说明的是 此时还与开发配置无关,仅仅是检查开发工具是否符合要求;下面就提示做详细说明:

1、Downloaded executables cannot execute on host.

上节我们说了 用 usrname -a 查看 芯片型号以便下载对应的 flutter SDK,此处提示 SDK要在 ARM 架构芯片上运行 需要执行命令: sudo softwareupdate --install-rosetta --agree-to-license,按照提示输入命令即可,所以输入

sudo softwareupdate --install-rosetta --agree-to-license

解决第一个问题,接着提示  

2、✗ cmdline-tools component is missing  ✗ Android license status unknown. 对于第一个可能有些莫名其妙,提示是  Run `path/to/sdkmanager --install "cmdline-tools;latest"` 难道是执行命令 ?

非也!即便你命令行到 Android SDK目录 去执行那个提示命令也会提示错误,正确方式打开 上节我们安装好的 Android Studio,下载安装 cmdline-tools;  具体先看图

MacOS 系统 Flutter开发Android 环境配置_第1张图片

打开 Android Studio ,找到“设置”选项,按图所示 找到 Android SDK 选择,然后在右边的选项卡中选中

Android SDK Command-line Tools (latest)

⚠️勾选第三项 ,当然 Flutter开发 移动端 大部分时间也会用到 NDK,你也可以一次安装好,不过这不是必须根据项目需要选择安装;这是一个漫长的下载安装过程,取决于你的网络状况;

Command-line Tools 下载安装完成后,执行命令

#Command-line Tools 安装成功后 执行命令
flutter doctor --android-licenses

一系列的同意条款,按提示操作即可!✅完成以上操作后

再次执行 flutter doctor 结果如下:

 MacOS 下 flutter 开发环境 Android安卓部分基本配置完毕,进入项目命令行 flutter build apk 试试

joson@MacBook ios % flutter build apk
Changing current working directory to: /Users/joson/Joson/

Running Gradle task 'assembleRelease'...  

#这里仅测试安装环境 是否正确 ,如果不报错即可;结果事与愿违,以下是网络问题@! 我想在天朝也许最为常见的问题了吧,相信你看到这应该知道怎么解决了吧@ 科学上网或者更改拉去镜像库,不懂的自行百度
Exception in thread "main" java.net.ConnectException: Operation timed out
	at java.base/sun.nio.ch.Net.connect0(Native Method)
	at java.base/sun.nio.ch.Net.connect(Unknown Source)
	at java.base/sun.nio.ch.Net.connect(Unknown Source)
	at java.base/sun.nio.ch.NioSocketImpl.connect(Unknown Source)
	at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
	at java.base/java.net.Socket.connect(Unknown Source)
	at java.base/sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
	at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(Unknown Source)
	at java.base/sun.net.NetworkClient.doConnect(Unknown Source)
	at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source)
	at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source)
	at java.base/sun.net.www.protocol.https.HttpsClient.(Unknown Source)
	at java.base/sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
	at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
	at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect0(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
	at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
	at org.gradle.wrapper.Download.download(Download.java:44)
	at org.gradle.wrapper.Install$1.call(Install.java:61)
	at org.gradle.wrapper.Install$1.call(Install.java:48)
	at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
	at org.gradle.wrapper.Install.createDist(Install.java:48)
	at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
	at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Running Gradle task 'assembleRelease'...                          187.5s
Gradle task assembleRelease failed with exit code 1

打开Android Studio 错误提示一样 

MacOS 系统 Flutter开发Android 环境配置_第2张图片

由于喜欢用VsCode 作为编辑器,然后命令行方式调试和编译 ,所以很少直接用的 Android Studio,问题很明显了是网络问题,同时打开 Android Studio 一样提示无法下载文件;

百度 关键词 Maven Gradle,解决吧,具体可以参考 这篇文章​​​​​​​

下一节:MacOS 14 系统 XCode15、 Flutter 开发 IOS​​​​​​​

你可能感兴趣的:(macos,android,flutter)