I've been at this for a whole day.
I created a new project using npx react-native init Project
. But If I try to run it on android I get this:
FAILURE: Build failed with an exception.
* What went wrong:
Incompatible magic value 0 in class file java/util/logging/ErrorManager
I've went through the docs many times. When I run npx react-native doctor
, I get this:
Android
✓ JDK
✖ Android Studio - Required for building and installing your app on Android
✖ Android SDK - Required for building and installing your app on Android
- Versions found: N/A
- Version supported: 29.0.3
✓ ANDROID_HOME
So there were a few things that were causing this issue.
✖ Android Studio - Required for building and installing your app on Android
It seems that npx react-native doctor
looks for /opt/android-studio, after placing my android studio in /opt/, it was able to detect it.
✖ Android SDK - Required for building and installing your app on Android
- Versions found: N/A
- Version supported: 29.0.3
From what I understood, react native uses sdkmanager script to look for sdk which comes with command line tools when you install android studio. In my case, when I ran the script it was giving me errors. The reason for that was that I hadn't created JAVA_HOME environment variable. So, after creating the environment variable and adding it to PATH, the sdkmanager script ran successfully and so did the react native project.
TL;DR
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
JAVA_HOME
and add it to PATH.