skip to Main Content

This is a project that was recently building and deploying with no issues, however after some recent node module imports (realm and @react-native-community/net-info) the installation process for "npx react-native run-android" is consistently failing, indicating that the "build/generated/autolinking/autolinking.json" file cannot be found. In an attempt to fix this, I first removed the latest imports, deleted and reinstalled all node modules (with the –force flag), but the error persisted. I then manually created an empty autolinking.json file to get around this, but now I get the error:

"RNGP – Autolinking: Could not find project.android.packageName in react-native config output! Could not autolink packages without this field."

From what I can see, the packageName is defined properly, I’m assuming the error is referring to the manifest file.

Below is the main AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.naturecounter">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.CAMERA"/>

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <uses-library android:name="org.apache.http.legacy" android:required="false"/>
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported = "true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />

        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
      <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key"/>
      <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
      <meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>
      <!-- <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyDQVy5Jju3QBfHWCQJ0RCXoj45VJS-SIys"/> -->
      <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
                "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name" />
      <activity
          android:name="com.facebook.CustomTabActivity"
          android:exported="true">
          <intent-filter>
              <action android:name="android.intent.action.VIEW" />
              <category android:name="android.intent.category.DEFAULT" />
              <category android:name="android.intent.category.BROWSABLE" />
              <data android:scheme="@string/fb_login_protocol_scheme" />
          </intent-filter>
      </activity>
    </application>
</manifest>

Is there a react-native command for triggering linking? Or am I missing something in my configuration?

react-native v0.71.14

react v18.2.0

android Gradle plugin: 8.4.1

Gradle version: 8.7-bin

2

Answers


  1. The error occurs during the build process in a React Native project, specifically when the autolinking process fails with the message:

    RNGP - Autolinking: Could not find project.android.packageName in react-native config output! Could not autolink packages without this field.
    

    This happens because the React Native CLI cannot find the packageName needed to correctly link the Android project.

    Solution:

    • Step 1: Create or Update react-native.config.js
      If you don’t already have a react-native.config.js file in the root directory of your project, create one. This file is used to configure the React Native CLI.

       module. Exports = {
       project: {
       android: {
         packageName: 'com.nymvp', // Replace 'com.nymvp' with your actual 
        package name
       },
      },
      };
      

    This configuration explicitly defines the packageName for your Android project, which the React Native CLI uses during the autolinking process.

    • Step 2:
      Remove the Existing Autolinking JSON File
      Next, remove the existing autolinking JSON file to ensure that the autolinking process generates a new file based on the updated configuration:
      you can manually delete it from

    /ProjectName/android/build/generated/autolinking/autolinking.json

    or
    by running command:

    rm -rf android/build/generated/autolinking/autolinking.json
    

    This file stores the results of the previous autolinking process, which may be outdated or incorrect if the packageName was not set properly.

    • Step 3:
      Clean and Rebuild the Project
      After making these changes, it’s important to clean and rebuild the project to apply the new configuration:

      cd android
      ./gradlew clean
      cd ..
      npx react-native run-android

    Login or Signup to reply.
  2. This helped me to fix it. Link is here: https://github.com/facebook/react-native/issues/46069#issuecomment-2298066865

    1
    Add autolinkLibrariesWithApp() within the app/build.gradle file.

     react {
          autolinkLibrariesWithApp()
        }
    

    Remove below lines from app/build.gradle file.

    apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle")    applyNativeModulesAppBuildGradle(project)
    

    4
    Remove below line from settings.gradle file.

    apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
    

    5
    Add below lines above the rootProject.name property.

    pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") }
    plugins { id("com.facebook.react.settings") }
    extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }
    rootProject.name = 'ProjectName'
    

    6
    Delete the .build,folder from android

    7
    Remove node_modules, yarn.lock file and run yarn android command to build the application

    Hope it helps you too

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search