[RN] 코드푸시 DevInternalSettings is not public in com.facebook.react.devsupport 에러 해결방법
최근 codepush 라이브러리를 적용하는데 있어서 안드로이드에서 예전 레퍼런스라서 최근 react-native kotlin으로 만들어진 파일내에서 처리하는 방법은 어떻게 하는지 알아봤습니다.
문서에는 아래와 같이 java파일을 수정하라고 설명되어있는데
// 1. Import the plugin class.
import com.microsoft.codepush.react.CodePush;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
...
// 2. Override the getJSBundleFile method to let
// the CodePush runtime determine where to get the JS
// bundle location from on each app start
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
};
}
현재는 MainApplication.kt으로 만들어져 있어서 위의 내용과 다르지만 아래와 같이 추가하면 됩니다.
import com.microsoft.codepush.react.CodePush;
...
override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> {
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return PackageList(this).packages
}
override fun getJSMainModuleName(): String = "index"
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
override fun getJSBundleFile(): String = CodePush.getJSBundleFile()
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
}
...
위의 방식대로 구성하고 build를 돌리면 제목과 같은 에러가 발생하는데, 현재 react-native 0.73.1 버전과 react-native-code-push 최신버전에서 android 모듈내의 패키지 임포트 문제인것같습니다.
git 이슈를 찾아본 결과, 아래처럼 해결하시면 됩니다.
먼저 patch를 적용해야하는데,
1. patch-package를 설치하고, 아래 코드 실행. 첫번째의 경우 직접 수정하고 두번째 명령어로 patch파일을 생성합니다. (현재 리액트 네이티브 프로젝트 루트 디렉토리에서 진행)
# 1. 노드모듈안의 코드푸시 자바 파일 임포트 수정
vim node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java
# 2. run patch-package으로 패치 파일 생성
npx patch-package react-native-code-push
2. 현프로젝트루트/patches/react-native-code-push+8.1.1.patch와 같은 파일이 생성됬을텐데 위의 1번을 진행안했다면 아래 코드 덮어쓰기.
diff --git a/node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java b/node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java
index 923dd15..91f8ac8 100644
--- a/node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java
+++ b/node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java
@@ -10,7 +10,8 @@ import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
-import com.facebook.react.devsupport.DevInternalSettings;
+//import com.facebook.react.devsupport.DevInternalSettings;
+import com.facebook.react.devsupport.DevSettingsActivity;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.uimanager.ViewManager;
@@ -152,7 +153,7 @@ public class CodePush implements ReactPackage {
if (instanceManager != null) {
DevSupportManager devSupportManager = instanceManager.getDevSupportManager();
if (devSupportManager != null) {
- DevInternalSettings devInternalSettings = (DevInternalSettings)devSupportManager.getDevSettings();
+ DevSettingsActivity devInternalSettings = (DevSettingsActivity)devSupportManager.getDevSettings();
Method[] methods = devInternalSettings.getClass().getMethods();
for (Method m : methods) {
if (m.getName().equals("isReloadOnJSChangeEnabled")) {
3. 아래 코드 패키지에 추가하고 (필요한지 모르겠음..), 아래 명령어 실행.
"scripts": {
...
"postinstall": "patch-package"
...
}
yarn add patch-package postinstall-postinstall
4. 패치 적용되고 다시 안드로이드 빌드하면 성공할겁니다.
참고 링크
https://github.com/microsoft/react-native-code-push/issues/2631
https://github.com/ds300/patch-package#readme