Johannes Kraft
Johannes Kraft

Reputation: 257

Cannot resolve external dependency for gradle

I have looked through many of the issues regarding similar problems but i could not find a solution that works. It might be my inexperience with android development but i don't think that the error message is all that clear. I have tried:

Any ideas on what to do to solve this one?

Using Android Studio version: 3.4.1

App: Build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.app.jokr.dogpark"
        minSdkVersion 23
        targetSdkVersion 28
        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 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.google.firebase:firebase-storage:17.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.firebase:firebase-firestore:19.0.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta1'
    testImplementation 'junit:junit:4.13-beta-3'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
}

buildscript {
    ext {
        var = '3.3.2'
    }
    dependencies {
        classpath 'com.android.tools.build:gradle'
    }
}

apply plugin: 'com.google.gms.google-services'

Project: Build.gradle

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

buildscript {
    ext.kotlin_version = '1.3.31'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // 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
}

gradle-wrapper.properties:

#Mon May 20 12:04:18 CEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

The build fails and returns:

Cannot resolve external dependency com.android.tools.build:gradle because no repositories are defined.

Upvotes: 1

Views: 12088

Answers (2)

Johannes Kraft
Johannes Kraft

Reputation: 257

Okey after doing what you said, removing this:

buildscript {
    ext {
        var = '3.3.2'
    }
    dependencies {
        classpath 'com.android.tools.build:gradle'
    }
}

from the app build.gradle file I got a better error message:

Gradle sync failed: Minimum supported Gradle version is 5.1.1. Current version is 4.6. If using the gradle wrapper, try editing the distributionUrl in c:/local_directory

I was able to search the project for 4.6 and found two gradle wrapper files one in project/gradle/wrapper/gradle-wrapper.properties and project/app/gradle/wrapper/gradle-wrapper.properties

After changing distributionUrl in both places to https\://services.gradle.org/distributions/gradle-5.1.1-all.zipit works.

I did not change these things to start with so why did this problem occur in the first place? Just for future reference.

Upvotes: 1

Martin Zeitler
Martin Zeitler

Reputation: 76669

remove this meaningless part:

buildscript {
    ext {
        var = '3.3.2'
    }
    dependencies {
        classpath 'com.android.tools.build:gradle'
    }
}

Upvotes: 3

Related Questions