React Native 0.57 업그레이드 후 Android 빌드 이슈 해결
문제 상황
프로젝트를 React Native 0.57로 업그레이드한 후 Android 빌드가 계속 실패했다. iOS는 정상 동작했지만 Android만 FAILURE: Build failed with an exception 에러가 발생했다.
Could not resolve all files for configuration ':app:debugCompileClasspath'.
> Could not find support-v4.aar
원인 분석
RN 0.57부터 AndroidX를 지원하기 시작했고, 서드파티 라이브러리들이 아직 AndroidX로 마이그레이션되지 않은 상태였다. react-native-vector-icons와 react-native-camera 등이 구버전 support 라이브러리를 참조하고 있었다.
해결 방법
1. jetifier 적용
npm install --save-dev jetifier
npx jetify
jetifier를 사용해 node_modules 내 라이브러리를 AndroidX로 변환했다.
2. gradle.properties 수정
android.useAndroidX=true
android.enableJetifier=true
3. build.gradle 버전 통일
allprojects {
repositories {
google()
jcenter()
}
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
}
}
}
}
}
모든 서브프로젝트의 compileSdkVersion을 통일시켰다.
결과
빌드가 정상적으로 완료되었고, postinstall 스크립트에 jetifier를 추가해 매번 실행되도록 설정했다.
{
"scripts": {
"postinstall": "npx jetify"
}
}
RN 업그레이드는 항상 네이티브 종속성 문제가 동반된다. 특히 Android는 버전 파편화가 심해 더 신경 써야 한다.