简体   繁体   中英

Android gradle build fails even for new projects

After updating Android Studio (to 3.2.1), Build Tools (28.0.3), SDK, and Gradle (to 5.0) all tries for building an app fail. Even with new projects. This is the error I get when I run ./gradlew clean in Android Studio's terminal:

Could not get resource ' https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom '.

However, I am able to download and open all these files and the internet connection has no problem or proxies

Here is the app Gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "ir.ddtapp.acepte"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
}
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
}

And the project's Gradle file :

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

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And Gradle Wrapper :

#Thu Nov 22 19:38:06 AEDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip

And Gradle properties :

org.gradle.jvmargs=-Xmx1536m

org.gradle.warning.mode=all

I'm on macOs and the problem was with a gradle.properties file in this path:

/Users/__username__/.gradle/gradle.properties

It looks like an old misconfiguration that Android Studio used without showing an option pointing to it.

I found the path under Global Gradle Settings in Android Studio preferences.

Edit 1:

Now build command works in built-in terminal but the IDE won't sync gradle yet.

Edit 2:

Build button in IDE works as well but still says "gradle sync failed". Tried deleting .gradle folder in user data path above. That didn't work too.

Edit 3:

Deleted both .gradle folders in the user data directory and project directory, built the project and used custom gradle distribution (downloaded from the website)

Update below code in your project level build.gradle and sync your project :

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.google.com/' }
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.google.com/' }
        maven { url 'https://jitpack.io' }

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}  

I have added maven { url 'https://maven.google.com/' }

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