简体   繁体   中英

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

I installed the Flutter SDK and when I try adb devices on my machine it shows my device connected .

So why it's taking that time to run ? (until now it didn't run yet)

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

Please note riftninja's answer. I look at this directory: C:\\Users\\myname.gradle\\wrapper\\dists Yes, the gradle file is really big: 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. Just follow these steps:

  1. Go to 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.

  3. Open Android Studio project explorer, and locate 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.

  5. Run your app, and hopefully it works this time.

When running flutter project first time even correct configuration it takes very long time. That is because of downloading gradel and dependencies for particular version. 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.

  • To Manually downloading gradle zip and put to suitable directory. Go in Project Dir: /android/gradle/wrapper/gradle-wrapper.properties and click on url and download it. 获取下载地址的路径

  • 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.
  • For Dependencies to download you need to wait depending on Internet speed.
  • 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,

For Windows ,

Go to File -> Settings .

And open the ' Build,Execution,Deployment '. Then open the

Build Tools -> Gradle

Then check the box -> Offline work below.

Click the OK button.

For Mac OS ,

go to Android Studio -> Preferences , and the rest is the same.

Goto Android Studio - File - Other Setting - Default Project Structure Uncheck use Embeded JDk Below, set your JDK path. Found in Program files - 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: 运行 gradlew.bat

Now it is much better, You can have a cup of coffee while watching it ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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