Mac下搭建Flutter开发环境

Flutter中文网-入门: 在macOS上搭建Flutter开发环境

安装过程中遇到的错误:


  • flutter doctor遇到Android SDK is missing command line tools;
[-] Android toolchain - develop for Android devices
    • Android SDK at /Users/obiwan/Library/Android/sdk
    ✗ Android SDK is missing command line tools; download from https://goo.gl/XxQghQ
    • Try re-installing or updating your Android SDK,
      visit https://flutter.io/setup/#android-setup for detailed instructions.

这个一般是因为Android Studio版本太低或者没有ANDROID_HOME环境变量等。先将Android Studio更新到最新版本,如果还有问题查看下ANDROID_HOME环境变量配置。

  export PATH=/Users/用户名/Documents/flutter/flutter/bin:$PATH
  export ANDROID_HOME="/Users/用户名/Documents/android_sdk" //android sdk目录,替换为你自己的即可
  export PATH=${PATH}:${ANDROID_HOME}/tools
  export PATH=${PATH}:${ANDROID_HOME}/platform-tools
  export PUB_HOSTED_URL=https://pub.flutter-io.cn
  export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

  • 执行/Users/****/Documents/android/sdk/tools/bin/sdkmanager --update 错误
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 5 more

查询相关资料是因为jdk版本太高,最后重新装了一下1.8的jdk才解决问题。

重新安装jdk:

  • 打开Java所在目录;

    open /Library/Java/JavaVirtualMachines/

  • 删除已安装版本的jdk;

    sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk

  • 下载安装JDK1.8;
  • 查找并设置JAVA_HOME,参考:在Mac中如何正确地设置JAVA_HOME;
  • 重启终点,重新运行/Users/****/Documents/android/sdk/tools/bin/sdkmanager --update

你可能感兴趣的:(Mac下搭建Flutter开发环境)