0

I am trying to setup firebase on my android studio.I am using a 2.2.3 version.So this is my code in app.gradle file:

   apply plugin: 'com.android.application'

    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"
        defaultConfig {
            applicationId "com.example.parth.carpool"
            minSdkVersion 22
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-a`enter code here`nnotations'
        })
        compile 'com.android.support:appcompat-v7:25.2.0'
        compile 'com.google.firebase:firebase-core:16.0.1'
        testCompile 'junit:junit:4.12'
    }
    apply plugin: 'com.google.gms.google-services'

This is the error that I am receiving.

Error:(27, 13) Failed to resolve: com.google.firebase:firebase-core:16.0.1

This is my project.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:2.2.3'
        classpath 'com.google.gms:google-services:4.0.0'

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

allprojects {
    repositories {
        jcenter()
    }
}

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

To correct this error I installed google play services, google repository, SDK platform,SDK platform tools etc. after I saw some of the posts on stackoverflow. Does anybody have a solution?

parth
  • 41
  • 6

5 Answers5

2

First you need to upgrade android studio to the newest version:

If you're not using Android Studio 3.1 to develop your app, you will need to upgrade in order to get the correct version checking behavior within the IDE.

https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html

Then you need to use the following top level gradle file:

buildscript {
 repositories {
      google()
      jcenter()
  }



dependencies {
 classpath 'com.android.tools.build:gradle:3.1.3'
 classpath 'com.google.gms:google-services:4.0.1'
 }
}

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

task clean(type: Delete) {
  delete rootProject.buildDir
  }
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • Your gonna have to upgrade eventually, to use `google()` you need android studio 3.0+, but for older versions you can use `maven { url "https://maven.google.com" }`. The google() repo contains the firebase libraries and other support libraries – Peter Haddad Aug 04 '18 at 13:30
1

Android Studio provides Awesome tool called Firebase Assistant, it handles any thing you need to setup firebase in you'r project

from Tools->Firebase

enter image description here

just pick which product you want and it'll do all the work for you

Sayed El-Abady
  • 247
  • 2
  • 12
1

Make sure you are connected to a good network

Goto >file -> other settings -> Under build, execution, and deployment -> you will see Gradle. uncheck the checkbox offline work. Then rebuild your project.

 buildscript {
repositories {

    // add google here
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    classpath 'com.google.gms:google-services:4.0.0'

}
}

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

task clean(type: Delete) {
delete rootProject.buildDir
}
olajide
  • 972
  • 1
  • 13
  • 26
0

Did you try on this link

In your root build.gradle file add the repo:

maven { url "https://maven.google.com" }
JustKhit
  • 407
  • 3
  • 9
0

It depends upon you how you want to setup you can try both explicit way and implicit way of setting up firebase .the easiest one is implicit one which is given in android studio

Suleman Khan
  • 1
  • 1
  • 3