准备开发一个flutter的项目,在环境搭建完成,新建后第一次执行时,问题来了,这里做个记录分享解决办法:

问题一

第一次运行 会卡在 Resovle ...中很长时间,然后就会报错

Finished with error: ProcessException: Process "F:\zy\httpd\flutter_app\android\gradlew.bat" exited abnormally:
Downloading https://services.gradle.org/distributions/gradle-4.10.2-all.zip

Unzipping C:\Users\Administrator\.gradle\wrapper\dists\gradle-4.10.2-all\9fahxiiecdb76a5g3aw9oi8rv\gradle-4.10.2-all.zip to C:\Users\Administrator\.gradle\wrapper\dists\gradle-4.10.2-all\9fahxiiecdb76a5g3aw9oi8rv

Exception in thread "main" java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:219)
at java.util.zip.ZipFile.<init>(ZipFile.java:149)
at java.util.zip.ZipFile.<init>(ZipFile.java:163)
at org.gradle.wrapper.Install.unzip(Install.java:214)
at org.gradle.wrapper.Install.access$600(Install.java:27)
at org.gradle.wrapper.Install$1.call(Install.java:74)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
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: F:\zy\httpd\flutter_app\android\gradlew.bat -v


问题原因:flutter 需要梯子在jcenter和google库里下载依赖,因为google被墙访问不到,所以会在那里一直处于下载状态,但又下载不了。

解决方法:​有两个地方需要添加的内容:

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

1.需要再你app 里的build.gradle 的两个地方加 阿里云的镜像

Finished with error: ProcessException: Process_flutter

2.需要在你flutter sdk 的 如下路径 下的 flutter.gradle 也同样添加镜像。


这里是我的Flutter SDK  .gradle路径

  Finished with error: ProcessException: Process_ProcessException_02 

打开后添加的镜像

Finished with error: ProcessException: Process_java_03

问题二

    看到报错猜测就是C:\Users\Administrator\.gradle\wrapper\dists\gradle-4.10.2-all目录下的gradle-4.10.2-all文件报错。

1、可能原因是该目录下的gradle-4.10.2-all文件不完整或损坏。重新下载gradle压缩包即可。

2、检查目录下是否有gradle-4.10.2-all这个文件。

Finished with error: ProcessException: Process "F:\zy\httpd\flutter_app\android\gradlew.bat" exited abnormally:
Unzipping C:\Users\Administrator\.gradle\wrapper\dists\gradle-4.10.2-all\9fahxiiecdb76a5g3aw9oi8rv\gradle-4.10.2-all.zip to C:\Users\Administrator\.gradle\wrapper\dists\gradle-4.10.2-all\9fahxiiecdb76a5g3aw9oi8rv

Exception in thread "main" java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:219)
at java.util.zip.ZipFile.<init>(ZipFile.java:149)
at java.util.zip.ZipFile.<init>(ZipFile.java:163)
at org.gradle.wrapper.Install.unzip(Install.java:214)
at org.gradle.wrapper.Install.access$600(Install.java:27)
at org.gradle.wrapper.Install$1.call(Install.java:74)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWra


解决办法:

1、将C:\Users\Administrator\.gradle\wrapper\dists\gradle-4.10.2-all\9fahxiiecdb76a5g3aw9oi8rv目录怀疑有问题的gradle压缩包删掉,然后下载一个没问题的放进去。

2、可以查看其它android项目的.gradle中gradle版本多少,可改为一致。

3、直接在网上下载此版本,直接添加进去。

以上两种是初学Flutter容易出现的问题