React-native-firebase: Error when installing Auth Package

Created on 14 Feb 2020  路  28Comments  路  Source: invertase/react-native-firebase

**EDIT: fixed in 6.3.4

Issue

I have a new fresh project made today with react native. When I install "@react-native-firebase/auth" I get a error when building the app for android. The issue is only with the auth package, cause I builded the app only with "@react-native-firebase/app" (I have it installed) and it worked.

* What went wrong:
A problem occurred evaluating project ':react-native-firebase_auth'.
> Project with path ':@react-native-firebase_app' could not be found in project ':react-native-firebase_auth'.

Project Files

package.json:

{
  "name": "freelouEstabelecimento",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "pod": "cd ./ios && pod install && cd ..",
    "release": "cd ./android %% ./gradlew assemblerelease && cd ..",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.6",
    "@react-native-firebase/app": "^6.3.3",
    "@react-native-firebase/auth": "^6.3.3",
    "@react-navigation/bottom-tabs": "^5.0.3",
    "@react-navigation/native": "^5.0.3",
    "@react-navigation/stack": "^5.0.3",
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-gesture-handler": "^1.5.6",
    "react-native-navigation-bar-color": "^1.0.0",
    "react-native-reanimated": "^1.7.0",
    "react-native-safe-area-context": "^0.7.3",
    "react-native-screens": "^2.0.0-beta.2",
    "react-native-svg": "^11.0.1",
    "react-native-touchable-scale": "^2.1.0"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.5.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.56.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

Android

android/app/build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
 *   bundleCommand: "ram-bundle",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,  // clean and rebuild if changing
]

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

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore.
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US.  Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
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.freelouestabelecimento"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            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 {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            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:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            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 fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

// 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 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 = 'freelouEstabelecimento'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'

MainApplication.java:

package com.freelouestabelecimento;

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;

public class MainApplication extends Application implements ReactApplication {

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

        @Override
        protected List<ReactPackage> getPackages() {
          @SuppressWarnings("UnnecessaryLocalVariable")
          List<ReactPackage> packages = new PackageList(this).getPackages();
          // Packages that cannot be autolinked yet can be added manually here, for example:
          // packages.add(new MyReactNativePackage());
          return packages;
        }

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

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

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    initializeFlipper(this); // Remove this line if you don't want Flipper enabled
  }

  /**
   * Loads Flipper in React Native templates.
   *
   * @param context
   */
  private static void initializeFlipper(Context context) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */
        Class<?> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
        aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
}

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.freelouestabelecimento">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

Environment

react-native info output:

System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
    Memory: 915.63 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 13.7.0 - /usr/local/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.6 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK:
      API Levels: 25, 27, 28, 29
      Build Tools: 28.0.3, 29.0.2
      System Images: android-29 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5900203
    Xcode: 11.2/11B52 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.5 => 0.61.5
  • Platform that you're experiencing the issue on:

    • [x] Android but have not tested behavior on iOS

  • react-native-firebase version you're using that has this issue:

    • 6.3.3

  • Firebase module(s) you're using that has the issue:

    • "@react-native-firebase/app", "@react-native-firebase/auth"

  • Are you using TypeScript?

    • N

Build Error Android Auto-linking issue React Native >= 6

Most helpful comment

Looks like @amorino is right. This appears to be the change that's causing this issue: https://github.com/react-native-community/cli/pull/910. Rolling @react-native-community/cli-platform-android back to 3.0.3 fixed the problem for me.

If you're using yarn, you can add this to your package.json as a temporary fix:

"resolutions": {
  "**/@react-native-community/cli-platform-android": "=3.0.3"
}

Then run yarn install && react-native link, and your gradle builds should work again.

All 28 comments

I am getting thesame issues with all packages, Auth, Admob, Analytics, Messaging. Please help

Here is my react native info

info Fetching system and libraries information...

info Fetching system and libraries information...
System:
    OS: Windows 10 10.0.18362
    CPU: (8) x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
    Memory: 10.24 GB / 23.96 GB
  Binaries:
    Node: 10.15.3 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.0 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.13.7 - C:\Program Files\nodejs\npm.CMD
  SDKs:
    Android SDK:
      API Levels: 23, 24, 26, 27, 28
      Build Tools: 24.0.2, 27.0.3, 28.0.3
      System Images: android-28 | Google APIs Intel x86 Atom, android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: Version  3.5.0.0 AI-191.8026.42.35.5900203
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.5 => 0.61.5

These are the firebase packages i have :

    "@react-native-firebase/admob": "^6.3.3",
    "@react-native-firebase/analytics": "^6.3.3",
    "@react-native-firebase/app": "^6.3.3",
    "@react-native-firebase/auth": "^6.3.3",
    "@react-native-firebase/messaging": "^6.3.3",

have same issue with @react-native-firebase/app and @react-native-firebase/messaging packages installed

