ERROR: Could not find method platform() for arguments - React Native - Firebase

buddhiv picture buddhiv · Aug 2, 2019 · Viewed 8.9k times · Source

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.

Answer

philals picture philals · Aug 5, 2019

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