From 9dfcc6fa1f0def5eb0e40682d17722c214f10165 Mon Sep 17 00:00:00 2001 From: Tom Berriot Date: Thu, 22 Feb 2024 15:19:53 +0100 Subject: [PATCH] Android Notifications : Fix Firebase messaging importation for React Native 0.71 and above - Closes #73 Fix Android Notifications issue https://github.com/cmaycumber/config-plugin-react-native-intercom/issues/73 --- .../build/withIntercomAndroid.js | 12 +++++++++-- .../src/withIntercomAndroid.ts | 20 ++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/intercom-react-native/build/withIntercomAndroid.js b/packages/intercom-react-native/build/withIntercomAndroid.js index 7308ce86..5c0d2621 100644 --- a/packages/intercom-react-native/build/withIntercomAndroid.js +++ b/packages/intercom-react-native/build/withIntercomAndroid.js @@ -155,9 +155,17 @@ const withIntercomAppBuildGradle = (config, { pushNotifications }) => { if (pushNotifications) { const firebaseImp = `implementation 'com.google.firebase:firebase-messaging:23.1.+'`; if (!config.modResults.contents.includes(firebaseImp)) { + const anchor = `implementation "com.facebook.react:react-native:+" // From node_modules`; - config.modResults.contents = config.modResults.contents.replace(anchor, `${anchor} - ${firebaseImp}`); + // In RN 0.71 and beyond, React Native Gradle Plugin is used, so import of firebase has to be adapted + if (config.modResults.contents.includes(anchor)) { + config.modResults.contents = config.modResults.contents.replace(anchor, `${anchor} + ${firebaseImp}`); + } else { + const anchorForReactNative071 = `implementation("com.facebook.react:react-android")`; + config.modResults.contents = config.modResults.contents.replace(anchorForReactNative071, `${anchorForReactNative071} + ${firebaseImp}`); + } } const applyPlugin = `apply plugin: 'com.google.gms.google-services'`; if (!config.modResults.contents.includes(applyPlugin)) { diff --git a/packages/intercom-react-native/src/withIntercomAndroid.ts b/packages/intercom-react-native/src/withIntercomAndroid.ts index a7f579ac..95080310 100644 --- a/packages/intercom-react-native/src/withIntercomAndroid.ts +++ b/packages/intercom-react-native/src/withIntercomAndroid.ts @@ -200,11 +200,21 @@ export const withIntercomAppBuildGradle: ConfigPlugin<{ const firebaseImp = `implementation 'com.google.firebase:firebase-messaging:23.1.+'`; if (!config.modResults.contents.includes(firebaseImp)) { const anchor = `implementation "com.facebook.react:react-native:+" // From node_modules`; - config.modResults.contents = config.modResults.contents.replace( - anchor, - `${anchor} - ${firebaseImp}` - ); + // In RN 0.71 and beyond, React Native Gradle Plugin is used, so import of firebase has to be adapted + if (config.modResults.contents.includes(anchor)) { + config.modResults.contents = config.modResults.contents.replace( + anchor, + `${anchor} + ${firebaseImp}` + ); + } else { + const anchorForReactNative071 = `implementation("com.facebook.react:react-android")`; + config.modResults.contents = config.modResults.contents.replace( + anchorForReactNative071, + `${anchorForReactNative071} + ${firebaseImp}` + ); + } } const applyPlugin = `apply plugin: 'com.google.gms.google-services'`;