7. Gradle Errors in React-Native

Today I am going to show you errors that I commonly faced in my React-Native Development phase.

Error 1:

FAILURE: Build failed with an exception. \ What went wrong: Could not open settings generic class cache for settings file 'E:\REACT-NATIVE\Awesome2Project\android\settings.gradle'*

(C:\Users\maroo\.gradle\caches\7.5.1\scripts\dik46fhmman8isugvn7v0x0ex). > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 63

Solution:

Check for the Compatible Gradle version for your React Native, for me it's Gradle Version : 7.6.1 compatible with React Native version 0.71.6 .

  1. Update Gradle Version: Open the android/gradle/wrapper/gradle-wrapper.properties file in your React Native project.

  2. In the gradle-wrapper.properties file, locate the distributionUrl property. It should look something like this:

     distributionUrl=https\://services.gradle.org/distributions/gradle-X.X.X-all.zip
    
  3. Make sure the version number (X.X.X) is set to a compatible and more recent Gradle version.

Error 2:

Why Only Package.json, Package-lock.json, Node Modules folder is created, Where are the rest Files and Folders.

Solution:

Instead of using this command to create a React-Native project:

npx react-native init ProjectName

Use this:

npx react-native@latest init ProjectName

The @latest part ensures that you are using the latest version of React Native. By running this command, it will download the latest version of React Native and initialize a new project with all the necessary files and folders.