3

Hello I really need your help.

I'm using Android Studio 3.1.2 and I'm new at Android app developpement.

So, I get some issues with Gradle. When I create a new project, the Gradle build starts but downloads take FOREVER. It has been now 3 hours that I'm waiting for the download to finish.

When I copy/paste the download file (https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.1.2/builder-3.1.2.jar) in my browser, It took only 30 seconds. I tried everything and searched all stackoverflow but I found nothing :(

Thank you

UPDATE Here are my two files as asked.

My project build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.bg.selim.reminder"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

My gradle.properties file:

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

build.gradle file from project root folder

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

buildscript {

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


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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
selimgrr
  • 43
  • 1
  • 8

6 Answers6

1

If you still have trouble, you can try to download the builder-3.1.2.jar and its builder-3.1.2.pom file, and put them into your Android Studio folder under:

AndroidStudio > gradle > m2repository > com > android > tools > build > builder > 3.1.2 

Put builder-3.1.2.jar and builder-3.1.2.pom under the folder 3.1.2 and you should be good to go.

xiaomi
  • 6,553
  • 3
  • 29
  • 34
  • yeah this is what I did not only for builder but for a half of the files. I don't know why Android Studio stuck at downloading files.. Now everything is good but I'm stuck with "Indexing suspended (context: Project Setup)". Why? – selimgrr Apr 30 '18 at 09:49
  • nevermind I definitively abandon my idea to create an Android app, now I can't create a new project or anything. I don't understand it's getting so annoying – selimgrr Apr 30 '18 at 09:57
  • @xiaomi do you khow that is this path when you work with InteliJ? – dev-masih Jul 07 '18 at 08:15
1

To the people of my team 2 different solutions worked out:

Move JCenter dependency

Move your jcenter() dependency to the bottom of your repository dependencies:

repositories {
        maven { url "https://jitpack.io" }
        maven { url "https://maven.fabric.io/public" }
        google()
        jcenter()
    }

Use a gradle distribution manually

It's just a workaround but it should be enough until they will fix this on the next AS version.

File > Settings > Build, Execution, deployment > Gradle -> Use local distribution and use the Gradle version inside your AndroidStudio folder

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Francisco Durdin Garcia
  • 12,540
  • 9
  • 53
  • 95
1

Disconnecting with jcenter https can also lead this problem.
And in this case it will show this message:

Could not find builder.jar (com.android.tools.build:builder:3.1.2).
Searched in the following locations:
    https://jcenter.bintray.com/com/android/tools/build/builder/3.1.2/builder-3.1.2.jar

Then I replace the jcenter () in the gradle repositories block with

jcenter {
   url "http://jcenter.bintray.com/"
}

Notice the http instead of https.

Then it compiles successfully.
Hope this could be helpful.

Crow
  • 46
  • 4
1

In my case, it was resolved by assigning write and modify permissions to the folder:

AndroidStudio> gradle> m2repository> com> android> tools
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Marco
  • 11
  • 1
0

Okay your files seem file, my suggestion would be to check if your gradle-wrapper.properties has the following

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

If that's fine then clean the project, delete any build folders inside your app folder.

Check File > Settings > Build, Execution, deployment > Gradle > use default gradle wrapper & uncheck offline work

Under the same menu goto Compiler and make sure only configure on demand is checked.

Clean and sync gradle after that. [ Make sure you are connected to the net when syncing gradle ]

Jude Fernandes
  • 7,437
  • 11
  • 53
  • 90
  • everything is fine but how do I "clean the project"? where are the build folders? – selimgrr Apr 29 '18 at 17:38
  • Look for a build menu that's in the same like as `File`, click on it you should find `clean project`. As for the `build` folder goto your project directory , then goto app and see if there is a directory called build there, if so delete it. – Jude Fernandes Apr 29 '18 at 17:44
  • :/ don't work.. always downloading forever the builder.jar file – selimgrr Apr 29 '18 at 17:47
  • Have you tried just creating a new basic android studio project with an empty activity and running that ? – Jude Fernandes Apr 29 '18 at 17:48
  • Yeah Its the 3rd time I create a new project with an empty activity. Here's a screenshot of what I get: https://i.imgur.com/fwt4mVm.png – selimgrr Apr 29 '18 at 17:49
  • Can you add `buildToolsVersion '27.0.3'` below the line `compileSdkVersion 27` – Jude Fernandes Apr 29 '18 at 17:52
  • added, do I have to rebuild? – selimgrr Apr 29 '18 at 17:54
  • any changes to the gradle files need to be synced so yes you need to sync first. – Jude Fernandes Apr 29 '18 at 17:55
  • I get the same issue.. I don't understand. Can it be a network issue? – selimgrr Apr 29 '18 at 17:59
  • Is it possible for you to push your code to git and I could give it a try? – Jude Fernandes Apr 29 '18 at 18:00
  • Tried it and worked fine for me mostly because I already had gradle working on existing projects, make sure you have your sdk tools installed correctly, goto sdk manager and sdk tools and make sure you have sdk build tools `27.0.3` as well as the latest support repo etc installed, once done goto `File > Invalidate Caches and restart` – Jude Fernandes Apr 29 '18 at 18:15
  • I'll try thank you, hm I came back and saw this: http://prntscr.com/jbo4xr can it be a network issue then? – selimgrr Apr 29 '18 at 18:17
  • Yep that's definitely a network issue, maybe your antivirus is blocking stuff or you need a different network – Jude Fernandes Apr 29 '18 at 18:21
  • I disabled my firewall, antivirus everything but still don't work. I don't know what can block it. I don't have proxy – selimgrr Apr 29 '18 at 18:23
0

Sooo I finally solved this problem! :D

The Jude Fernandes and xiaomi answers were pretty helpful but not solved my problem. I just reinstalled Android Studio (took ~2 mins) and it's working perfectly. I don't know what happened but.. everything works FINE!

Thank you for your precious help Jude and Xiaomi!

selimgrr
  • 43
  • 1
  • 8