Skip to content

Commit

Permalink
Android Notifications : Fix Firebase messaging importation for React …
Browse files Browse the repository at this point in the history
…Native 0.71 and above - Closes cmaycumber#73

Fix Android Notifications issue cmaycumber#73
  • Loading branch information
Tom Berriot committed Feb 22, 2024
1 parent fd91a60 commit 1f609fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
12 changes: 10 additions & 2 deletions packages/intercom-react-native/build/withIntercomAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.contains(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)) {
Expand Down
20 changes: 15 additions & 5 deletions packages/intercom-react-native/src/withIntercomAndroid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.contains(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'`;
Expand Down

0 comments on commit 1f609fe

Please sign in to comment.