프레임워크/React Native

[ReactNative] FCM+AsyncStorage 설치 후 build failed

pythaac 2022. 2. 18. 16:58

1. 현상

  react native로 android를 타겟으로 한 프로그램 작성 도중에 아래와 같은 현상이 발생했습니다. 이전에 정상적으로 build와 emulator가 실행되었었고, FCM과 AsyncStorage 사용을 위한 패키지 설치 및 테스트 도중 발생하였습니다.

 

2. 문제 접근

1) [실패] app:mergeLibDexDebug FAILED

  mergeLibDexDebug에 관련하여 검색해본 결과, 아래와 같이 android/app/build.gradle에 추가 삽입이 필요하다는 내용을 확인하였습니다.

android {
    ...
    defaultdConfig {
        ...
        multiDexEnabled true
        ...
    }
    dependencies {
        ...
        implementation 'androidx.multidex:multidex:2.0.1'
    }
}

그러나 같은 문제가 여전히 발생하였습니다.

 

2) [실패] @react-native-firebase/app과 react-native-firebase

  @react-native-firebase/app과 react-native-firebase를 모두 설치해서 발생하는 문제로, @react-native-firebase/app을 삭제하여 해결하였다는 내용도 검색하였습니다. FCM을 처음 시도해보느라 이것저것 설치했던 것 같아서 저도 같은 방식으로 시도를 해보았으나, 에러메시지가 바뀌고 해결되지 않았습니다.

여기서 확인해봐야할 에러 메시지들은 다음과 같았습니다.

  • Deprecated Gradle features were used in this build, making it imcompatible with Gradle 8.0
  • 1. Task failed with an exception
    • Where : Build file '...\node_modules\@react-native-firebase\messaging\android\build.gradle
    • What : A problem occurred evaludating project ':react-native-firebase_messaging'.
      > Could not find the react-native-firebase/app package, have you installed it?
  • 2. Task failed with an exception
    • What : A problem occurred configuring project ':react-native-firebase_messaging'.
      >  com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

3) [해결] npm init

분명 @react-native-firebase/app을 uninstall했는데 계속 해당 패키지에 접근하다가 생기는 문제로 보였습니다. 그래서 npm ls를 통해 패키지들을 확인해보았는데, uninstall이 정상작동하지 않는 것으로 보였습니다. 그래서 아래와 같은 방식으로 해결하였습니다.

  • npm init으로 초기화
  • package.json에서 @react-native-firebase\messaging 직접 삭제
  • npm install 후 실행

 


이 후 App은 빌드+실행이 되었으나, 결국 messaging을 사용하기 위해서는 @react-native-firebase가 필요했습니다. 아래 문서에도 @가 붙은 패키지를 설치하라고 나와있네요.

https://rnfirebase.io/

 

React Native Firebase | React Native Firebase

Welcome to React Native Firebase! To get started, you must first setup a Firebase project and install the "app" module. React Native Firebase is the officially recommended collection of packages that brings React Native support for all Firebase services on

rnfirebase.io

 

결국 @react-native-firebase가 아닌 react-native-firebase를 package.json에서 삭제하여 해결하였습니다.