invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.69k stars 2.21k forks source link

[🐛] A problem occurred evaluating project ':react-native-firebase_app'. It is too late to set namespace It has already been read to configure this project. #7801

Closed RobertSavage closed 5 months ago

RobertSavage commented 5 months ago

Issue

Describe your issue here Any time I try to build, sync, or clean gradle I get this error.

Error:

Gradle Properties: https\://services.gradle.org/distributions/gradle-8.6-bin.zip Kotlin: kotlinVersion = "1.8.0" J ava: java 19.0.2 2023-01-17 dependencies "com.android.tools.build:gradle:7.6.0-alpha01" "com.google.gms:google-services:4.4.0" "com.facebook.react:react-native-gradle-plugin:+"


Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "name": "copiaReactnativeApp", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "lint": "eslint .", "start": "react-native start", "test": "jest", "bundle:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'", "postinstall": "npm run bundle:ios" }, "dependencies": { "@azure/storage-blob": "^12.17.0", "@bam.tech/react-native-image-resizer": "^3.0.9", "@expo/vector-icons": "^13.0.0", "@fortawesome/fontawesome-svg-core": "^6.5.1", "@fortawesome/react-native-fontawesome": "^0.3.0", "@react-native-async-storage/async-storage": "^1.23.1", "@react-native-async-storage/root": "github:react-native-community/async-storage", "@react-native-community/cli": "^12.3.6", "@react-native-community/cli-platform-android": "^12.3.6", "@react-native-community/cli-platform-ios": "^12.3.6", "@react-native-firebase/app": "^18.9.0", "@react-native-picker/picker": "^2.6.1", "@react-navigation/bottom-tabs": "^6.5.20", "@react-navigation/native": "^6.1.10", "@react-navigation/stack": "^6.3.21", "es6-promise": "^4.2.8", "es6-promise-polyfill": "^1.2.0", "expo-font": "^11.10.3", "expo-modules-core": "^1.11.9", "firebase": "^10.8.0", "install": "^0.13.0", "isomorphic-fetch": "^3.0.0", "metro-react-native-babel-preset": "^0.77.0", "react": "18.2.0", "react-native": "0.73.4", "react-native-background-actions": "^3.0.1", "react-native-background-timer": "^2.4.1", "react-native-config": "^1.5.1", "react-native-document-picker": "^9.1.2", "react-native-dotenv": "^3.4.9", "react-native-element-dropdown": "^2.10.1", "react-native-fs": "^2.20.0", "react-native-gesture-handler": "^2.15.0", "react-native-image-picker": "^7.1.0", "react-native-multiple-select": "^0.5.12", "react-native-permissions": "^4.1.5", "react-native-progress": "^5.0.1", "react-native-progress-bar": "github:mattslight/react-native-progress-bar", "react-native-reanimated": "^3.7.0", "react-native-safe-area-context": "^4.9.0", "react-native-screens": "^3.29.0", "react-native-share": "^10.2.0", "react-native-splash-screen": "^3.3.0", "react-native-svg": "^15.1.0", "react-native-vector-icons": "^10.0.3", "react-navigation": "^5.0.0", "react-router-dom": "^6.22.0", "rn-fetch-blob": "^0.12.0", "stacktrace-parser": "^0.1.10" }, "devDependencies": { "@babel/core": "^7.20.0", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", "@react-native/babel-preset": "0.73.21", "@react-native/eslint-config": "0.73.2", "@react-native/metro-config": "0.73.5", "@react-native/typescript-config": "0.73.1", "@types/react": "^18.2.6", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.6.3", "eslint": "^8.19.0", "jest": "^29.6.3", "prettier": "2.8.8", "react-test-renderer": "18.2.0", "ts-jest": "^29.1.2", "typescript": "5.0.4" }, "engines": { "node": ">=18" } } ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # N/A ``` #### `AppDelegate.m`: ```objc // N/A ```


Android

Click To Expand

