flutter环境安装踩坑

flutter sdk及android studio插件的安装都是参照flutter环境搭建来进行的,flutter doctor一切正常。但新建flutter project后,运行就卡住了。


Running Gradle task 'assembleDebug'...    
This is taking an unexpectedly long time.

运行时会卡在Running Gradle task 'assembleDebug'..., 因为Gradle的Maven仓库在国外, 可以使用阿里云的镜像地址。

(1). 修改项目中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:3.2.1'
     }
 }

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

rootProject.buildDir = '../build'
 subprojects {
     project.buildDir = "${rootProject.buildDir}/${project.name}"
 }
 subprojects {
     project.evaluationDependsOn(':app')
 }

task clean(type: Delete) {
     delete rootProject.buildDir
 }

(2). 修改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:3.2.1'
     }
 }

重新开始

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve io.flutter:flutter_embedding_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
     Required by:
         project :app
      > Could not resolve io.flutter:flutter_embedding_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
         > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/flutter_embedding_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/flutter_embedding_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
            > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/flutter_embedding_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/flutter_embedding_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
               > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Connection timed out: connect
      > Could not resolve io.flutter:flutter_embedding_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
         > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/flutter_embedding_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/flutter_embedding_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
            > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/flutter_embedding_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/flutter_embedding_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
               > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Read timed out
   > Could not resolve io.flutter:arm64_v8a_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
     Required by:
         project :app
      > Could not resolve io.flutter:arm64_v8a_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
         > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/arm64_v8a_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/arm64_v8a_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
            > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/arm64_v8a_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/arm64_v8a_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
               > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Connection timed out: connect
      > Could not resolve io.flutter:arm64_v8a_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
         > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/arm64_v8a_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/arm64_v8a_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
            > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/arm64_v8a_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/arm64_v8a_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
               > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Read timed out
   > Could not resolve io.flutter:x86_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
     Required by:
         project :app
      > Could not resolve io.flutter:x86_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
         > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
            > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
               > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Connection timed out: connect
      > Could not resolve io.flutter:x86_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
         > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
            > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
               > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Read timed out
   > Could not resolve io.flutter:x86_64_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
     Required by:
         project :app
      > Could not resolve io.flutter:x86_64_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
         > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_64_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
            > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_64_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
               > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Connection timed out: connect
      > Could not resolve io.flutter:x86_64_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
         > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_64_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
            > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_64_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
               > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Read timed out

于是,我把/packages/flutter_tools/gradle/flutter.gradle中的
private static final String MAVEN_REPO = "https://storage.googleapis.com/download.flutter.io";改为private static final String MAVEN_REPO = "https://storage.flutter-io.cn/download.flutter.io";
于是提示变成了

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not find io.flutter:flutter_embedding_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
     Required by:
         project :app
   > Could not find io.flutter:arm64_v8a_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
     Required by:
         project :app
   > Could not find io.flutter:x86_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
     Required by:
         project :app
   > Could not find io.flutter:x86_64_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
     Required by:
         project :app

google后参考这里
加上如下解决

 maven {
            url 'http://download.flutter.io'
 }

你可能感兴趣的:(flutter环境安装踩坑)