2

I'm developing an app using React-Native and I'm trying to connect it to my Firebase database. When I try to run my code (i.e., react-native run-android), I get the following:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
   > Could not find com.google.firebase:firebase-database: 15.0.0.

I've looked at the solutions proposed in Could not find com.google.firebase:firebase-database:9.2.0 and react native Could not find com.google.firebase, but neither have worked for me so far...

Here is my top level build.gradle file:

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 {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
    maven { url "https://maven.google.com" }
    maven { url "https://jitpack.io" }
    }
}

Here is part of my app level build.gradle file:

dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+"  // From node_modules
compile "com.google.firebase:firebase-core:15.0.2"
compile "com.google.firebase:firebase-database: 15.0.0"
compile "com.google.android.gms:play-services-base:15.0.0"

task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}

apply plugin: 'com.google.gms.google-services'
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

How can I fix this issue? Thanks.

Mike
  • 23
  • 1
  • 5

2 Answers2

3

You need to update your gradle and android build plugin the add the google() repo to your project build.gradle.

Update your gradle version to at least version 4.4 by changing your gradle-wrapper.properties in gradle folder to:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

Update build plugin and add google() repo to your build.gradle so that your project build.gradle will become like this:

buildscript {
  repositories {
    jcenter()
    google()
  }
  dependencies {
    // update to version 3.1.3
    classpath 'com.android.tools.build:gradle:3.1.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 {
        mavenLocal()
        jcenter()

        // the following is the same as google()
        //maven { url "https://maven.google.com" }
        google()
        maven { url "https://jitpack.io" }
    }
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • I made these changes but I'm now getting the following error: > Could not find method google() for arguments [] on repository container. Any thoughts? – Mike Jun 21 '18 at 14:20
  • I've made the changes according to your edits but I'm still getting the same error... Any thoughts? – Mike Jun 21 '18 at 14:53
  • It seems the `google()` line is not recognized. Try reverting back to `maven { url "https://maven.google.com" }` – ישו אוהב אותך Jun 21 '18 at 14:57
  • Thanks! I needed maven { url "https://maven.google.com" } in both the all projects repositories and the buildscript repositories. I've also updated to the latest gradle version (4.8). I'm now running into a different issue though... but I'll create a separate question for that. – Mike Jun 21 '18 at 17:40
  • Here is a link to my new issue: https://stackoverflow.com/questions/50976840/could-not-find-com-google-firebasefirebase-database-16-0-1. I would really appreciate your help on this if possible! – Mike Jun 21 '18 at 20:18
1

Add google() in this block:

allprojects {
    repositories {
        google()   // add this
        // others here...
    }
}

It's the repo required for all Android, Firebase, and Play services dependencies. You should add it here too:

buildscript {
    repositories {
        google()
        jcenter()
    }
}

Read more about it here.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Thanks Doug! But now I'm getting the following error: * What went wrong: A problem occurred evaluating root project 'Caravan'. > Could not find method google() for arguments [] on repository container. Any thoughts? Thanks. – Mike Jun 20 '18 at 23:31
  • Upgrade your gradle. Latest version is 4.8. – Doug Stevenson Jun 20 '18 at 23:41
  • Thanks Doug. I've updated my gradle to version 4.8, but I'm still getting the same error... What else could it be? – Mike Jun 20 '18 at 23:49
  • There are no other requirements. Are you sure you're running with gradle 4.8? What change did you make, and how are you verifying that they're effective? – Doug Stevenson Jun 21 '18 at 00:47
  • Thanks Doug! I was able to solve this problem, but now I'm running into another one... Here's a link to my new question: https://stackoverflow.com/questions/50976840/could-not-find-com-google-firebasefirebase-database-16-0-1. I would really appreciate your help on this is possible! – Mike Jun 21 '18 at 20:19
  • Your other problem is exactly like this one. You're missing the google repo. – Doug Stevenson Jun 21 '18 at 23:00
  • I've added the google repo but I'm still getting the same problem... I've gone into more detail in my other question. – Mike Jun 22 '18 at 12:38