#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy buildscript { ext { buildToolsVersion = "34.0.0" minSdkVersion = 21 compileSdkVersion = 34 targetSdkVersion = 34 ndkVersion = "25.1.8937393" kotlinVersion = "1.8.0" } ext.kotlin_version = "1.4.0" repositories { google() mavenCentral() } dependencies { classpath "com.android.tools.build:gradle:7.6.0-alpha01" classpath "com.google.gms:google-services:4.4.0" classpath "com.facebook.react:react-native-gradle-plugin:+" } } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-parcelize' // If you use Kotlin Parcelize apply plugin: 'com.facebook.react.rootproject' java { toolchain { languageVersion = JavaLanguageVersion.of(19) } } android { compileSdkVersion rootProject.ext.compileSdkVersion defaultConfig { applicationId "com.example.yourapplication" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" } namespace "com.example.yourapplication" // This line sets the namespace buildFeatures { viewBinding true } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}" implementation project(':react-native-firebase_app') } ``` #### `android/app/build.gradle`: ```groovy apply plugin: "com.android.application" apply plugin: "org.jetbrains.kotlin.android" apply plugin: "com.facebook.react" /** * This is the configuration block to customize your React Native Android app. * By default you don't need to apply any configuration, just uncomment the lines you need. */ react { /* Folders */ // The root of your project, i.e. where "package.json" lives. Default is '..' // root = file("../") // The folder where the react-native NPM package is. Default is ../node_modules/react-native // reactNativeDir = file("../node_modules/react-native") // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen // codegenDir = file("../node_modules/@react-native/codegen") // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js // cliFile = file("../node_modules/react-native/cli.js") /* Variants */ // The list of variants to that are debuggable. For those we're going to // skip the bundling of the JS bundle and the assets. By default is just 'debug'. // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. // debuggableVariants = ["liteDebug", "prodDebug"] /* Bundling */ // A list containing the node command and its flags. Default is just 'node'. // nodeExecutableAndArgs = ["node"] // // The command to run when bundling. By default is 'bundle' // bundleCommand = "ram-bundle" // // The path to the CLI configuration file. Default is empty. // bundleConfig = file(../rn-cli.config.js) // // The name of the generated asset file containing your JS bundle // bundleAssetName = "MyApplication.android.bundle" // // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' // entryFile = file("../js/MyApplication.android.js") // // A list of extra flags to pass to the 'bundle' commands. // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle // extraPackagerArgs = [] /* Hermes Commands */ // The hermes compiler command to run. By default it is 'hermesc' // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" // // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" // hermesFlags = ["-O", "-output-source-map"] } /** * Set this to true to Run Proguard on Release builds to minify the Java bytecode. */ def enableProguardInReleaseBuilds = false /** * The preferred build flavor of JavaScriptCore (JSC) * * 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:+' android { ndkVersion rootProject.ext.ndkVersion buildToolsVersion rootProject.ext.buildToolsVersion compileSdk rootProject.ext.compileSdkVersion namespace "com.copiareactnativeapp" defaultConfig { applicationId "com.copiareactnativeapp" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" } 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://reactnative.dev/docs/signed-apk-android. signingConfig signingConfigs.debug minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } } } dependencies { // The version of react-native is set by the React Native Gradle Plugin implementation("com.facebook.react:react-android") implementation("com.facebook.react:flipper-integration") if (hermesEnabled.toBoolean()) { implementation("com.facebook.react:hermes-android") } else { implementation jscFlavor } } apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle") ``` #### `android/settings.gradle`: ```groovy rootProject.name = 'copiaReactnativeApp' apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' includeBuild('../node_modules/@react-native/gradle-plugin') include ':app', ':react-native-firebase_app' ``` #### `MainApplication.java`: ```java package com.copiareactnativeapp import android.app.Application import com.facebook.react.PackageList import com.facebook.react.ReactApplication import com.facebook.react.ReactHost import com.facebook.react.ReactNativeHost import com.facebook.react.ReactPackage import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost import com.facebook.react.defaults.DefaultReactNativeHost import com.facebook.react.flipper.ReactNativeFlipper import com.facebook.soloader.SoLoader import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingPackage; class MainApplication : Application(), ReactApplication { override val reactNativeHost: ReactNativeHost = object : DefaultReactNativeHost(this) { override fun getPackages(): List = PackageList(this).packages.apply { // Packages that cannot be autolinked yet can be added manually here, for example: // add(MyReactNativePackage()) } override fun getJSMainModuleName(): String = "index" override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED } override val reactHost: ReactHost get() = getDefaultReactHost(this.applicationContext, reactNativeHost) override fun onCreate() { super.onCreate() SoLoader.init(this, false) if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { // If you opted-in for the New Architecture, we load the native entry point for this app. load() } ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager) } } ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` OUTPUT GOES HERE ``` - **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:** - `10.8.0` - **`Firebase` module(s) you're using that has the issue:** - `e.g. Instance ID` - **Are you using `TypeScript`?** - `No`


RobertSavage commented 5 months ago

The main problem came from non compatible versions. Here are the versions I landed on to fix the problem:

Kotlin: 1.8.0 Gradle: gradle-8.2-all.zip Java: 17

Also in my android/buil.gradle setting the plugin dependency to not be dynamic so classpath "com.facebook.react:react-native-gradle-plugin:8.2"

Then lastly in my android/app/build.gradle I set this as my dependencies:

dependencies {
    implementation 'com.facebook.react:react-native:+'

    // Exclude Flipper integration if not used
    implementation('com.facebook.react:react-native:+') {
        exclude group: 'com.facebook.flipper'
    }

    implementation 'com.facebook.soloader:soloader:0.10.1+'
}