skip to Main Content

Expo apk build crash after show splashscreen. Connecting my device to logcat of android studio i see the log that say
"Fatal Exeption: mqt_native_modules"
com.facebook.react.common.JavascriptException: FirebaseError: Firebase: Error (auth/invalid-api-key).
Im using "firebase": "^9.9.3" (sdk)

The values of api-key are in .env file, then in mi app.config.js expo -> extra ->

      "apiKey": process.env.APIKEY,
      "authDomain": process.env.AUTHDOMAIN,
      "projectId": process.env.PROJECTID,
      "storageBucket": process.env.STORAGEBUCKET,
      "messagingSenderId": process.env.MESSAGINGSENDERID,
      "appId": process.env.APPID,
      "measurementId": process.env.MEASUREMENTID

When i run with expo go all works nice, no crash. I made a development build and test with emulator and works too.

When crash logcat dont execute the console.log(firebaseConfig) so i cant see the values.
I also thought if the problem was the credentials in expo.dev (FCM V1 service account key) but I tried modifying and updating the values ​​in the .env but it doesn’t work either.

My firebase.js

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";

import Constants from "expo-constants";

// https://firebase.google.com/docs/web/setup#available-libraries

// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: Constants.expoConfig.extra.apiKey || '',
  authDomain: Constants.expoConfig.extra.authDomain || '',
  projectId: Constants.expoConfig.extra.projectId || '',
  storageBucket: Constants.expoConfig.extra.storageBucket || '',
  messagingSenderId: Constants.expoConfig.extra.messagingSenderId || '',
  appId: Constants.expoConfig.extra.appId || '',
  measurementId: Constants.expoConfig.extra.measurementId || ''
};

// Initialize Firebase
console.log(firebaseConfig);
const app = initializeApp(firebaseConfig);

// Initialize Firebase services
const database = getFirestore(app);
const auth = getAuth(app);

const firebaseServices = { database, auth };

export default firebaseServices;

My .env (is in root)

URL_BACK=xxx
APIKEY=xxx
AUTHDOMAIN=xxx
PROJECTID=xxx
STORAGEBUCKET=xxx
MESSAGINGSENDERID=xxx
APPID=xxx
MEASUREMENTID=xx

Here is my eas.json

{
  "build": {
    "development": {
      "android": {
        "buildType": "apk",
        "developmentClient": true,
        "gradleCommand": ":app:assembleDebug"
      }
    },
    "preview": {
      "android": {
        "buildType": "apk"
      }
    },
    "preview2": {
      "android": {
        "gradleCommand": ":app:assembleRelease"
      }
    },
    "production": {
      "android": {
        "buildType": "apk"
      }
    }
  }
}

2

Answers


  1. Chosen as BEST ANSWER

    I finally deleted the web app in Firebase and created a new one and Instead of taking the data from the .env, I hardcoded it in the firebase.js, and it worked.


    1. In one of your profiles, set both developmentClient: true and buildType: "apk" then build that profile.
    2. Install that build to a device or emulator.
    3. Start the Expo development system (Metro) on your computer (npx expo start)
    4. Start the app on your device/simulator. Since it is a dev client build, it will give you a startup screen asking to connect to your Expo dev system. Any JS code changes you make will sync to your dev client and any console.log() statements in your JS code will now display in the Expo console.
    5. Add a console.log() to see if the values in your firebaseConfig are what you expect them to be just before you call initializeApp(firebaseConfig)

    My bet is that the values are not what you expect them to be. The API Key values are likely incorrect (my guess is they are undefined), which maps onto the specific error message you are getting ("invalid-api-key").

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search