16

Has anyone faced this issue following the official documentation for react-native-firebase?

ERROR: Could not find method platform() for arguments [com.google.firebase:firebase-bom:21.1.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Open File

This happens after editing the two build.gradle files and clicking sync on the Android Studio popup. I think it is there because of a gradle issue.

Any help is welcome. Could not find a similar issue though.

Edited question with the two build.gradle files as per the request by Gabriele Mariotti.

This is the build.gradle file contents.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 23
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'com.android.tools.build:gradle:3.3.1'
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

This is the app/build.gradle file contents.

apply plugin: "com.android.application"

apply from: "../../node_modules/react-native/react.gradle"

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "my.app.id"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 33
        versionName "2.2.2"
        multiDexEnabled true
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'com.google.firebase:firebase-core:17.0.0'
}

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

both build.gradle files are modified according to the documentation.

buddhiv
  • 692
  • 1
  • 7
  • 24

2 Answers2

13

So, I think you're using Gradle 4.x. I had the same issue. Upgrading to 5.0 solved it: https://docs.gradle.org/current/userguide/upgrading_version_4.html

philals
  • 390
  • 2
  • 5
  • 1
    Correct! I updated and came here to update the question and saw this answer. I resolved by going into gradle 5.1.1 – buddhiv Aug 12 '19 at 11:45
  • @buddhiv How have you upgraded the gradle to 5.0? – Kevin Vugts Oct 07 '19 at 11:35
  • 1
    I can't get it working with react-native-firebase v6 – Kevin Vugts Oct 07 '19 at 13:53
  • Kevin I followed the docs to update the gradle version. There are plenty examples to do so. You just change the necessary places and Android Studio will take care of the rest. https://stackoverflow.com/questions/17727645/how-to-update-gradle-in-android-studio – buddhiv Oct 10 '19 at 05:51
8

Solution: put in android/gradle/wrapper/gradle-wrapper.properties:

distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-all.zip

Follow this link: https://github.com/FirebaseExtended/flutterfire/issues/3287

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
rohit
  • 348
  • 3
  • 11