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. Gradle sync failed: Could not read build file ‘E:\Projects\android-tv-live\node_modules\react-native-video\android\build.gradle’ as it does not exist.
  11. The connection to https://services.gradle.org/distributions/gradle-x.x.x-all.zip is slow.
  12. Gradle plugins download is slow

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

Gradle sync failed: Could not read build file ‘E:\Projects\android-tv-live\node_modules\react-native-video\android\build.gradle’ as it does not exist.

Change into E:\Projects\android-tv-live\ and run npm i or yarn to install npm packages.

The connection to https://services.gradle.org/distributions/gradle-x.x.x-all.zip is slow.

Change the Gradle distribution URL in android/gradle/wrapper/gradle-wrapper.properties, find the line that looks like this:

1
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip

Replace it with a faster mirror or a local Gradle distribution. Here is an alternative:

1
https://mirrors.tencent.com/gradle/gradle-8.12-all.zip

Gradle plugins download is slow

Open android/build.gradle add custom mirrors in buildscript.repositories section:

1
2
3
4
5
6
7
8
9
10
11
12
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }

google()
mavenCentral()
}
}

Add:

1
2
3
4
5
6
7
8
9
10
11
12
allprojects {
repositories {
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }

google()
mavenCentral()
}
}

Open android/settings.gradle add custom mirrors in pluginManagement.repositories section:

1
2
3
4
5
6
7
8
9
10
11
12
13
pluginManagement {
repositories {
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }

// Fallback to default repositories
google()
mavenCentral()
}
}

Beside, we need to add these mirrors in .kts files in the node_modules directory.

Search google(), mavenCentral() and mavenCentral(), open all files contain these words and put your mirrors above them:

1
2
3
4
5
6
7
8
9
10
11
12
13
repositories {

maven("https://maven.aliyun.com/repository/central")
maven("https://maven.aliyun.com/repository/jcenter")
maven("https://maven.aliyun.com/repository/google")
maven("https://maven.aliyun.com/repository/public")
maven("https://maven.aliyun.com/repository/gradle-plugin")


mavenCentral()
google()
gradlePluginPortal()
}