This error occurred when trying to run npx react-native run-android
error encountered
I've figured a way to resolve this issue. To resolve this please follow the following steps. Here we'll be trying two steps, if you're lucky the issue will resolve in first step it self.
cd android
(you can also go directly to project/android folder and open cmd there)gradlew clean
(for modern versions: ./gradlew clean
)chmod +x gradlew
If your issue is resolved have a good coding else continue. Most common error is
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
for resolving this please following the below steps,
https://www.oracle.com/java/technologies/javase-jdk14-downloads.html
your_project/android/gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
npx react-native run-android
this worked for me.