Getting error 'RNFirebase core module was not found natively on Android' on Expo

Viewed 2090

I'm trying to run my React Native project using the Expo client on my Android device. I'm getting an error RNFirebase core module was not found natively on Android, ensure you have correctly added the RNFirebase and Firebase gradle dependencies to your 'android/app/build.gradle' I get a similar error when trying to run the app on an iOS Expo client.

I built this project using the starter project provided by React Native Firebase and not create-react-native-app. I am able to run my project locally with yarn run ios/android and the corresponding emulator.

I looked at this post (very similar error screen) and ensured that my MainApplication.java included the import io.invertase.firebase.RNFirebasePackage; and new RNFirebasePackage() statements.

My package.json:

{
  "name": "MyProject",
  "version": "5.4.0",
  "private": true,
  "scripts": {
    "android-bundle": "mkdir -p android/app/src/main/assets && react-native bundle --platform android --dev true --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/",
    "android": "react-native run-android",
    "ios": "react-native run-ios --simulator=\"iPhone X\"",
    "apk": "cd android && ./gradlew assembleRelease",
    "rename": "node ./bin/rename.js",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "expo": "^33.0.7",
    "react": "16.8.3",
    "react-native": "^0.59.9",
    "react-native-datepicker": "^1.7.2",
    "react-native-firebase": "^5.4.0",
    "react-native-gesture-handler": "^1.3.0",
    "react-native-material-bottom-navigation": "^1.0.4",
    "react-native-paper": "^2.16.0",
    "react-native-screens": "^1.0.0-alpha.22",
    "react-native-vector-icons": "^6.5.0",
    "react-navigation": "^3.11.0",
    "react-navigation-material-bottom-tabs": "^1.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.4.3",
    "@babel/runtime": "^7.4.3",
    "babel-jest": "^24.7.1",
    "fs-extra": "^7.0.1",
    "jest": "^24.7.1",
    "metro-react-native-babel-preset": "^0.53.1",
    "react-test-renderer": "16.8.3",
    "replace-in-file": "^3.4.4"
  },
  "jest": {
    "preset": "react-native"
  }
}

My MainApplication.java:

import android.support.multidex.MultiDexApplication;

import com.facebook.react.ReactApplication;
import com.oblador.vectoricons.VectorIconsPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.admob.RNFirebaseAdMobPackage;
import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage;
import io.invertase.firebase.auth.RNFirebaseAuthPackage;
import io.invertase.firebase.config.RNFirebaseRemoteConfigPackage;
import io.invertase.firebase.database.RNFirebaseDatabasePackage;
import io.invertase.firebase.fabric.crashlytics.RNFirebaseCrashlyticsPackage;
import io.invertase.firebase.firestore.RNFirebaseFirestorePackage;
import io.invertase.firebase.functions.RNFirebaseFunctionsPackage;
import io.invertase.firebase.instanceid.RNFirebaseInstanceIdPackage;
import io.invertase.firebase.invites.RNFirebaseInvitesPackage;
import io.invertase.firebase.links.RNFirebaseLinksPackage;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;
import io.invertase.firebase.perf.RNFirebasePerformancePackage;
import io.invertase.firebase.storage.RNFirebaseStoragePackage;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends MultiDexApplication implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages()
    {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new VectorIconsPackage(),
        new RNFirebasePackage(),
        new RNFirebaseAdMobPackage(),
        new RNFirebaseAnalyticsPackage(),
        new RNFirebaseAuthPackage(),
        new RNFirebaseRemoteConfigPackage(),
        new RNFirebaseCrashlyticsPackage(),
        new RNFirebaseDatabasePackage(),
        new RNFirebaseFirestorePackage(),
        new RNFirebaseFunctionsPackage(),
        new RNFirebaseInstanceIdPackage(),
        new RNFirebaseInvitesPackage(),
        new RNFirebaseLinksPackage(),
        new RNFirebaseMessagingPackage(),
        new RNFirebaseNotificationsPackage(),
        new RNFirebasePerformancePackage(),
        new RNFirebaseStoragePackage()
      );
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

My android/app/build.gradle (set up exactly following this guide):

apply plugin: "com.android.application"
apply plugin: "com.google.firebase.firebase-perf"
apply plugin: 'io.fabric'

import com.android.build.OutputFile
import com.google.gms.googleservices.GoogleServicesPlugin

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

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

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.checkbox.checkbox"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    buildTypes {
        release {
            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 project(':react-native-firebase')
    implementation project(':react-native-vector-icons')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"

    implementation project(path: ':react-native-firebase')

    implementation "com.google.firebase:firebase-core:16.0.9"
    implementation "com.google.android.gms:play-services-base:16.1.0"

    implementation('com.google.firebase:firebase-ads:15.0.1') {
      exclude group: 'com.android.support', module: 'customtabs'
    }

    implementation "com.google.firebase:firebase-auth:17.0.0"
    implementation "com.google.firebase:firebase-analytics:16.5.0"
    implementation "com.google.firebase:firebase-perf:16.2.4"
    implementation "com.google.firebase:firebase-config:17.0.0"
    implementation "com.google.firebase:firebase-storage:17.0.0"
    implementation "com.google.firebase:firebase-invites:17.0.0"
    implementation "com.google.firebase:firebase-dynamic-links:17.0.0"
    implementation "com.google.firebase:firebase-database:17.0.0"
    implementation "com.google.firebase:firebase-functions:17.0.0"
    implementation "com.google.firebase:firebase-firestore:19.0.0"
    implementation "com.google.firebase:firebase-messaging:18.0.0"
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
        transitive = true
    }
    implementation "com.android.support:multidex:1.0.3"

    implementation "com.android.support:customtabs:27.1.1"

    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
}

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

apply plugin: 'com.google.gms.google-services'
GoogleServicesPlugin.config.disableVersionCheck = true
0 Answers
Related