Search code examples
androidreact-nativereact-native-cli

Execution failed for task ':app:processDebugMainManifest'. in ReactNative CLI


I try to build a ReactNative app using ReactNative CLI following the steps in their documentation: Link for the documentation

After downloading the initializing the App I tried to run the app:

  1. npx react-native start - to start the metro bundler and it's successfully launched.
  2. npx react-native run-android - to start the application on the android emulator but failed to build.

It gave the following error message:

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01 Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01

Execution failed for task ':app:processDebugMainManifest'.

Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @26c4a53

The problem is I have already added the required path variables as follows. So, how can I get the above error? Does anybody know how to resolve this issue, please?

Screenshot of the powershell output for checking 'User variables':

enter image description here


Solution

  • It seems the problem is associated with the JDK version. There are many solutions I came across in different platforms which relate to the Android SDK and emulator but non solved the issue.
    Finally, I carried out the following steps and the issue was solved.

    1. If you have already installed the JDK 17 or any other version, uninstall it.

    2. Then download and install the JDK version 8
      Refer to the link: Download from here

    3. Set the environmental variables as follows

      Advanced system settings -> Environmental Variables -> System variables

      Next, in the 'System variables' click on 'New' and, add JAVA_HOME (if it is not available) as variable name and add C:\Program Files\Java\jdk1.8.0_202 as the 'Variable value' and Ok.
      This path is the directory path where you installed the JDK. Keep in mind to take the path without including the /bin folder.

      enter image description here

      In the Path of 'System variables', click edit and add the following path variables to the top of the list and save.

      %JAVA_HOME%\bin

      enter image description here

    4. Now restart the computer and rerun the application