41

I'm new to Android Studio and while creating a new project it stuck at resolving dependencies :app:_debugCompile.

I waited for sometime and even tried to create a new project, but that didn't work. Here's a screenshot of the window:

Here's the contents of build.gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
Gowtham
  • 11,853
  • 12
  • 43
  • 64
  • possible duplicate of [Android Studio stuck when creating new Project on Gradle: Configure Project or Gradle: Resolve Dependencies ':classpath:'](http://stackoverflow.com/questions/24621678/android-studio-stuck-when-creating-new-project-on-gradle-configure-project-or-g) – JBaruch Dec 25 '14 at 17:06
  • 4
    Not a duplicate. Totally different issues. – SBerg413 Dec 30 '14 at 21:41
  • I had this problem.Just see this page. [Solution is here](http://stackoverflow.com/q/36529301/5037958) – Mehdi Jahed Manesh Apr 10 '16 at 19:31
  • http://stackoverflow.com/a/37378848/538284 – Omid Raha May 22 '16 at 19:52

15 Answers15

16

maybe you have problem to connect to the internet to download gradle, you can set in http proxy

File->Settings->Http Proxy->Manual proxy configuration->HTTP

Host name:172.16.26.2(that's mine) Port number:8080

of course,you need to change the Host name,the proxy you use

Jiajun Shen
  • 211
  • 2
  • 5
13

Killing the process or restarting the system helped me. Now it works perfectly fine...

P.S: A quote from the sitcom The IT Crowd:

Did you try turning it off and on again?
Gowtham
  • 11,853
  • 12
  • 43
  • 64
  • 2
    somehow , restarting the system worked for me too after uninstalling, deleting all android studio and gradle folders in users/youAsUser/.. and reinstalling the android studio – smoothumut Aug 03 '15 at 08:25
  • 7
    restarting did not work for me... :( Still stuck with the gradle resolve dependencies.. – Swapnil Kale Feb 03 '16 at 13:04
13

100% fix for you Android lover

you can ether fix it for each of your new project or just fix it for every new project you open. I'm gonna explain both:

** For each project separately :

When you create a new project and when you stuck at: Gradle: Resolve dependencies ':app:_debugCompile' just hit Cancel button after that the process may continue again and you may see at the bottom of Android studio that you stuck on the same point you can click on the red Cancel button beside progress bar now too

so at this point your new project should open but with some error like : Error: Could not run build action using gradle .........

Now open the Project tap in the left side of android studio window (it has green icon of android studio on it) now go to this path: Gradle Scripts > build.gradle(project:your project name)

after double clicking on it you will see the contents of it in a editor at the right side of it

just look for the lines :

allprojects {
    repositories {
        jcenter()    }
}

and just select jcenter() and nothing more and replace it with below line:

maven { url 'http://repo1.maven.org/maven2' }

after this just hit the Try Again button at the top of the editor

That's it now your project will rebuild in no time without any problem (don't forget to be connected to internet) this method just work for this project and if you open another new project you have to do the same thing to get it working

**Now the fix for every new project at once:

first open Notepad as administrator (just right click on it and click on Run as administrator)

Go to below path of your Android Studio installation path with Notepad (when you open Notepad as administrator you can drag and prop file in it, so open the below path in notepad): the default path is :

C:\Program Files\Android\Android Studio\plugins\android\lib\templates\gradle-projects\NewAndroidProject\root

you can't see anything in this path and you have to set the File type chooser to All Files at the right bottom side of file opener window

Now open build.gradle.ftl

press Ctrl+F keys and search for:

allprojects

in front of the the above word you search for you can see this line:

{       repositories {         jcenter()<#if mavenUrl != "mavenCentral">

all you have to do is to select just jcenter() and nothing more and replace it with below line:

maven { url 'http://repo1.maven.org/maven2' }

Save the file and close the Notepad

That's it now your new project build time is less than 30 seconds depending on your system hardware.

Hit thanks if this solved your problem Regards

Badboy
  • 151
  • 1
  • 6
5

In my case, I imported the project which was created by someone else. For me it was proxy set in gradle.properties file of the project. I commented below lines in gradle.properties and it worked fine.

#systemProp.https.proxyPort=8080
#systemProp.http.proxyHost=10.10.11.12
#systemProp.https.proxyHost=10.10.11.12
#systemProp.http.proxyPort=8080
Bharat Dodeja
  • 1,137
  • 16
  • 22
3

Try looking at Gradle debug output. (My guess is IDE is not able to get to jcenter repository). Here is what you can try.

  1. Go to Settings> Compiler(Gradle-Based Android Project)
  2. In Command-line Options, add "--stacktrace --debug"
  3. Build your project
  4. Click and look at Gradle Console on the bottom right. You should see where gradle is choking up.

How does your module "build.gradle" look like? you might want to add "mavenCentral()" under repositories block. (assuming you have dependencies that are found there)

bond
  • 11,236
  • 7
  • 48
  • 62
3

Network problem. After I restart Android Studio and use a proxy everything is OK now. During the Gradle build , Android Studio need to download some file from the Internet. Make sure you have a good connection.

einverne
  • 6,454
  • 6
  • 45
  • 91
  • I had the same problem with gradle standalone, and setting the proxy worked for me. In `gradle.properties` just set `systemProp.https.proxyHost` and `systemProp.https.proxyPort` variables. – Andrea Apr 12 '17 at 13:31
2

I had the same issue, and I just let it go for 30 mins. Then it started working after that.

It was also resolving other stuff after "_debugCompile".

Pal R
  • 534
  • 4
  • 11
1

I solved this by going to AppName\app -> open build.gradle and replace the dependencies part with:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:multidex:1.0.0'
}

You'll have to do this for every app you create but after this they will load fine.

I do it this way:

  1. Create new project
  2. Wait for it to get stuck
  3. Exit Android Studio
  4. Do the modifications above
  5. Open project
Bugs
  • 4,491
  • 9
  • 32
  • 41
Kr3Ep
  • 102
  • 1
  • 12
1

Check Your gradle.properties file it might be having some system Properties enables. Remove them, you may don't need them

-systemProp.http.proxyPassword=password
-systemProp.http.proxyHost=172.18.**.**
-systemProp.http.proxyUser=user.name
-systemProp.http.proxyPort=80

Invalidate cache and restart Android studio.

Jagdeep Singh
  • 1,200
  • 1
  • 16
  • 34
  • More info, check if your Global gradle.properties file has these properties too, see https://stackoverflow.com/a/50350959/2413303 – EpicPandaForce Dec 04 '19 at 23:26
0
  1. Cancel the Gradle build when its taking long time.

  2. Check the HTTP proxy settings in File-> Settings-> Appearance & Behavior -> System Settings -> HTTP Proxy. Verify using "Check connection"

  3. If fine, remove the android test compile and/or unit test build from app/build.gradle file e.g remove the below line

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' })

chandru
  • 11
  • 2
0

I have the same problem.And I finally solved it.

  1. Download your Gradle, it is in your Gradle-wrapper.properties.for example

    https\://services.gradle.org/distributions/gradle-3.3-all.zip

    And unzip it anywhere.

  2. go to File-> Settings-> BUild, Execution, Deployment -> Gradle, select use local gradle distribution and offline work, then set the Gradle Home as the path where you unzip the gradle-3.3-all.zip.Like this /opt/android-studio/gradle/gradle-3.3.

  3. Click Try again, it will build very quickly, because it won't connect to jcenter anymore.It uses the local gradle.

P.S.: If you add new dependencies, you have to turn off offline work.

LeeR
  • 568
  • 6
  • 10
0

check if your android studio's gradle is in offline mode. if yes then uncheck offline mode.

path: file->setting->Build Exexcution -> gradle ->offline work

Munir
  • 2,548
  • 1
  • 11
  • 20
0

resolving dependencies is taking too much time because it is trying to download some files to build successfully. With proper bandwidth, it can be removed. Here, I am discussing what I did with my project on the android studio:

1. Open the terminal in Android Studio.

2. Move to your project's android folder with the help of terminal command cd it might be something like: YourProjectNameHere\, if you are working on flutter then this might be like: YourProjectNameHere\android\.

3. run the grdlew by typing gradlew in the terminal.

4. Let it finish or abort with some error. Don't interrupt the process. You can see on your terminal that few files are downloading.

5. if again there is an error, read the error carefully, you can figure it out where is the error and what's the error. And go to step 3. until it finishes build successfully.

P.S.: if gradlew command is unable to download few files due to some reason, you can download it manually by using your favourite browser.

Udit
  • 51
  • 1
  • 2
-1

I had a similar problem (after installing Android Studio and creating a new project this issue occurs). Adding the JAVA_HOME variable hepled to me. Quote from the official help:

On some Windows systems, the launcher script does not find where Java is installed. If you encounter this problem, you need to set an environment variable indicating the correct location.

Select Start menu > Computer > System Properties > Advanced System Properties. Then open Advanced tab > Environment Variables and add a new system variable JAVA_HOME that points to your JDK folder, for example C:\Program Files\Java\jdk1.7.0_21.

Community
  • 1
  • 1
Mikhail
  • 2,612
  • 3
  • 22
  • 37
-2

Re-install latest version of Android Studio.

Install in the directory such that that directory has no white space, meaning space char.

Before creating any project in the studio, first update it's components using sdk manager.

Create a workspace such that it has no white space in it's path.

Harsh
  • 644
  • 3
  • 14
  • 27