Flutter开发环境搭建 for mac

  • step1:brew
    https://segmentfault.com/a/1190000013317511
    (brew 是 Mac 下的一个包管理工具,类似于 centos 下的 yum,可以很方便地进行安装/卸载/更新各种软件包,例如:nodejs, elasticsearch, kibana, mysql, mongodb 等等,可以用来快速搭建各种本地环境,程序员必备工具)
  • step2:Flutter SDK包
    https://flutter.io/setup-macos/
    (记住解压的地址)
  • step3:环境变量配置
    终端键入
vim ~/.bash_profile

键入(意思是配置flutter命令在任何地方都可以使用,)
pwd是Flutter下载解压的地址

export PATH=/pwd/flutter/bin:$PATH

source命令重新加载一下

source ~/.bash_profile
  • step4:开发环境配置
    检查
flutter doctor

如果有[!]x标志,表示本行检测没有通过,就需要我们设置或者安装相应的软件

  • Android studio安装
    http://www.android-studio.org/
  • 终端允许协议:flutter doctor --android-licenses 一通Y下去
  • 其他按照对应的安装插件
  • step5:Android studio
  • Configure----->plugin-----> download Flutter
  • Tools------->AVD manager(虚拟机)------>Create Virtual Device----->Nexus 5x(自选)
  • 虚拟机运行以后,点击debug按钮,让Flutter程序跑起来
  • Debug
    错误1:
 FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not download kotlin-compiler-embeddable.jar (org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.50)
      > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.3.50/kotlin-compiler-embeddable-1.3.50.jar'.
         > Read timed out

解决:
一、修改掉项目下的android目录下的build.gradle文件,把google() 和 jcenter()这两行去掉。改为阿里的链接

maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }  

二、修改Flutter SDK包下的flutter.gradle文件,这个目录要根据你的SDK存放的位置有所变化。

这一步有两种情况

1、flutter.gradle文件中repositories中是google() 和 jcenter(),

repositories{
google()
gcenter()
}

把google() 和 jcenter()这两行去掉。改为阿里的链接。

maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }  

2,flutter.gradle文件中repositories中是下图这样的

repositories {
 jcenter()
 maven {
 url 'https://dl.google.com/dl/android/maven2'
 }

把repositories 中改成

repositories {
        maven{
            url 'https://maven.aliyun.com/repository/jcenter'
        }
        maven{
            url 'http://maven.aliyun.com/nexus/content/groups/public'
        }
    }

以上两步骤之后再debug,若又出现相同报错,则在终端

扫描二维码关注公众号,回复: 10587236 查看本文章
vim ~/.bash_profile

加上两句

PUB_HOSTED_URL=https://pub.flutter-io.cn
FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

不再报错

错误2:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Could not resolve all artifacts for configuration ':app:debugCompileClasspath'.
   > Failed to transform artifact 'arm64_v8a_debug.jar (io.flutter:arm64_v8a_debug:1.0.0-2994f7e1e682039464cb25e31a78b86a3c59b695)' to match attributes {artifactType=android-classes, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for JetifyTransform: C:\Users\juwuguo\.gradle\caches\modules-2\files-2.1\io.flutter\arm64_v8a_debug\1.0.0-2994f7e1e682039464cb25e31a78b86a3c59b695\2ef393f0cfe7b16f75cbb560a12364cc448a62af\arm64_v8a_debug-1.0.0-2994f7e1e682039464cb25e31a78b86a3c59b695.jar.
         > Failed to transform 'C:\Users\juwuguo\.gradle\caches\modules-2\files-2.1\io.flutter\arm64_v8a_debug\1.0.0-2994f7e1e682039464cb25e31a78b86a3c59b695\2ef393f0cfe7b16f75cbb560a12364cc448a62af\arm64_v8a_debug-1.0.0-2994f7e1e682039464cb25e31a78b86a3c59b695.jar' using Jetifier. Reason: invalid block type. (Run with --stacktrace for more details.)
   > Failed to transform artifact 'x86_64_debug.jar (io.flutter:x86_64_debug:1.0.0-2994f7e1e682039464cb25e31a78b86a3c59b695)' to match attributes {artifactType=android-classes, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for JetifyTransform: C:\Users\juwuguo\.gradle\caches\modules-2\files-2.1\io.flutter\x86_64_debug\1.0.0-2994f7e1e682039464cb25e31a78b86a3c59b695\ce0e3fab2c8696e176c54639579d3d438a8a0925\x86_64_debug-1.0.0-2994f7e1e682039464cb25e31a78b86a3c59b695.jar.
         > Failed to transform 'C:\Users\juwuguo\.gradle\caches\modules-2\files-2.1\io.flutter\x86_64_debug\1.0.0-2994f7e1e682039464cb25e31a78b86a3c59b695\ce0e3fab2c8696e176c54639579d3d438a8a0925\x86_64_debug-1.0.0-2994f7e1e682039464cb25e31a78b86a3c59b695.jar' using Jetifier. Reason: invalid literal/length code. (Run with --stacktrace for more details.)

解决:
AndroidStudio Preference ----->Compiler----->kotlin Compiler-----> Target JVM version 把1.6改为1.8

发布了1 篇原创文章 · 获赞 1 · 访问量 30

猜你喜欢

转载自blog.csdn.net/azzaz/article/details/105364916