5

I have did my React-native setup following instructions from https://reactnative.dev/docs/environment-setup

Project has been created successfully.

Android phone also connected using USB but when I try to install App on phone using command-

npx react-native run-android

Following error occured and BUILD FAILED

what went wrong

Could not initialize class org.codehaus.groovy.reflection.ReflectionCache

Error:

Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7

I'm using Powershell to perform commands.

jdk
  • 451
  • 1
  • 6
  • 18

1 Answers1

8

The answer was very simple I got it after about a week of posting this question.

You just need to update to latest gradle version.

  1. Go to android > gradle > gradle-wrapper.properties file in your project folder.

In gradle-wrapper.properties file change the following line with latest version of gradle:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
  1. Just change the version number 6.7.1 to the latest number.

Run command again to build your app:

npx react-native run-android

It resolved my problem and React-native app got installed on android phone using USB.

jdk
  • 451
  • 1
  • 6
  • 18