zoukankan      html  css  js  c++  java
  • Flutter安装

    TOC

    Flutter安装

    • 操作系统: windows7以上64位操作系统
    • 磁盘空间:大于3G,最好可以达到5G
    • 安装java
    • 安装flutter sdk
    • 虚拟机

    安装flutterSDK

    安装

    https://github.com/flutter/flutter.git
    国内镜像地址:
    https://mirrors.tuna.tsinghua.edu.cn/git/flutter-sdk.git
    码云https://gitee.com/mirrors/Flutter的:https://gitee.com/mirrors/Flutter.git
    
    建议:
    使用码云的git
    使用分支:stable

    配置环境变量

    • path:将flutter的bin地址添加到环境变量的path中;
    • 添加flutter镜像等配置FLUTTER_STORAGE_BASE_URLPUB_HOSTED_URL;

    中国库

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

    清华

    PUB_HOSTED_URL:https://mirrors.tuna.tsinghua.edu.cn/dart-pub
    FLUTTER_STORAGE_BASE_URL:https://mirrors.tuna.tsinghua.edu.cn/flutter

    上海交通大学

    FLUTTER_STORAGE_BASE_URL:https://mirrors.sjtug.sjtu.edu.cn
    PUB_HOSTED_URL:https://dart-pub.mirrors.sjtug.sjtu.edu.cn

    我最终选择的是

    PUB_HOSTED_URL:https://pub.flutter-io.cn
    FLUTTER_STORAGE_BASE_URL:https://mirrors.sjtug.sjtu.edu.c

    安装配置

    • 双击运行安装路径/bin/flutter.bat
    • 运行检查
    flutter doctor
    • 没有X之后运行
    flutter doctor --android-licenses

    一直输入y,完成配置

    • 修改镜像:flutterpackagesflutter_toolsgradleflutter.gradle
    buildscript {
        repositories {
    // 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' }
    maven { url "https://storage.googleapis.com/download.flutter.io" }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.0'
        }
    }

    每一个项目配置

    buildscript {
        repositories {
    // 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' }
    maven { url "https://storage.googleapis.com/download.flutter.io" }
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.0'  //这个版本号看自己的配置
        }
    }
    
    allprojects {
        repositories {
    // 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' }
    maven { url "https://storage.googleapis.com/download.flutter.io" }
        }
    }

    升级flutter

    升级

    • 方法1:flutter upgrade
    • 方法2:删除旧的sdk,重新下载

    配置

    • 双击运行安装路径/bin/flutter.bat
    • 运行检查
    flutter doctor

    注意:flutter升级之后,有的项目就无法正常运行了,建议在项目根目录使用flutter clean清除配置,然后使用flutter pub get重新配置一下

    vscode搭建环境

    安装Dart/Flutter/Flutter Widget Snippets /Awesome Flutter Snippets/Android ios Emulator插件;

    vscode创建项目

    进入需要创建项目的文件夹

    运行

    flutter create 项目名

    (可能需要安装cmake)

    运行

    普通运行

    使用vscode打开项目文件夹,在终端输入flutter run,这种模式不能热加载,需要在命令行输入相应字符才能操作

    操作
    R:重启并热加载
    r:热加载
    h:帮助
    d:分离
    q:退出
    p:显示网格,这个可以很好的掌握布局情况,工作中很有用。
    o:切换android和ios的预览模式。
    q:退出调试预览模式。

    热加载debugger

    左侧选择debugger的中的运行即可.

    连接第三方模拟器

    第三方模拟器需要开启root权限,若是有usb调试选项,也要开启

    cmd进入Android sdk的platform-tools文件夹,运行adb连接代码

    夜神模拟器:adb connect 127.0.0.1:62001
    
    逍遥安卓模拟器:adb connect 127.0.0.1:21503
    
    天天模拟器:adb connect 127.0.0.1:6555
    
    海马玩模拟器:adb connect 127.0.0.1:53001
    
    网易MUMU模拟器:adb connect 127.0.0.1:7555
    
    原生模拟器:adb connect (你的IP地址):5555
    
    mumu:adb connect 127.0.0.1:7555

    异常

    启动异常Initialization gradle…

    如果启动过程中一直卡在 Initialization gradle…

    那就去gradle官网下载他的zip压缩包 然后放在.gradlewrapperdistsgradle-4.10.2-all9fahxiiecdb76a5g3aw9oi8rv下 把其他文件删除
    gradle的版本要对应好

    adb 提示adb server version(31) doesn't match this client(40)

    adb的版本冲突问题,

    1. 将AndroidSDK的platform-toolscmdline-toolsbuild-tools路径添加到path中,重启虚拟机(重连手机),重启Android SDK软件(最好重启软件),测试一下;
    2. 若是还有问题,可能是电脑之前安装过adb的服务,打开windows管理工具中的服务,看看有没有adb的,把这个服务停止(最好禁用了,不然每次都要停止一下),测试一下;
    3. 可能是端口冲突,这是因为你的电脑安装了,鲁大师手机助手,360手机助手占用了adb的端口引起的。
      1. cmd输入netstat -ano|findstr “5037”,去查找5037对应的端口号的进程id 也就是pid。如果有相应的pid,就证明此端口5037有程序占用了

        1586002659137

      2. 输入tasklist |findstr “15828”,看到占用端口的软件,去吧这个软件停了
        1. 任务管理器的详细信息可以看到,右键结束即可(可以按照名字查找或者在表头右键显示pid,找到对应pid的程序);
        2. 使用代码强制结束:taskkill /pid 15828 -t -f

        1586002696708

    flutter安装dart失败:

    打开flutter目录ininternal
    打开engine.version
    下载文件

    https://mirrors.sjtug.sjtu.edu.cn/flutter_infra/flutter/文件内容/dart-sdk-darwin-x64.zip

    下载的dart文件,解压,添加bin目录到path环境变量

    添加环境变量FLUTTER_STORAGE_BASE_URL,值为https://mirrors.tuna.tsinghua.edu.cn(注意不要有后面的flutter)

    Could not resolve io.flutter:flutter_embedding_debug:1.0.0-6bc433c6b6b5b98dcf4cc11aff31cdee90849f32


    进入flutterpackagesflutter_toolsgradle 目录下

    • aar_init_script.gradle
    • resolve_dependencies.gradle
    • flutter.gradle
    将http://download.flutter.io 替换为: https://storage.googleapis.com/download.flutter.io
    
    将
    google()
    jcenter()
    替换为:
    // 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' }
    maven { url "https://storage.googleapis.com/download.flutter.io" }

    下载包失败:Could not resolve all artifacts for configuration....

    flutter在下载依赖失败或者flutter run运行的时候出现某个jar或者文件下载失败的时候,如下:

    FAILURE: Build failed with an exception.
    * What went wrong:
    A problem occurred configuring project ':url_launcher'.
    > Could not resolve all artifacts for configuration ':url_launcher:classpath'.
       > Could not download kotlin-reflect.jar (org.jetbrains.kotlin:kotlin-reflect:1.3.31)
          > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.3.31/kotlin-reflect-1.3.31.jar'.
             > Could not GET 'https://d29vzk4ow07wi7.cloudfront.net/a0172daf57e511e8e0df9251b508db8aa6b885cdf0c5849addc9b840db4814f0?response-content-disposition=attachment%3Bfilename%3D%22kotlin-reflect-1.3.31.jar%22&Policy=eyJTdGF0ZW1lbnQiOiBbeyJSZXNvdXJjZSI6Imh0dHAqOi8vZDI5dnprNG93MDd3aTcuY2xvdWRmcm9udC5uZXQvYTAxNzJkYWY1N2U1MTFlOGUwZGY5MjUxYjUwOGRiOGFhNmI4ODVjZGYwYzU4NDlhZGRjOWI4NDBkYjQ4MTRmMD9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPWF0dGFjaG1lbnQlM0JmaWxlbmFtZSUzRCUyMmtvdGxpbi1yZWZsZWN0LTEuMy4zMS5qYXIlMjIiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE1ODYyNTYzNDF9LCJJcEFkZHJlc3MiOnsiQVdTOlNvdXJjZUlwIjoiMC4wLjAuMC8wIn19fV19&Signature=g7IpNFZ30ml7BofrDRqxvVTOidUqrfYgiNEb4ykjpCzmiRKMLPNV19Zy09LSxB5zwo2bYkmGNyvVqBKiYL26uuTtFER5t5Z7YcQPfmb220WviYE~3fuSMLA84FAPTwweRwEO1ZXHWmMupgMO41ao6XfCzd9zSEzPC5o5yWXne4GZSPShEVmgHOg8nhL5G8WD5nUOQNxu9VeO7npIRzU5d6XkrB~pSPKkMkRNisl0LcxjuljT6FKbGtfnhm2uYvpGVNaDvIeff3Qp9Bx3gdmxBH6-AbzS-GxVf1xIBtzzoBqUyq6raz27mL8TIX7mROGomvOV0z5MhlRnG1Kl21UVIw__&Key-Pair-Id=APKAIFKFWOMXM2UMTSFA'.
                > d29vzk4ow07wi7.cloudfront.net
       > Could not download kotlin-stdlib.jar (org.jetbrains.kotlin:kotlin-stdlib:1.3.31)
          > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib/1.3.31/kotlin-stdlib-1.3.31.jar'.
             > Could not GET 'https://d29vzk4ow07wi7.cloudfront.net/f38c84326543e66ed4895b20fb3ea0fca527fd5a040e1f49d0946ecf3d2b3b23?response-content-disposition=attachment%3Bfilename%3D%22kotlin-stdlib-1.3.31.jar%22&Policy=eyJTdGF0ZW1lbnQiOiBbeyJSZXNvdXJjZSI6Imh0dHAqOi8vZDI5dnprNG93MDd3aTcuY2xvdWRmcm9udC5uZXQvZjM4Yzg0MzI2NTQzZTY2ZWQ0ODk1YjIwZmIzZWEwZmNhNTI3ZmQ1YTA0MGUxZjQ5ZDA5NDZlY2YzZDJiM2IyMz9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPWF0dGFjaG1lbnQlM0JmaWxlbmFtZSUzRCUyMmtvdGxpbi1zdGRsaWItMS4zLjMxLmphciUyMiIsIkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTU4NjI1NjM5MX0sIklwQWRkcmVzcyI6eyJBV1M6U291cmNlSXAiOiIwLjAuMC4wLzAifX19XX0_&Signature=MgenmHLDSO66gc2YAaf1l6L9eQjg9xBAKROmoMwEP9-FUACk9uUXgD6CS~2uj1jAlKUFap88Uo50C5z47EAirrxFeQnjrkrQ2epdPGVCYlWJ~lF9IJShpYJpOifd27MwWUFZQpKq1OT5Ahn0eCFWMoZLasji1rg~indBd3nwqfu4ewXZVpkZhsna~bDkSolIHQ3CVAYbsdkOxsHQEFx92WQNGdgj-AMjoC5JoTitlXNPqgMrh4QQ4PwKsdOaXPleSna7~kCmbl7iFPlCRBtGQKYb87pvgpIOM09rX4DpMYGXew47dZLeML0fAHdb2AQ2SYI3LASEGC            > d29vzk4ow07wi7.cloudfront.net
       > Could not get unknown property 'android' for project ':url_launcher' of type org.gradle.api.Project.
       > Could not find method implementation() for arguments [project ':url_launcher_web'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
       > Could not find method implementation() for arguments [project ':url_launcher_macos'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
    * 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

    解决方法:将镜像依赖下载地址改为国内地址
    ```shell

    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' }
    maven { url "https://storage.googleapis.com/download.flutter.io" }
    google()
    jcenter()
    ````
    需要修改的位置:

    • 当前项目:android/build.gradle
    • fluttersdk:flutter安装位置packagesflutter_toolsgradle里的flutter.gradleresolve_dependencies.gradle
    • 下载失败的镜像(比如上面的是url_launcher):在flutter安装位置.pub-cachehosted当前仓库androiduild.gradle

    注意:上面的配置有的文件中有一处,有的有两处





  • 相关阅读:
    grab jpegs from v4l2 devices
    c helloworld on zynq
    minicom installation and configuration on ubuntu
    DBA的做法
    sqlserver锁表、解锁、查看销表
    linux内核分析(网课期末&地面课期中)
    Linux内核分析实验八------理解进程调度时机跟踪分析进程调度与
    LINUX内核分析第七周——可执行程序的装载
    Linux内核分析实验六
    Linux内核分析实验五
  • 原文地址:https://www.cnblogs.com/ziyue7575/p/fb021dbeea6b3e4b43e32ee4b0cbcf77.html
Copyright © 2011-2022 走看看