Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: Gradle Build Error No repositories are defined

Andriod Studio 3.3.1

gradle 4.4

I added firebase storage through the Android > Tools > Firebase option. However when I sync the gradle the build fails. This is the error that I'm getting:

Cannot resolve external dependency com.google.gms:google-services:3.2.1 
because no repositories are defined. Required by:project :app

Does anyone know how to correct this error?

build.gradle (Module: APP)

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.example.test"
    minSdkVersion 16
    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'
    }
}
compileOptions {
    targetCompatibility 1.8
    sourceCompatibility 1.8
}
}

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'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.google.firebase:firebase-core:15.0.0'
    implementation 'com.google.firebase:firebase-storage:15.0.0'
    implementation 'com.google.firebase:firebase-auth:15.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:design:27.1.1'
    //implementation 'com.google.android.gms:play-services:11.0.4'
}

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:3.2.1'
    }
}

apply plugin: 'com.google.gms.google-services'
like image 965
Val Avatar asked Apr 22 '18 01:04

Val


3 Answers

In my case, I have to add below code to project level gradle:

allprojects {
    repositories {
        google()
        jcenter()

    }
}
like image 173
Jithin Jude Avatar answered Nov 02 '22 22:11

Jithin Jude


The error indicates that repositories is missing in order to determine from where google-services will be downloaded.

buildscript {
    repositories {
       jcenter()
    }
    dependencies {
        classpath 'com.google.gms:google-services:3.2.1'
    }
}

jcenter is a reference to bintray jcenter. Gradle can find the google-services:3.2.1 there.

like image 30
xiaomi Avatar answered Nov 03 '22 00:11

xiaomi


In my case I was able to get it working by adding another repository scope to the top level.

repositories {
    mavenLocal()
    mavenCentral()
}

I was inspired to do so by this example.

like image 22
Naruto Sempai Avatar answered Nov 02 '22 23:11

Naruto Sempai