androidlinuxreact-nativemanjaro

Cant get react native project to run on android


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

Solution

  • 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

    1. You need to have your android studio folder in opt and it must be named android-studio.
    2. Install android sdk command line tools(latest) and add it to your PATH like this export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
    3. Also create JAVA_HOME and add it to PATH.