Linux 桌面版 Ubuntu16.04 安装Flutter 1.0 正式版注意事项

发布日期 目录 Flutter, Linux

Linux 桌面版 Ubuntu16.04 安装Flutter 1.0 正式版注意事项

其实在linux系统安装Flutter很简单,你只要按着官方的教程一步步来就行,我就没必要重复正确的安装步骤了。
官方地址:https://flutter.io/docs/get-started/install/linux
中文版地址:https://flutterchina.club/setup-linux/
英文不好的还是看中文版吧。

这里以中文版地址参照安装的注意事项。

安装步骤不说了,来说下安装过程中的注意事项以及可能会报的错误。

注意事项:

1、使用Flutter官方为中国开发者搭建的临时镜像,将环境变量复制到用户变量~/.bash_profile中,然后执行source ~/.bash_profile使环境变量生效。这里还有一个需要注意的点是:如果你的ubuntu系统使用了zsh终端主题,点这查看漂亮的ubuntu终端 ZSH 主题,需要将source ~/.bash_profile这句命令添加到~/.zshrc这个文件中(放在最低部即可),其实文档中在更新环境变量那部分已经说明了。

2、该flutter工具使用Google Analytics匿名报告功能使用情况统计信息和基本崩溃报告。记得一定要将这部分的命令执行完才行,flutter config --no-analytics然后运行flutter config,将这个报告功能禁用掉,因为发送报告是被墙的。也就是说严格安装文档步骤安装Flutter。

3、不能直接下载github上已经打包好的安装包,因为运行Flutter命令时会报错。使用git clone <\project address>这种方式下载Flutter SDK。

报错信息

1、运行Flutter命令时出现:

Error: The Flutter directory is not a clone of the GitHub project.
       The flutter tool requires Git in order to operate properly;
       to set up Flutter, run the following command:
       git clone -b beta https://github.com/flutter/flutter.git

flutter 包使用git clone拉取下github的flutter包即可例如: git clone https://github.com/flutter/flutter.git
当前也可以在flutter目录下执行git init初始化工程(不推荐)

2、Google Analytics匿名报告功能错误:

Initializing gradle...                                          ⣻
Oops; flutter has exited unexpectedly.

Sending crash report to Google.
Failed to send crash report due to a network error: SocketException: Connection failed (OS Error: Network is
unreachable, errno = 101), address = clients2.google.com, port = 443
Crash report written to /home/seebin/桌面/flutter_word/flutter_01.log;
please let us know at https://github.com/flutter/flutter/issues.

这个就是上面注意事项里面说的匿名报告功能,被墙掉了,禁用该功能即可。

3、运行 Flutter run 可能会出现的错误:

ProcessException: Process "/home/seebin/桌面/flutter_word/android/gradlew" exited abnormally:
Exception in thread "main" java.lang.RuntimeException: Timeout of 120000 reached waiting for exclusive access to file: /home/seebin/.gradle/wrapper/dists/gradle-4.10.2-all/9fahxiiecdb76a5g3aw9oi8rv/gradle-4.10.2-all.zip
    at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:61)
    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)
  Command: /home/seebin/桌面/flutter_word/android/gradlew -v
Exited (sigterm)

出现上面的错误 请删除.gradle/wrapper/dists文件夹,重新执行flutter run即可。

4、如果google为我们搭建的临时镜像不好使了,可能会报下面的错误,也是window最常见的错误:

* Error running Gradle:
ProcessException: Process "F:\flutter-examples\flutter_gallery\android\gradlew.bat" exited abnormally:
Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :connectivity

Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the
afterEvaluate {} error.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':connectivity'.
> Could not resolve all artifacts for configuration ':connectivity:classpath'.
   > Could not download guava.jar (com.google.guava:guava:22.0)
      > Could not get resource 'https://jcenter.bintray.com/com/google/guava/guava/22.0/guava-22.0.jar'.
         > Read timed out

* 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

BUILD FAILED in 8m 21s
  Command: F:\flutter-examples\flutter_gallery\android\gradlew.bat app:properties


Please review your Gradle project setup in the android/ folder.

解决方法:
修改项目下的build.gradle文件,注释掉jcenter(),google()。使用阿里的镜像。原因是jcenter google库无法访问到导致的问题。参考如下:

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:3.1.2'
    }
}

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' }
    }
}

第二步:找到Flutter sdk目录 进入如下目录

<你的SDK目录>/⁨Flutter⁩/packages/⁨flutter_tools/⁨gradle⁩
找到下 flutter.gradle文件 找如如下内容替换成和我一样的 把对应注释掉即可。

​buildscript {
    repositories {
        //jcenter()
        //maven {
        //    url 'https://dl.google.com/dl/android/maven2'
        //}
        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:3.1.2'
    }
}

发表评论

邮箱地址不会被公开。