본문 바로가기
  • 바쁜 일상 속 작은 기억
React Native

[React Native] SplashScreen 에러 : MainActivityDelegate cannot be converted to Activity SplashScreen.show(this);

by hellomingure 2022. 12. 19.

이번 리네 프로젝트 Splash Screen 작업하다가 발견한 이슈. 이 전 프로젝트에서 쓰던대로 그대로 splash screen 설치해서 작업하는데................

yarn add eact-native-splash-screen

https://github.com/crazycodeboy/react-native-splash-screen

 

GitHub - crazycodeboy/react-native-splash-screen: A splash screen for react-native, hide when application loaded ,it works on iO

A splash screen for react-native, hide when application loaded ,it works on iOS and Android. - GitHub - crazycodeboy/react-native-splash-screen: A splash screen for react-native, hide when applicat...

github.com

 

 Android   MainApplication.java file 파일에서 설정해줘야 하는 작업 하니....

요딴 에러가 떨어지는거 있지뭐에여........

BUILD FAILED in 12s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/Users/minjiseo/buyaladdin/BRApp/BuyaladdinApp/android/app/src/main/java/com/aladdin/com/aladdin/MainActivity.java:59: error: incompatible types: MainActivityDelegate cannot be converted to Activity
      SplashScreen.show(this);
                        ^
Note: /Users/minjiseo/myFolder/MyAppName/AppName/android/app/src/debug/java/com/AppName/com/AppName/ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

 

지난 프로젝트와 달라진 점은, React Native 버전이 0.70.0 대로 올라왔다는 것 뿐인데, 리네 버전 업데이트 된지 얼마 되지 않은 시기에 splash screen 라이브러리 설치해서 새로운 프로젝트 진행중인 사람이 많지 않아서 그런건지 해당 오류에 대한 자료가 많지 않았다. 

 

그래서 아예 라이브러리 이슈 등록 해버리기..!!!!!

https://github.com/crazycodeboy/react-native-splash-screen/issues/591#issue-1424947030

 

MainActivityDelegate cannot be converted to Activity SplashScreen.show(this); · Issue #591 · crazycodeboy/react-native-splash-

Run react-native info in your project and share the content. Node : 16.17.0 Yarn : 1.22.19 react : 18.1.0 react-native : 0.70.0 What react-native-splash-screen version are you using? "react-na...

github.com

 

혹시나 나와 같은 이슈가 있다면 해당 링크에서 답을 찾을 수 있다. 간단하게 답을 설명하자면,

SplashScreen.show(this); 를 추가해 줘야 하는 onCreate 부분이 내 경우 ReactActivityDelegate 안에 들어있었다. 

@Override
  protected ReactActivityDelegate createReactActivityDelegate() {
  
  //...내 다른 코드들
 
   @Override
    protected void onCreate(Bundle savedInstanceState) {
    
     SplashScreen.show(this);
     super.onCreate(null);
     
    } 
  }

이 코드를 아예 ReactActivityDelegate 밖으로 빼내서 독립적으로 넣어주었다. 아래 이미지 참고하면 된다.

그랬더니, 완전 깔끔하게 오류 해결 끝!