Could not resolve com.facebook.react:react-native:+

Tags
 

빌드 에러 메세지

FAILURE: Build failed with an exception. * Where: Build file '/Users/haneojin/Desktop/algocare-device-app/node_modules/react-native-apk-installer-n/android/build.gradle' line: 113 * What went wrong: A problem occurred configuring project ':react-native-apk-installer-n'. > Could not resolve all files for configuration ':react-native-apk-installer-n:implementation'. > Could not resolve com.facebook.react:react-native:+. <-- 이게 핵심 Required by: project :react-native-apk-installer-n > Cannot choose between the following variants of com.facebook.react:react-native:0.71.0-rc.0: - debugVariantDefaultRuntimePublication - releaseVariantDefaultRuntimePublication All of them match the consumer attributes: - Variant 'debugVariantDefaultRuntimePublication' capability com.facebook.react:react-native:0.71.0-rc.0: - Unmatched attributes: - Provides com.android.build.api.attributes.BuildTypeAttr 'debug' but the consumer didn't ask for it - Provides org.gradle.category 'library' but the consumer didn't ask for it - Provides org.gradle.dependency.bundling 'external' but the consumer didn't ask for it - Provides org.gradle.libraryelements 'aar' but the consumer didn't ask for it - Provides org.gradle.status 'release' but the consumer didn't ask for it - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it - Variant 'releaseVariantDefaultRuntimePublication' capability com.facebook.react:react-native:0.71.0-rc.0: - Unmatched attributes: - Provides com.android.build.api.attributes.BuildTypeAttr 'release' but the consumer didn't ask for it - Provides org.gradle.category 'library' but the consumer didn't ask for it - Provides org.gradle.dependency.bundling 'external' but the consumer didn't ask for it - Provides org.gradle.libraryelements 'aar' but the consumer didn't ask for it - Provides org.gradle.status 'release' but the consumer didn't ask for it - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 22s at makeError (/Users/haneojin/Desktop/algocare-device-app/node_modules/execa/index.js:174:9) at /Users/haneojin/Desktop/algocare-device-app/node_modules/execa/index.js:278:16 at processTicksAndRejections (node:internal/process/task_queues:96:5) at async runOnAllDevices (/Users/haneojin/Desktop/algocare-device-app/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5) at async Command.handleAction (/Users/haneojin/Desktop/algocare-device-app/node_modules/@react-native-community/cli/build/index.js:192:9) info Run CLI with --verbose flag for more details. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
 

원인

여기에서 발생하게 된 원인을 상세하게 알려주고 있다.
이 또한 JCenter 서비스가 종료됨에 따라 Maven Central로 옮기게 되면서 발생하게 된 이슈로 보인다.
 
역사적으로 React Native 템플릿 build.gradle은 다음과 같이 React Native Android 라이브러리에 대한 종속성을 포함하는 파일을 제공 implementation("com.facebook.react:react-native:+")했습니다.
특히 이 종속성 선언에서 + 부분은 Gradle이 선언된 모든 리포지토리 중에서 가장 높은 버전을 선택하도록 합니다(종종 Gradle 다이나믹 버전이라고 함).  React-native 0.70 까지는 Maven Repository를 ./android 폴더 안에 넣어서 npm package를 배포하였으나, 0.71 버전 부터는 Maven Central로 업로드 하였습니다.
Gradle Dynamic 버전(즉, +종속성)을 사용하는 것이 이제는 안티패턴으로 간주됩니다( 이 페이지의 다양한 경고 및 참고 사항 참조 ). 특히 지금과 같은 시나리오로 이어질 수 있고 일반적으로 아무 코드도 바꾸지 않았는데 갑자기 빌드가 실패하는 등 프로젝트의 재현성을 낮게 만들기 때문입니다.
에서는 0.71새 앱 템플릿을 정리하고 모든 +종속성을 제거했으며( 여기 참조 ) React Native Gradle 플러그인을 사용하도록 템플릿을 옮겼습니다. 그러면 앞으로 이와 같은 시나리오가 발생하지 않도록 방지할 수 있습니다.
 
notion image
 

영향 받는 사용자

  • ~~ 0.66.* 까지는 전부 영향을 받는다.
  • 0.67 ~ 0.70 까지는 사용하는 서드파티에 따라 영향을 받을 수 있다.

해결방안

 
resolutionStrategy블록을 통해 모든 프로젝트의 com.facebook.react:react-native 버전을 node_modules에 설치된 즉, 실제로 프로젝트에서 사용 중인 React Native 버전으로 강제 적용한다.
 
android/buld.gradle 파일에 아래의 코드들을 추가한다.
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim()) allprojects { configurations.all { resolutionStrategy { // Remove this override in 0.66, as a proper fix is included in react-native itself. force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION } }
 
notion image