美文网首页
安装flutter环境

安装flutter环境

作者: 你飞跃俊杰 | 来源:发表于2021-02-05 15:48 被阅读0次

    一、下载flutter SDK
    1.git 拉取
    git clone https://github.com/flutter/flutter.git
    2.在github上下载

    二、配置环境
    1.打开操作终端,执行 ls ~/.bash_profile

    jundeiMac:~ jun$ ls  ~/.bash_profile
    ls: /Users/jun/.bash_profile: No such file or directory
    

    2.如果不存在,执行命令: touch ~/.bash_profile
    3.执行命令:vim ~/.bash_profile ,输入以下内容

    if [ -f /etc/bash_profile ]; then
    ./etc/bash_profile
    fi
    
    #修改地址flutter
    export PUB_HOSTED_URL=https://pub.flutter-io.cn
    export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
    #我的目录
    export PATH="$PATH:~/Downloads/flutter/bin"
    

    4.安装flutter指令
    flutter -v

    问题一、
    Building flutter tool...
    ^CError: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (9 tries left)
    在bash_profile修改flutter地址

    #修改地址flutter
    export PUB_HOSTED_URL=https://pub.flutter-io.cn
    export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
    

    三、增加http支持
    1.安卓
    增加xml目录,在里面添加network_security_config.xml文件,内容如下

    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
     
        <base-config cleartextTrafficPermitted="true" />
     
    </network-security-config>
    
    
    file1614137975253.png

    在AndroidManifest.xml增加之前的配置

     android:networkSecurityConfig="@xml/network_security_config">
    
    file1614144988144.png

    2.iOS

        <key>NSAppTransportSecurity</key>
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
        </dict>
    
    file1614145224298.png

    四、修改gradle镜像
    修改项目中android/build.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' }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:4.1.0'
        }
    }
    ........
            project.rootProject.allprojects {
                repositories {
                    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 repository
                    // }
                }
    
    
    
     修改Flutter的配置文件, 该文件在`Flutter安装目录/packages/flutter_tools/gradle/flutter.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' }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:4.1.0'
        }
    }
    

    五、配置flutter和dart路径
    必须打开flutter工程才行
    看一下有没配对,一般自动配置的

    相关文章

      网友评论

          本文标题:安装flutter环境

          本文链接:https://www.haomeiwen.com/subject/hhfgtltx.html