react-native-netinfo: 🔥 Error: Program type already present: com.reactnativecommunity.netinfo.BroadcastReceiverConnectivityReceiver$1

Environment

System:
    OS: macOS 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 34.59 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 8.9.4 - /usr/local/bin/node
    npm: 6.9.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
    Android SDK:
      API Levels: 23, 25, 26, 27, 28
      Build Tools: 26.0.2, 26.0.3, 27.0.2, 27.0.3, 28.0.2, 28.0.3
      System Images: android-28 | Google Play Intel x86 Atom, android-P | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5692245
    Xcode: 10.1/10B61 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.4 => 0.60.4 
  npmGlobalPackages:
    create-react-native-app: 1.0.0
    react-native-cli: 2.0.1
    react-native-git-upgrade: 0.2.7

Platforms

Android

package.json

{
  "name": "moodPixel",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "postinstall": "npx jetify",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-community/netinfo": "^4.1.4",
    "axios": "^0.19.0",
    "chroma-js": "^2.0.2",
    "moment": "^2.23.0",
    "react": "16.8.6",
    "react-native": "0.60.4",
    "react-native-chart-kit": "^3.0.0",
    "react-native-clean-project": "^3.2.4",
    "react-native-color-picker": "github:FrederickEngelhardt/react-native-color-picker",
    "react-native-device-info": "^2.3.2",
    "react-native-easy-toast": "^1.2.0",
    "react-native-firebase": "^5.5.6",
    "react-native-fs": "^2.13.3",
    "react-native-google-drive-api-wrapper": "^1.1.2",
    "react-native-google-places": "^3.1.1",
    "react-native-google-signin": "^1.2.3",
    "react-native-image-crop-picker": "^0.25.0",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-localization": "^2.1.5",
    "react-native-location": "^2.3.0",
    "react-native-router-flux": "^4.0.6",
    "react-native-sentry": "^0.43.2",
    "react-native-sortable-grid": "^2.0.0",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^9.5.1",
    "react-native-svg-charts": "^5.3.0",
    "react-native-swiper": "^1.5.14",
    "react-native-text": "0.0.8",
    "react-native-vector-icons": "^6.1.0",
    "react-native-video": "^5.0.0",
    "react-redux": "^6.0.0",
    "recyclerlistview": "^1.3.4",
    "redux": "^4.0.1",
    "redux-persist": "^5.10.0",
    "redux-thunk": "^2.3.0",
    "rn-fetch-blob": "^0.10.16",
    "unsplash-js": "^5.0.0"
  },
  "devDependencies": {
    "@babel/core": "7.5.5",
    "@babel/runtime": "7.5.5",
    "@react-native-community/eslint-config": "0.0.3",
    "babel-jest": "^24.8.0",
    "eslint": "^6.1.0",
    "jest": "^24.8.0",
    "jetifier": "^1.6.3",
    "metro-react-native-babel-preset": "0.54.1",
    "react-test-renderer": "16.8.6"
  },
  "jest": {
    "preset": "react-native"
  },
  "rnpm": {
    "assets": [
      "src/assets/fonts/Poppins"
    ]
  }
}

Description

When running ./gradlew assembleRelease does not let me compile.

I get the following error:

> Task :app:transformClassesWithMultidexlistForRelease FAILED
D8: Program type already present: com.reactnativecommunity.netinfo.BroadcastReceiverConnectivityReceiver$1

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForRelease'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list:
  Error while merging dex archives: 
  Program type already present: com.reactnativecommunity.netinfo.BroadcastReceiverConnectivityReceiver$1
  Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.

I have npx jetify in my post-install scripts and have migrated several libs to AndroidX. However, this lib has thrown this new error.

Furthermore, when inspecting using Android Studio I can see the following error:

ERROR: The modules ['@react-native-community_netinfo', 'react-native-community-netinfo'] point to the same directory in the file system.
Each module must have a unique path.

I think this might be the cause of the error.

android/settings.gradle

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

include ':react-native-community-netinfo'
project(':react-native-community-netinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/netinfo/android')
include ':react-native-image-crop-picker'
project(':react-native-image-crop-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-crop-picker/android')
include ':react-native-google-places'
project(':react-native-google-places').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-places/android')
include ':react-native-location'
project(':react-native-location').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-location/android')
include ':react-native-video'
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer')
include ':react-native-firebase'
project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android')
include ':react-native-linear-gradient'
project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android')
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-splash-screen'   
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
include ':react-native-localization'
project(':react-native-localization').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-localization/android')
include ':rn-fetch-blob'                                                                                                  
project(':rn-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/rn-fetch-blob/android')
include ':react-native-fs'
project(':react-native-fs').projectDir = new File(settingsDir, '../node_modules/react-native-fs/android')
include ':react-native-google-signin', ':app'
project(':react-native-google-signin').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-signin/android')
include ':react-native-svg'
project(':react-native-svg').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-svg/android')

include ':app'

android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
        googlePlayServicesAuthVersion = "15.0.1"
        googlePlayServicesVersion = "16.+"
        firebaseVersion = "17.3.4"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.3.0'
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven { url "https://jitpack.io" }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        google()
        jcenter()
    }
}

android/gradle.properties

android.useAndroidX=true
android.enableJetifier=true

android/app/build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    enableHermes: true,
    entryFile: "index.js",
    //bundleCommand: "ram-bundle",
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.moodpixel"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 35
        versionName "3.2"
        multiDexEnabled true
    }
    dexOptions {
        jumboMode true
        incremental true
        javaMaxHeapSize "4g"
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }

    packagingOptions {
        pickFirst '**/armeabi-v7a/libc++_shared.so'
        pickFirst '**/x86/libc++_shared.so'
        pickFirst '**/arm64-v8a/libc++_shared.so'
        pickFirst '**/x86_64/libc++_shared.so'
        pickFirst '**/x86/libjsc.so'
        pickFirst '**/armeabi-v7a/libjsc.so'
    }
}

dependencies {
    // enabling multiDex for minSdkVersion below 20 (current is 16)
    implementation 'androidx.multidex:multidex:2.0.1'

    // react-native
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules

    // 3rd party
    implementation project(':rn-fetch-blob')
    implementation project(':react-native-fs')
    implementation project(':react-native-svg')
    implementation project(':react-native-video')
    implementation project(':react-native-location')
    implementation project(':react-native-device-info')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-localization')
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-google-signin')
    implementation project(':react-native-google-places')
    implementation project(':react-native-linear-gradient')
    implementation project(':react-native-community-netinfo')
    implementation project(':react-native-image-crop-picker')
    
    // react-native-firebase
    implementation project(':react-native-firebase')
    implementation "com.google.android.gms:play-services-base:16.0.1"
    implementation 'com.google.firebase:firebase-analytics:17.0.1'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.google.firebase:firebase-auth:18.1.0'
    implementation 'com.google.firebase:firebase-firestore:20.2.0'
    implementation "com.google.firebase:firebase-ads:18.1.1"
    implementation "com.google.firebase:firebase-messaging:19.0.1"
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
    implementation "com.google.android.gms:play-services-location:16.0.0"

    if (enableHermes) {
      def hermesPath = "../../node_modules/hermesvm/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
      implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

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

android/app/src/main/java/your/package/name/MainApplication.java

package com.moodpixel;

import java.util.List;
import android.util.Log;
import android.app.Application;
import androidx.multidex.MultiDexApplication;

// react native
import com.facebook.react.PackageList;
import com.facebook.soloader.SoLoader;
import com.facebook.react.ReactPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactApplication;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;

// react-native-firebase
import io.invertase.firebase.auth.RNFirebaseAuthPackage;
import io.invertase.firebase.admob.RNFirebaseAdMobPackage;
import io.invertase.firebase.firestore.RNFirebaseFirestorePackage;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;

public class MainApplication extends MultiDexApplication implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      
      // Packages that cannot be autolinked yet can be added manually here, for example:
      packages.add(new RNFirebaseAuthPackage());
      packages.add(new RNFirebaseAdMobPackage());
      packages.add(new RNFirebaseFirestorePackage());
      packages.add(new RNFirebaseMessagingPackage());
      packages.add(new RNFirebaseNotificationsPackage());
    
       
      return packages;
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (3 by maintainers)

Most upvoted comments

Anyway I fixed my problem so for those who are having this kind of problem… What I did was, first i typed this command gradelw app:dependencies to check if there are duplicates in dependencies… so what happened was the Jitsi Package is using the old version of netinfo so i just add this inside my app/build.gradle…

implementation(project(':react-native-jitsi-meet')) {
        exclude group: 'com.facebook.react',module:'react-native-community-async-storage'
        exclude group: 'com.facebook.react',module:'react-native-community_netinfo'
}

then viola! everything went ok…

@wmonecke It looks like your issue is that you have “auto-linking” enabled, while also linking some projects manually. In theory this should work with the auto-linking system just ignoring the ones you are manually linking, however, my guess is that because of the special characters in this libraries module name (@react-native-community/netinfo) the name it’s checking for is different to the one you are using.

To test this theory, you can do one of two things:

  1. Remove this library from your manual linking and leave it to the auto-linking system to handle for you.
  2. Change the name of the linked library from react-native-community-netinfo to @react-native-community_netinfo.

My preference would be to number 1 as this is the cleanest solution. I would recommend moving as many of your dependencies to being automatically linked rather than manually linked to avoid any confusion.

Let me know if that doesn’t work for you and I will reopen the issue to investigate further.

For those who for some reason need manual linking (e.g using https://github.com/wix/react-native-navigation), create a react-native.config.js at the root of your project folder with these contents :

module.exports = {
  dependencies: {
    '@react-native-community/netinfo': {
      platforms: {
        android: null, // disable Android platform, other platforms will still autolink if provided
      },
    },
  },
};

@matt-oakes Thanks for the hint! It works now. I removed references from:

  • android/settings.gradle
  • android/app/build.gradle
  • android/app/src/main/java/your/package/name/MainApplication.java

for anyone else with this issues.

👋 Thanks for submitting this issue. It sounds like you’re linking the project twice. Can you please provide the full contents of these files:

  • android/settings.gradle
  • android/build.gradle
  • android/gradle.properties
  • android/app/build.gradle
  • android/app/src/main/java/your/package/name/MainApplication.java

Anyway I fixed my problem so for those who are having this kind of problem… What I did was, first i typed this command gradelw app:dependencies to check if there are duplicates in dependencies… so what happened was the Jitsi Package is using the old version of netinfo so i just add this inside my app/build.gradle…

implementation(project(':react-native-jitsi-meet')) {
        exclude group: 'com.facebook.react',module:'react-native-community-async-storage'
        exclude group: 'com.facebook.react',module:'react-native-community_netinfo'
}

then viola! everything went ok…

I love you

@eskiesirius cd android && ./gradlew clean and make sure you don’t have multiple references to netinfo in your project anywhere. Might be two somehow, either in package.json or your gradle stuff your java stuff