Problem

최근 react-native^0.63를 이용하여 새 프로젝트 생성 하고 안드로이드 환경의 앱을 실행할 때 아래와 같이 NoClassDefFoundError와 관련된 에러를 경험했다.

npx react-native init
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app@0.0.1 android: `react-native run-android`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app@0.0.1 android script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
...

Solution

gradle-wrapper.properties 파일의 gradle 버전을 6.3으로 아래와 같이 수정하면 에러를 해결할 수 있다.1 2

distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

References