I have problems with the installation of firebase Realtime DataBase
I followed the documentation step by step:
First I completely installed firebase App. Then I installed FBRDB. At the time of running the application, it fails.
Similar issues, but solution don't fix my problem:
2353
2069
2512
Note:
Before trying to install Firebase DB, I had to link Firebase V6 with RN0.61.2 otherwise it didn't work
android/build.gradle
:buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 19
compileSdkVersion = 28
targetSdkVersion = 28
}
repositories {
google()
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
//RNFirebase
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
subprojects { subproject ->
afterEvaluate {
if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
android {
variantFilter { variant ->
def names = variant.flavors*.name
if (names.contains("reactNative51") || names.contains("reactNative55") ||
names.contains("reactNative56") || names.contains("reactNative57") ||
names.contains("reactNative57_5")) {
setIgnore(true)
}
}
}
}
}
}
android/app/build.gradle
:apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js",
enableHermes: false,
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.metricsdoqchatapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
//react-native-navigation
missingDimensionStrategy "RNN.reactNativeVersion", "reactNative60"
//
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) {
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"
//react-native-navigation
implementation project(':react-native-navigation')
//react-native-svg
implementation project(':react-native-svg')
//firebase App
implementation project(":@react-native-firebase_app")
//firebase DB
implementation project(":@react-native-firebase_database")
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply plugin: 'com.google.gms.google-services'
android/settings.gradle
:[...]
rootProject.name = 'metricsDoqChatApp'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
//React navigation
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/lib/android/app/')
//react-native-svg
include ':react-native-svg'
project(':react-native-svg').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-svg/android')
//RN Firebase App
include ':@react-native-firebase_app'
project(':@react-native-firebase_app').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/app/android')
//Firebase Data Base
include ':@react-native-firebase_database'
project(':@react-native-firebase_database').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/database/android')
MainApplication.java
:package com.metricsdoqchatapp;
import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Arrays;
import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import com.reactnativenavigation.react.ReactGateway;
//react-native-svg
import com.horcrux.svg.SvgPackage;
//Firebase App
import io.invertase.firebase.app.ReactNativeFirebaseAppPackage;
//firebase DB
import io.invertase.firebase.database.ReactNativeFirebaseDatabasePackage;
public class MainApplication extends NavigationApplication {
@Override
protected ReactGateway createReactGateway() {
ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
@Override
protected String getJSMainModuleName() {
return "index";
}
};
return new ReactGateway(this, isDebug(), host);
}
@Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}
protected List<ReactPackage> getPackages() {
// Add additional packages you require here
// No need to add RnnPackage and MainReactPackage
return Arrays.<ReactPackage>asList(
// eg. new VectorIconsPackage()
new SvgPackage(),
//firebase DB
new MainReactPackage(),
new ReactNativeFirebaseAppPackage(),
new ReactNativeFirebaseDatabasePackage()
);
}
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return getPackages();
}
}
Click To Expand
**`react-native info` output:**
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz
Memory: 2.83 GB / 11.90 GB
Binaries:
Node: 10.16.3 - C:\Program Files\nodejs\node.EXE
Yarn: 1.17.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.11.3 - C:\Program Files\nodejs\npm.CMD
SDKs:
Android SDK:
API Levels: 23, 25, 26, 27, 28, 29
Build Tools: 27.0.3, 28.0.3, 29.0.2
System Images: android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel
x86 Atom, android-28 | Google Play Intel x86 Atom
IDEs:
Android Studio: Version 3.5.0.0 AI-191.8026.42.35.5791312
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.2 => 0.61.2
- **Platform that you're experiencing the issue on**:
- [ ] iOS
- [x ] Android
- [ ] **iOS** but have not tested behavior on Android
- [ ] **Android** but have not tested behavior on iOS
- [ ] Both
- **`react-native-firebase` version you're using that has this issue:**
- ``
- **`Firebase` module(s) you're using that has the issue:**
- `
"@react-native-firebase/app": "^6.0.2"
"@react-native-firebase/database": "^6.0.2",`
Think react-native-firebase
is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]
React Native Firebase
and Invertase
on Twitter for updates on the library.Don't show snippets, show the whole file - these things are subtle and we need to see the whole thing
I think you're missing this which causes autolinking ot fail https://github.com/invertase/react-native-firebase/blob/master/tests/android/app/build.gradle#L16
Don't show snippets, show the whole file - these things are subtle and we need to see the whole thing
I think you're missing this which causes autolinking ot fail https://github.com/invertase/react-native-firebase/blob/master/tests/android/app/build.gradle#L16
Sorry, I update the information.
That is confusing then - it appears auto-linking should work, but you've got manually linked items. Your build is specifically failing because you include MainReactPackage but that is not imported in the java file so the symbol doesn't exist. It shouldn't be necessary either. I would compare and contrast the setup of the tests project in general, linked above in my previous comment, or, following the getting started / new app steps on invertase.io react-native-firebase documentation there is a react-native init command line that uses the special template here to create a template project nicely integrated. Running that should generate something you can compare with to see where the differences are
Fixed adding
import com.facebook.react.shell.MainReactPackage;
Closed.
Saved my ass!
Most helpful comment
Fixed adding
import com.facebook.react.shell.MainReactPackage;
Closed.