Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing Gradle is taking forever on android studio for Flutter project

Tags:

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)

like image 386
Souames Avatar asked Jun 09 '18 10:06

Souames


People also ask

How long does it take to create gradle in Android Studio?

gradle, if you have minifyEnabled for debug, remove it. I had it in my project and it took ~2-3 minutes to build.

Why does flutter build take so long?

When you are going to build the Flutter app for the first time, it takes a very long time than usual because Flutter builds a device-specific IPA or APK file. In this process, the Xcode and Gradle are used to build a file, which usually takes a long time.

Why is Gradle build so slow?

Dynamic Dependencies slow down your build since they keep searching for the latest builds every time. To improve the performance we need to fix the version in place. Use only those dependencies that you need.


2 Answers

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.

like image 98
hyyou2010 Avatar answered Sep 30 '22 05:09

hyyou2010


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.

like image 30
evals Avatar answered Sep 30 '22 04:09

evals