React Native - Build Failed with 2 errors

If you are a developer, you must have come across this situation where your application build failed with errors. It can be really frustrating, especially when you are not sure about the root cause of the problem. In this article, we will discuss one such error that you might encounter while building your React Native application.

The error we are going to discuss has two parts:

  1. Problem occurred while evaluating the project ':app'

  2. compiledSdkVersion is not specified

Let's understand the meaning of these errors and possible solutions to fix them.

  1. Problem occurred while evaluating the project ':app': This error message is usually encountered while building a React Native application with the Android platform. It means that there is an issue with the project evaluation process. There can be various reasons for this error, such as issues with the build.gradle files or dependencies not being installed properly.

Possible solution: One of the most common solutions for this error is to delete the node_modules folder and reinstall all the dependencies. To do this, open the terminal in the root directory of your project and run the following commands:

rm -rf node_modules
npm install

This will remove the node_modules folder and reinstall all the dependencies. After that, try to build your project again and see if the error is resolved.

  1. compiledSdkVersion is not specified: This error message is also encountered while building a React Native application with the Android platform. It means that the target SDK version is not specified in the build.gradle file.

Possible solution: To fix this error, you need to specify the target SDK version in the build.gradle file. To do this, follow these steps:

  1. Open the Android Studio and navigate to your React Native project.

  2. Expand the android folder and open the build.gradle file.

  3. Look for the following line of code:

targetSdkVersion //add target SDK version here
  1. Replace the comment with the target SDK version that you want to use. For example:
targetSdkVersion=30
  1. Save the file and try to build your project again.

If the above solution does not work, you can try running the following command in the terminal:

cd android
./gradlew clean

Note: ./android/gradlew clean command might not work, so better change directory to andriod folder.

This will clean the project and rebuild it from scratch. After that, try to build your project again and see if the error is resolved.

In conclusion, encountering build errors is a common issue while developing React Native applications. However, by following the above solutions, you can easily fix the "Problem occurred while evaluating the project ':app'" and "compiledSdkVersion is not specified" errors.