react native trouble shooting

  1. Could not find com.android.tools.build:gradle:8.1.1.
  2. Could not determine the dependencies of task ‘:app:compileDebugKotlin’.
  3. No online devices found.
  4. Unable to load script.
  5. generate index.android.bundle
  6. Crash on Android 5.1
  7. ERROR: JAVA_HOME is not set and no ‘java’ command could be found in your PATH.
  8. Exception in thread “main” java.io.IOException: Downloading from https://services.gradle.org/distributions/gradle-7.5.1-all.zip failed: timeout
  9. Could not open settings generic class cache for settings file
  10. SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project’s local properties fil

Could not find com.android.tools.build:gradle:8.1.1.

  1. Check dependencies in build.gradle, ensure that the following dependency exists:
1
2
3
dependencies {
classpath 'com.android.tools.build:gradle:8.1.1'
}
  1. Open https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/8.1.1/gradle-8.1.1.pom in your browser and ensure it is accessible.

  2. Sync project with gradle files

Could not determine the dependencies of task ‘:app:compileDebugKotlin’.

  1. Check your network connection and/or proxy settings.

No online devices found.

Unable to load script.

Make sure you’re either running Metro (run ‘npx react-native start’) or that your bundle ‘index.android.bundle’ is packaged correctly for release.

generate index.android.bundle

To generate the index.android.bundle file for your React Native app in Android Studio, follow these steps:

  1. Open a Terminal or Command Prompt:
  • Navigate to your project’s root directory using the terminal or command prompt.
  1. Run the Following Command:
  • Execute the following command to generate the index.android.bundle file:
    react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
  • This command will create the bundle file and place it in the specified location.
  1. Build Your App:
    • After generating the bundle, you can proceed with building your app using Android Studio or by running the following command:
      cd android && ./gradlew assembleRelease
    • This will create the APK file for your React Native app.

Crash on Android 5.1

  1. Use the React Native 0.71.x version, newer versions have dropped support for Android 5.1
  2. Run the following command to create a TV project for Android 5.1+:
1
npx [email protected] init TestApp [email protected]

This command will create a new project named TestApp in the TestApp directory using the react-native-tvos template.

ERROR: JAVA_HOME is not set and no ‘java’ command could be found in your PATH.

First, download and install the JDK (Java Development Kit) if it’s not already installed:

  • Go to the Java JDK download page or install OpenJDK.
  • Install the JDK following the instructions for your operating system

Set the JAVA_HOME Environment Variable

Once the JDK is installed, you’ll need to set JAVA_HOME and add it to your system PATH.

On Windows:
Open System Properties > Advanced > Environment Variables.
Under System Variables, click New and enter:

  • Variable name: JAVA_HOME
  • Variable value: The path to your JDK installation, usually something like C:\Program Files\Java\jdk-17.

Find the Path variable under System Variables, click Edit, and add a new entry:
Add %JAVA_HOME%\bin to the path list.

Restart any open command prompts or terminals.

Exception in thread “main” java.io.IOException: Downloading from https://services.gradle.org/distributions/gradle-7.5.1-all.zip failed: timeout

My solution was to update my global ~/.gradle/gradle.properties file with the correct proxy settings:

1
2
3
4
5
6
org.gradle.daemon=true
systemProp.https.proxyHost=proxy.company.net
systemProp.https.proxyPort=8181
systemProp.http.proxyHost=proxy.company.net
systemProp.http.proxyPort=8181
systemProp.https.nonProxyHosts=*.company.com|localhost

Could not open settings generic class cache for settings file

So the problem arises from inconsistency in the Java version installed on your machine, the default Java version configured on your android studio and the gradle version for your project.

https://docs.gradle.org/current/userguide/compatibility.html

SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project’s local properties fil