Skip to content

Commit a4d1dfd

Browse files
committed
fix: android for expo 50
1 parent d41e409 commit a4d1dfd

File tree

2 files changed

+26
-47
lines changed

2 files changed

+26
-47
lines changed

packages/intercom-react-native/build/withIntercomAndroid.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
55
Object.defineProperty(exports, "__esModule", { value: true });
66
exports.withIntercomMainApplication = exports.withIntercomAppBuildGradle = exports.withIntercomAndroidManifest = exports.withIntercomAndroid = void 0;
77
const config_plugins_1 = require("@expo/config-plugins");
8-
const generateCode_1 = require("@expo/config-plugins/build/utils/generateCode");
98
const image_utils_1 = require("@expo/image-utils");
109
const fs_1 = require("fs");
1110
const path_1 = __importDefault(require("path"));
@@ -35,24 +34,22 @@ async function saveFileAsync(path, content) {
3534
}
3635
function getMainNotificationService(packageName) {
3736
return `package ${packageName};
38-
import expo.modules.notifications.service.ExpoFirebaseMessagingService;
37+
import com.google.firebase.messaging.FirebaseMessagingService;
3938
import com.google.firebase.messaging.RemoteMessage;
4039
import com.intercom.reactnative.IntercomModule;
4140
42-
public class MainNotificationService extends ExpoFirebaseMessagingService {
4341
44-
@Override
45-
public void onNewToken(String refreshedToken) {
42+
public class MainNotificationService extends FirebaseMessagingService {
43+
44+
@Override public void onNewToken(String refreshedToken) {
4645
IntercomModule.sendTokenToIntercom(getApplication(), refreshedToken);
47-
super.onNewToken(refreshedToken);
4846
}
4947
50-
@Override
5148
public void onMessageReceived(RemoteMessage remoteMessage) {
5249
if (IntercomModule.isIntercomPush(remoteMessage)) {
5350
IntercomModule.handleRemotePushMessage(getApplication(), remoteMessage);
5451
} else {
55-
super.onMessageReceived(remoteMessage);
52+
// HANDLE NON-INTERCOM MESSAGE
5653
}
5754
}
5855
}`;
@@ -134,8 +131,8 @@ const withIntercomAndroidManifest = (config, { EURegion, pushNotifications }) =>
134131
exports.withIntercomAndroidManifest = withIntercomAndroidManifest;
135132
const withIntercomProjectBuildGradle = (config) => {
136133
return (0, config_plugins_1.withProjectBuildGradle)(config, async (config) => {
137-
const googleClasspath = `classpath 'com.google.gms:google-services:4.3.15'`;
138-
if (!config.modResults.contents.includes(googleClasspath)) {
134+
const googleClasspath = `classpath 'com.google.gms:google-services:4.2.0'`;
135+
if (!config.modResults.contents.includes('com.google.gms:google-services')) {
139136
const anchor = `dependencies {`;
140137
config.modResults.contents = config.modResults.contents.replace(`${anchor}`, `${anchor}\n\t\t${googleClasspath}`);
141138
}
@@ -144,18 +141,10 @@ const withIntercomProjectBuildGradle = (config) => {
144141
};
145142
const withIntercomAppBuildGradle = (config, { pushNotifications }) => {
146143
return (0, config_plugins_1.withAppBuildGradle)(config, async (config) => {
147-
config.modResults.contents = (0, generateCode_1.mergeContents)({
148-
tag: "okhttp-urlconnection",
149-
src: config.modResults.contents,
150-
newSrc: " implementation 'com.squareup.okhttp3:okhttp-urlconnection:4.10.+'",
151-
anchor: /dependencies\s*\{/,
152-
offset: 1,
153-
comment: "//",
154-
}).contents;
155144
if (pushNotifications) {
156-
const firebaseImp = `implementation 'com.google.firebase:firebase-messaging:23.1.+'`;
145+
const firebaseImp = `implementation 'com.google.firebase:firebase-messaging:20.2.+'`;
157146
if (!config.modResults.contents.includes(firebaseImp)) {
158-
const anchor = `implementation "com.facebook.react:react-native:+" // From node_modules`;
147+
const anchor = `implementation("com.facebook.react:react-android")`;
159148
config.modResults.contents = config.modResults.contents.replace(anchor, `${anchor}
160149
${firebaseImp}`);
161150
}
@@ -209,14 +198,14 @@ const modifyMainApplication = ({ contents, apiKey, appId, packageName, }) => {
209198
}
210199
const importLine = `import com.intercom.reactnative.IntercomModule;`;
211200
if (!contents.includes(importLine)) {
212-
const packageImport = `package ${packageName};`;
201+
const packageImport = `package ${packageName}`;
213202
// Add the import line to the top of the file
214203
// Replace the first line with the intercom import
215-
contents = contents.replace(`${packageImport}`, `${packageImport}\n${importLine}`);
204+
contents = contents.replace(`${packageImport}`, `${packageImport}\n\n${importLine}`);
216205
}
217206
const initLine = `IntercomModule.initialize(this, "${apiKey}", "${appId}");`;
218207
if (!contents.includes(initLine)) {
219-
const soLoaderLine = `SoLoader.init(this, /* native exopackage */ false);`;
208+
const soLoaderLine = `SoLoader.init(this, false)`;
220209
// Replace the line SoLoader.init(this, /* native exopackage */ false); with regex
221210
contents = contents.replace(`${soLoaderLine}`, `${soLoaderLine}\n\t\t${initLine}\n`);
222211
}

packages/intercom-react-native/src/withIntercomAndroid.ts

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,22 @@ async function saveFileAsync(path: string, content: string) {
5252

5353
function getMainNotificationService(packageName: string) {
5454
return `package ${packageName};
55-
import expo.modules.notifications.service.ExpoFirebaseMessagingService;
55+
import com.google.firebase.messaging.FirebaseMessagingService;
5656
import com.google.firebase.messaging.RemoteMessage;
5757
import com.intercom.reactnative.IntercomModule;
5858
59-
public class MainNotificationService extends ExpoFirebaseMessagingService {
6059
61-
@Override
62-
public void onNewToken(String refreshedToken) {
60+
public class MainNotificationService extends FirebaseMessagingService {
61+
62+
@Override public void onNewToken(String refreshedToken) {
6363
IntercomModule.sendTokenToIntercom(getApplication(), refreshedToken);
64-
super.onNewToken(refreshedToken);
6564
}
6665
67-
@Override
6866
public void onMessageReceived(RemoteMessage remoteMessage) {
6967
if (IntercomModule.isIntercomPush(remoteMessage)) {
7068
IntercomModule.handleRemotePushMessage(getApplication(), remoteMessage);
7169
} else {
72-
super.onMessageReceived(remoteMessage);
70+
// HANDLE NON-INTERCOM MESSAGE
7371
}
7472
}
7573
}`;
@@ -170,8 +168,9 @@ export const withIntercomAndroidManifest: ConfigPlugin<{
170168

171169
const withIntercomProjectBuildGradle: ConfigPlugin<object> = (config) => {
172170
return withProjectBuildGradle(config, async (config) => {
173-
const googleClasspath = `classpath 'com.google.gms:google-services:4.3.15'`;
174-
if (!config.modResults.contents.includes(googleClasspath)) {
171+
const googleClasspath = `classpath 'com.google.gms:google-services:4.2.0'`;
172+
173+
if (!config.modResults.contents.includes('com.google.gms:google-services')) {
175174
const anchor = `dependencies {`;
176175
config.modResults.contents = config.modResults.contents.replace(
177176
`${anchor}`,
@@ -186,20 +185,11 @@ const withIntercomProjectBuildGradle: ConfigPlugin<object> = (config) => {
186185
export const withIntercomAppBuildGradle: ConfigPlugin<{
187186
pushNotifications: boolean;
188187
}> = (config, { pushNotifications }) => {
189-
return withAppBuildGradle(config, async (config) => {
190-
config.modResults.contents = mergeContents({
191-
tag: "okhttp-urlconnection",
192-
src: config.modResults.contents,
193-
newSrc:
194-
" implementation 'com.squareup.okhttp3:okhttp-urlconnection:4.10.+'",
195-
anchor: /dependencies\s*\{/,
196-
offset: 1,
197-
comment: "//",
198-
}).contents;
188+
return withAppBuildGradle(config, async (config) => {
199189
if (pushNotifications) {
200-
const firebaseImp = `implementation 'com.google.firebase:firebase-messaging:23.1.+'`;
190+
const firebaseImp = `implementation 'com.google.firebase:firebase-messaging:20.2.+'`;
201191
if (!config.modResults.contents.includes(firebaseImp)) {
202-
const anchor = `implementation "com.facebook.react:react-native:+" // From node_modules`;
192+
const anchor = `implementation("com.facebook.react:react-android")`;
203193
config.modResults.contents = config.modResults.contents.replace(
204194
anchor,
205195
`${anchor}
@@ -287,19 +277,19 @@ const modifyMainApplication = ({
287277

288278
const importLine = `import com.intercom.reactnative.IntercomModule;`;
289279
if (!contents.includes(importLine)) {
290-
const packageImport = `package ${packageName};`;
280+
const packageImport = `package ${packageName}`;
291281
// Add the import line to the top of the file
292282
// Replace the first line with the intercom import
293283
contents = contents.replace(
294284
`${packageImport}`,
295-
`${packageImport}\n${importLine}`
285+
`${packageImport}\n\n${importLine}`
296286
);
297287
}
298288

299289
const initLine = `IntercomModule.initialize(this, "${apiKey}", "${appId}");`;
300290

301291
if (!contents.includes(initLine)) {
302-
const soLoaderLine = `SoLoader.init(this, /* native exopackage */ false);`;
292+
const soLoaderLine = `SoLoader.init(this, false)`;
303293
// Replace the line SoLoader.init(this, /* native exopackage */ false); with regex
304294
contents = contents.replace(
305295
`${soLoaderLine}`,

0 commit comments

Comments
 (0)