Skip to content
Advertisement

React native issue firebase messaging

I am trying to install the react native firebase messaging module to my project so I can remotely send notifications.

When I built my app yarn android/react-native build-android I got an error in which I have been trying to fix for the last 3 hours.

build.gradle:

apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'  // Google Services plugin
...
dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules

    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    implementation platform('com.google.firebase:firebase-bom:28.1.0')
    implementation 'com.google.firebase:firebase-analytics'

    implementation project(path: ":@react-native-firebase_app")
    implementation project(path: ":@react-native-firebase_messaging")

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
      exclude group:'com.facebook.fbjni'
    }

    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

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

settings.gradle:

rootProject.name = 'NerdeeMobile'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'

include ':@react-native-firebase_app'
project(':@react-native-firebase_app').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/app/android')

include ':@react-native-firebase_messaging'
project(':@react-native-firebase_messaging').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/messaging/android')

MainApplication.java:

import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.ReactActivity;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import io.invertase.firebase.app.ReactNativeFirebaseAppPackage;
import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingPackage;
...
@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());
          packages.add(new ReactNativeFirebaseMessagingPackage());
          // return packages;
          return packages;
        }

Error/Output:

245 actionable tasks: 2 executed, 243 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeLibDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform classes.jar (project :@react-native-firebase_app) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: C:xampphtdocsProjectsnerdeeNerdeeMobilenode_modules@react-native-firebaseappandroidbuildintermediatesruntime_library_classes_jardebugclasses.jar.
         > Unable to read jar file C:xampphtdocsProjectsnerdeeNerdeeMobilenode_modules@react-native-firebaseappandroidbuildintermediatesruntime_library_classes_jardebugclasses.jar
   > Failed to transform classes.jar (project :react-native-firebase_app) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: C:xampphtdocsProjectsnerdeeNerdeeMobilenode_modules@react-native-firebaseappandroidbuildintermediatesruntime_library_classes_jardebugclasses.jar.
         > Unable to read jar file C:xampphtdocsProjectsnerdeeNerdeeMobilenode_modules@react-native-firebaseappandroidbuildintermediatesruntime_library_classes_jardebugclasses.jar

* 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

BUILD FAILED in 7s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeLibDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform classes.jar (project :@react-native-firebase_app) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: C:xampphtdocsProjectsnerdeeNerdeeMobilenode_modules@react-native-firebaseappandroidbuildintermediatesruntime_library_classes_jardebugclasses.jar.
         > Unable to read jar file C:xampphtdocsProjectsnerdeeNerdeeMobilenode_modules@react-native-firebaseappandroidbuildintermediatesruntime_library_classes_jardebugclasses.jar
   > Failed to transform classes.jar (project :react-native-firebase_app) to match attributes {artifactType=android-dex, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.api.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-incremental-transform=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: C:xampphtdocsProjectsnerdeeNerdeeMobilenode_modules@react-native-firebaseappandroidbuildintermediatesruntime_library_classes_jardebugclasses.jar.
         > Unable to read jar file C:xampphtdocsProjectsnerdeeNerdeeMobilenode_modules@react-native-firebaseappandroidbuildintermediatesruntime_library_classes_jardebugclasses.jar

* 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

BUILD FAILED in 7s

    at makeError (C:xampphtdocsProjectsnerdeeNerdeeMobilenode_modulesexecaindex.js:174:9)
    at C:xampphtdocsProjectsnerdeeNerdeeMobilenode_modulesexecaindex.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (C:xampphtdocsProjectsnerdeeNerdeeMobilenode_modules@react-native-communitycli-platform-androidbuildcommandsrunAndroidrunOnAllDevices.js:94:5)
    at async Command.handleAction (C:xampphtdocsProjectsnerdeeNerdeeMobilenode_modules@react-native-communityclibuildindex.js:186:9)

Any help is greatly appreciated.

Advertisement

Answer

Add after => import com.facebook.react.ReactApplication;

import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingPackage; 

Remove:

packages.add(new ReactNativeFirebaseMessagingPackage());
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement