简体   繁体   English

为 Flutter 项目初始化 Gradle 永远需要在 android studio 上进行

[英]Initializing Gradle is taking forever on android studio for Flutter project

I'm trying to run a hello world flutter app for the first time on my device, but when I hit run on android studio, it shows initilizing gradle, and it stays like that for more than 20 minutes with no logging or error, I have an intel i5 as a CPU and I'm running it on Linux (dual boot, my download speed is quite slow (200 kb/s average download rate), in case this help我第一次尝试在我的设备上运行一个 hello world flutter 应用程序,但是当我在 android studio 上运行时,它显示初始化 gradle,并且它保持这样的状态超过 20 分钟没有记录或错误,我有一个英特尔 i5 作为 CPU,我在 Linux 上运行它(双启动,我的下载速度很慢(平均下载速率为 200 kb/s),以防万一

I installed the Flutter SDK and when I try adb devices on my machine it shows my device connected .我安装了 Flutter SDK,当我在我的机器上尝试adb devices ,它显示我的设备已连接。

So why it's taking that time to run ?那么为什么要花时间运行呢? (until now it didn't run yet) (直到现在它还没有运行)

https://github.com/flutter/flutter/issues/15106 https://github.com/flutter/flutter/issues/15106

Please note riftninja's answer.请注意 riftninja 的回答。 I look at this directory: C:\\Users\\myname.gradle\\wrapper\\dists Yes, the gradle file is really big: 87M.我看看这个目录: C:\\Users\\myname.gradle\\wrapper\\dists 是的,gradle文件真的很大:87M。 You have to wait for a long time.你必须等待很长时间。 After this will be "Resolving dependencies....", which also slowly.在这之后将是“解决依赖关系....”,这也很慢。 But finally it succeed.但最后还是成功了。

I've faced the same problem, and my internet is currently very slow, so I solved it by changing the gradle in flutter project to an already downloaded one.我遇到了同样的问题,我的互联网目前很慢,所以我通过将 flutter 项目中的 gradle 更改为已经下载的 gradle 来解决它。 Just follow these steps:只需按照以下步骤操作:

  1. Go to C:\\Users\\YOUR_USER_NAME\\.gradle\\wrapper\\dists转到C:\\Users\\YOUR_USER_NAME\\.gradle\\wrapper\\dists

  2. You should find one or more folders with the name of the distribution (for example with the name "gradle-4.6-all" if you were developing in Android Studio previously), choose one of these folders (make sure it is not empty) and copy its name.您应该找到一个或多个带有发行版名称的文件夹(例如,如果您之前在 Android Studio 中开发,则名称为“gradle-4.6-all”),选择这些文件夹之一(确保它不为空)并复制它的名字。

  3. Open Android Studio project explorer, and locate android\\gradle\\wrapper\\gradle-wrapper.properties打开 Android Studio 项目资源管理器,找到android\\gradle\\wrapper\\gradle-wrapper.properties

  4. You will find a line like this:你会发现这样一行:
    distributionUrl=https\\://services.gradle.org/distributions/gradle-5.4.1-all.zip
    Change gradle-5.4.1-all with the folder name you copied in step 2.使用您在步骤 2 中复制的文件夹名称更改gradle-5.4.1-all

  5. Run your app, and hopefully it works this time.运行您的应用程序,希望这次它可以正常工作。

When running flutter project first time even correct configuration it takes very long time.第一次运行 flutter 项目时,即使是正确的配置也需要很长时间。 That is because of downloading gradel and dependencies for particular version.那是因为下载了特定版本的 Gradel 和依赖项。 If you ar noob Wait it to complete automatically till all files get downloaded .如果您是菜鸟,请等待它自动完成,直到下载所有文件 By using command:通过使用命令:

  • flutter run <project-name> -v you can see whats happening in background. flutter run <project-name> -v你可以看到后台发生了什么。

  • To Manually downloading gradle zip and put to suitable directory.手动下载 gradle zip 并放入合适的目录。 Go in Project Dir: /android/gradle/wrapper/gradle-wrapper.properties and click on url and download it.进入项目目录: /android/gradle/wrapper/gradle-wrapper.properties并点击 url 并下载它。 获取下载地址的路径

  • After Downloading it visit to : /Users//.gradle/wrapper/dists/gradle-4.10.2-all/9fahxiiecdb76a5g3aw9oi8rv your version path may vary and paste downloaded zip inside it.下载后访问:/ Users//.gradle/wrapper/dists/gradle-4.10.2-all/9fahxiiecdb76a5g3aw9oi8rv您的版本路径可能会有所不同,并将下载的 zip 粘贴到其中。
  • For Dependencies to download you need to wait depending on Internet speed.要下载依赖项,您需要等待,具体取决于 Internet 速度。
  • It is one time process until next updated version and dependencies come UP.这是一个时间过程,直到下一个更新版本和依赖项出现。

Providing an active internet connection worked for me.提供有效的互联网连接对我有用。

To build gradle offline,要离线构建 gradle,

For Windows ,对于Windows

Go to File -> Settings .转到文件->设置

And open the ' Build,Execution,Deployment '.并打开“构建、执行、部署”。 Then open the然后打开

Build Tools -> Gradle构建工具 -> Gradle

Then check the box -> Offline work below.然后选中下面的框 ->离线工作

Click the OK button.单击确定按钮。

For Mac OS ,对于Mac 操作系统

go to Android Studio -> Preferences , and the rest is the same.转到Android Studio -> Preferences ,其余相同。

Goto Android Studio - File - Other Setting - Default Project Structure Uncheck use Embeded JDk Below, set your JDK path.转到 Android Studio - File - Other Setting - Default Project Structure 取消选中 use Embeded JDk 下面,设置你的 JDK 路径。 Found in Program files - Java - Jdk.在程序文件 - Java - Jdk 中找到。

尝试使用flutter run -v ,它基本上会提供在后台运行的信息。

The problem is that Gardle is downloading dependencies and not using any way to show progress(This is NOT good for UX), so it is better to run gradlew.bat in the terminal and things will become more clear, like this:问题是,Gardle被下载依赖和不使用任何方式来显示进度(这不是UX好),所以最好是运行gradlew.bat终端,事情会变得更加清晰,就像这样: 运行 gradlew.bat

Now it is much better, You can have a cup of coffee while watching it ;)现在好多了,你可以一边看一边喝杯咖啡;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM