androidreact-nativegradle-pluginpackage-name

Upon attempting to deploy React-Native project on android emulator, experience React Native Autolinking Failure


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


Solution

  • 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