I'm also facing this issue same issue

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

  • Where:
    Build file '/home/user/projects/projectname/node_modules/@react-native-firebase/storage/android/build.gradle' line: 60

  • What went wrong:
    A problem occurred evaluating project ':@react-native-firebase_storage'.

    Project with path ':@react-native-firebase_app' could not be found in project ':@react-native-firebase_storage'.

  • Try:

    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

2: Task failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':@react-native-firebase_storage'.

    compileSdkVersion is not specified.

  • Try:

    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

I reproduce this with my rnfbdemo v6 script https://github.com/mikehardy/rnfbdemo/blob/master/make-demo-v6.sh - appears something about react-native-firebase 6.3.2 is broken on android. Investigating...

Sorry - no time to investigate actually. But I can confirm it at least. The missing compileSdkVersion is something I have seen before, it is a secondary problem and just a distraction. The first problem is the one to investigate and then compileSdkVersion will resolve itself

@mikehardy what temporary solution do you recommend to do? Downgrade to a working version?

Ahh okay, thanks for looking into it @mikehardy. I thought this was my fault been stuck on this issues for quite some time since upgrading react native. I will await the fix

As a temporary fix I would say yes, incrementally backing down until you find a version that works seems reasonable. There are real fixes in the recent releases so it is only a stopgap but a build failure is a hard stop of course, no reason not to work around that by any means available

I downgraded to Version 6.0.0 and the error continue to appear

@amorino Now that's a problem. I have a working project with v6.0.2 I think. I will try to downgrade it next Monday and post the results here.

I am having this problem too, I downgraded until 6.0.0 but still having this problem,
I have it with firebase/analytics

I fixed the issue by adding the dependencies to settings.gradle and build.gradle following this link but at this point I'm really confused since I'm using RN 0.61.4 and auto-linking should work ...

So perhaps if you have package-lock.json or yarn.lock in source control that's the thing to bisect. I know react-native 0.62 is getting close to stable and the react-native-cli pushed a version out. Could be the CLI messed up something about android auto-linking - smells like that to me though I have not done the work to test that hypothesis yet. When I did an initial investigation here I did not see anything in react-native-firebase's gradle/android area at all - no changes - so it would not surprise me if it was a dependency vs this package

I manual linked react-native-firebase/app and it work using react-native run-android, but if you check the gradle on Android Studio, two dependencies are added to the project. I believe that the new autolinking is linking the project as react-native-firebase_app instead of @react-native-firebase_app and maybe that's the problem.

I have this issue too. Hope for a solution 馃檹

Looks like @amorino is right. This appears to be the change that's causing this issue: https://github.com/react-native-community/cli/pull/910. Rolling @react-native-community/cli-platform-android back to 3.0.3 fixed the problem for me.

If you're using yarn, you can add this to your package.json as a temporary fix:

"resolutions": {
  "**/@react-native-community/cli-platform-android": "=3.0.3"
}

Then run yarn install && react-native link, and your gradle builds should work again.

@Salakar / @thymikee we have a CLI / react-native-firebase issue at present from the 'remove @ from module names' CLI change, FYI

@bjyoungblood great work pinning it down

Looks like we'll have to do a find project in gradle for old and new and use whichever exists now for backwards compat, will sort this afternoon

confirmed success building in my demo script, looks like this:

https://github.com/mikehardy/rnfbdemo/blob/b103c5911d8e06ca81bd7aa0a31c3fa7d2f0951e/make-demo-v6.sh#L11-L12

echo "Temporary workaround for CLI issue"
yarn add @react-native-community/[email protected]

It's quite unfortunate this commit https://github.com/react-native-community/cli/commit/874ce4a1d89cc60b23cfa7160460eb7c12490a0f broke your use case without a warning. Can we do a better job at documenting this?

@thymikee I think in this instance it's probably my fault, I was aware this change was coming as I did approve it on the original PR - I just didn't get around to changing our code soon enough 馃檲

I'm not sure if there is many other libs that this is an issue for, quite a niche case I think 馃

New release with this in will be out shortly, thank you

Released in 6.3.4

The workaround mentioned above regarding setting cli-platform-android to 3.0.3 works for me but I am still experiencing the issue after updating the firebase components to 6.3.4 - does anyone have any pointers please?

This is the error when running any gradle command.

  • What went wrong:
    A problem occurred evaluating project ':app'.
    Project with path ':@react-native-firebase_perf' could not be found in project ':app'.

Using the workaround resolves this but it looks from the comments above that the workaround shouldn't be needed when using 6.3.4?

The workaround is definitely not needed in 6.3.4 - I just expanded / verified my v6 demo script on Sunday and it worked fine. Perhaps you have a stale yarn.lock or something?

Thanks @mikehardy for sharing your demo script - that helped me to identify my issue which turned out to be an incorrect migration from v5.

Some of the _react-native-firebase_ components were still referenced in the build.gradle script, rather than being properly picked up using Auto Linking, as your sample project project and script helped to highlight.

Glad that helped @julianD77 ! Good luck with your project

Was this page helpful?
0 / 5 - 0 ratings