@@ -12,20 +12,38 @@ export const withAndroidMainApplicationDependency: ConfigPlugin<
1212> = ( config ) => {
1313 return withMainApplication ( config , ( mainApplicationProps ) => {
1414 // Import the plugin class.
15- mainApplicationProps . modResults . contents = addBelowAnchorIfNotFound (
16- mainApplicationProps . modResults . contents ,
17- "import expo.modules.ReactNativeHostWrapper;" ,
18- "import com.microsoft.codepush.react.CodePush;"
19- ) ;
15+ const hostWrapperClass = "import expo.modules.ReactNativeHostWrapper" ;
16+ const codePushClass = "import com.microsoft.codepush.react.CodePush" ;
17+
18+ // Expo 50 uses Kotlin and does not require the ;
19+ if ( mainApplicationProps . modResults . contents . includes ( hostWrapperClass ) ) {
20+ mainApplicationProps . modResults . contents = addBelowAnchorIfNotFound (
21+ mainApplicationProps . modResults . contents ,
22+ hostWrapperClass ,
23+ codePushClass
24+ ) ;
25+ }
26+
27+ // Expo 49 uses Java and requires the ;
28+ if (
29+ mainApplicationProps . modResults . contents . includes ( `${ hostWrapperClass } ;` )
30+ ) {
31+ mainApplicationProps . modResults . contents = addBelowAnchorIfNotFound (
32+ mainApplicationProps . modResults . contents ,
33+ `${ hostWrapperClass } ;` ,
34+ `${ codePushClass } ;`
35+ ) ;
36+ }
37+
38+ /**
39+ * Override the getJSBundleFile method in order to let
40+ * the CodePush runtime determine where to get the JS
41+ * bundle location from on each app start
42+ */
2043
2144 // The default on Expo 50, which uses kotlin
2245 const kotlinAnchor = `override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry"` ;
2346 if ( mainApplicationProps . modResults . contents . includes ( kotlinAnchor ) ) {
24- /**
25- * Override the getJSBundleFile method in order to let
26- * the CodePush runtime determine where to get the JS
27- * bundle location from on each app start
28- */
2947 const kotlinJSBundleFileOverride = `
3048 override fun getJSBundleFile(): String? {
3149 return CodePush.getJSBundleFile()
@@ -36,14 +54,10 @@ export const withAndroidMainApplicationDependency: ConfigPlugin<
3654 kotlinAnchor ,
3755 kotlinJSBundleFileOverride
3856 ) ;
57+ return mainApplicationProps ;
3958 }
4059
41- /**
42- * Override the getJSBundleFile method in order to let
43- * the CodePush runtime determine where to get the JS
44- * bundle location from on each app start
45- */
46- const getJSBundleFileOverride = `
60+ const javaJSBundleFileOverride = `
4761 @Override
4862 protected String getJSBundleFile() {
4963 return CodePush.getJSBundleFile();
@@ -59,7 +73,7 @@ export const withAndroidMainApplicationDependency: ConfigPlugin<
5973 mainApplicationProps . modResults . contents = addBelowAnchorIfNotFound (
6074 mainApplicationProps . modResults . contents ,
6175 defaultReactNativeAnchor ,
62- getJSBundleFileOverride
76+ javaJSBundleFileOverride
6377 ) ;
6478
6579 return mainApplicationProps ;
@@ -73,7 +87,7 @@ export const withAndroidMainApplicationDependency: ConfigPlugin<
7387 mainApplicationProps . modResults . contents = addBelowAnchorIfNotFound (
7488 mainApplicationProps . modResults . contents ,
7589 reactNativeHostAnchor ,
76- getJSBundleFileOverride
90+ javaJSBundleFileOverride
7791 ) ;
7892
7993 return mainApplicationProps ;
0 commit comments