Sajad Beheshti
Sajad Beheshti

Reputation: 689

Android studio error - react native using firebase

i get this error :

The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[15.0.1,15.0.1], [15.0.0,15.0.0]], but resolves to 15.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

android/build.gradle

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
         classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.google.gms:google-services:4.0.1'
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()

        /// notice the same objecct maven, but with different url
        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'
        }
    }
}

android/app/build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile


project.ext.react = [
    entryFile: "index.js"
]

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


def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.xapp1"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    implementation(project(':react-native-firebase')) {
        transitive = false
    }
//    implementation project(':react-native-config')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:23.0.1"
    implementation "com.facebook.react:react-native:+" // From node_modules
    implementation "com.google.android.gms:play-services-base:11.6.0"
    // Firebase dependencies
    implementation 'com.google.firebase:firebase-core:11.8.0'
    implementation "com.google.firebase:firebase-firestore:17.0.2"
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}
apply plugin: 'com.google.gms.google-services'

Help me please, it's about 4 days i'm looking for the resolve, thanks.

Upvotes: 2

Views: 540

Answers (1)

Ravi Raj
Ravi Raj

Reputation: 6677

Update your react-native-firebase to version v4.3.8 then perform npm or yarn install.

Then configure your app/build.gradle as follows,

dependencies {
    // Other dependencies for react-native

    // RNFirebase
    implementation project(':react-native-firebase')

    // RNFirebase required dependencies
    implementation "com.google.android.gms:play-services-base:15.0.1"
    implementation "com.google.firebase:firebase-core:16.0.1"

    // RNFirebase optional depedencies
    implementation "com.google.firebase:firebase-firestore: 17.0.4"

}

The error you get is due to mismatch of direct or transitive dependencies versions.

check out the app/build.gradle file from the sample project of react-native-firebase,

https://github.com/invertase/react-native-firebase/blob/master/bridge/android/app/build.gradle

Use proper versions, tell if it works. Thanks

Upvotes: 1

Related Questions