MacOS 系统 Flutter开发Android 环境配置

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

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

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

bash 复制代码
[!] 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,按照提示输入命令即可,所以输入

bash 复制代码
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; 具体先看图

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

|---|---|---|
| Android SDK Command-line Tools (latest) |||

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

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

bash 复制代码
#Command-line Tools 安装成功后 执行命令
flutter doctor --android-licenses

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

再次执行 flutter doctor 结果如下:

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

bash 复制代码
joson@MacBook ios % flutter build apk
Changing current working directory to: /Users/joson/Joson/

Running Gradle task 'assembleRelease'...  

#这里仅测试安装环境 是否正确 ,如果不报错即可;结果事与愿违,以下是网络问题@! 我想在天朝也许最为常见的问题了吧,相信你看到这应该知道怎么解决了吧@ 科学上网或者更改拉去镜像库,不懂的自行百度
bash 复制代码
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.<init>(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 错误提示一样

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

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

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

相关推荐
风和先行31 分钟前
adb 命令查看设备存储占用情况
android·adb
AaVictory.1 小时前
Android 开发 Java中 list实现 按照时间格式 yyyy-MM-dd HH:mm 顺序
android·java·list
似霰2 小时前
安卓智能指针sp、wp、RefBase浅析
android·c++·binder
大风起兮云飞扬丶2 小时前
Android——网络请求
android
干一行,爱一行2 小时前
android camera data -> surface 显示
android
断墨先生3 小时前
uniapp—android原生插件开发(3Android真机调试)
android·uni-app
Java小白笔记3 小时前
Mac中安装homebrew
macos
无极程序员4 小时前
PHP常量
android·ide·android studio
萌面小侠Plus5 小时前
Android笔记(三十三):封装设备性能级别判断工具——低端机还是高端机
android·性能优化·kotlin·工具类·低端机
慢慢成长的码农5 小时前
Android Profiler 内存分析
android