앱 개발 중 npm 캐시 삭제 후 npm install 후 android 파일에서 gradlew clean 후 다시 실행시키려고 했는데
Error: Unable to deserialize cloned data.
에러가 떴다. 이건 리액트 네이티브 Metro가 내부 캐시 파일을 디스크에서 읽다가 손상된 캐시 파일을 파싱하지 못해 발생하는 문제라고 한다.
이후 모든 캐시를 삭제하고 node_modules, package-lock 삭제 후 재설치하면 해결이 될 것이라고 해서 진행했는데 npm install 후 gradlew clean을 하니까
FAILURE: Build failed with an exception. * Where: Settings file 'C:\Users\User\reactn\CatchApp\android\settings.gradle' line: 2 * What went wrong: Plugin [id: 'com.facebook.react.settings'] was not found in any of the following sources:
다시 에러가 떴고
android/setting.gradle에서
plugins {
id("com.facebook.react.settings")
}
선언이 문제라고 에러가 뜨며 삭제해야 한다고 했지만 이건 에러가 발생하기 전에 잘 돌아갔던 설정이었고 .. 이때부터 뭐가 잘못된 것인지 쉽게 해결되지 않을 문제인 것 같다는 생각이 들었다.
어제 저녁부터 계속 붙잡고 있으면서 compileSdkVersion 문제도 뜨고, 연쇄적으로 발생하는 작은 에러들을 stackoverflow와 gpt의 도움을 받으면서 수정해가던 중
기존에 잘 돌아가던 설정들인데 이렇게 수정해가면서 더 문제가 해결될 것 같지 않자 에러가 발생하기 전의 android/build.gradle, android/app/build.gradle로 다시 처음으로 돌리고 npx react-native start --reset-cache 후 다시 gradlew clean하니 빌드가 성공했다..
문제는 처음에 발생한 오류로 gradle 캐시를 삭제했는데 이후 Gradle은 모든 의존성을 다시 원본 위치에서 찾기 때문에 repositories가 명시되지 않으면 에러가 발생한다고 한다. 따라서 Gradle이 com.facebook.react.setting 플러그인을 어디서 받을지 모르기 때문에 해당 플러그인을 찾지 못해서 발생한 에러였다.
android/settings.gradle에서 repositories를 추가하였고 문제가 해결되었다.
pluginManagement {
repositories { // 추가
gradlePluginPortal()
google()
mavenCentral()
}
includeBuild("../node_modules/@react-native/gradle-plugin")
}
plugins {
id("com.facebook.react.settings")
}