React-native: [android] Native module AccessibilityInfo tried to override AccessibilityInfoModule.

Created on 1 Oct 2019  路  6Comments  路  Source: facebook/react-native

I am upgrading my RN from 0.59.10 to 0.60.5. When i run react-native run-android my app loads but i am greeted with

 Native module AccessibilityInfo tried to override AccessibilityInfoModule. Check the getPackages() method in MainApplication.java, it might be that module is being created twice. if this was your intention, set canOverrideExistingModule=true

I have checked my MainApplication.java and i cannot see any modules being instantiated twice...

React Native version:

 System:
    OS: macOS 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
    Memory: 137.17 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.10.0 - /usr/local/bin/node
    npm: 6.11.3 - /usr/local/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2
      System Images: android-25 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 11.0/11A420a - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.5 => 0.60.5 
  npmGlobalPackages:
    react-native-cli: 2.0.1

Steps To Reproduce

  1. Upgrade to RN0.60.5
  2. run react-native run-android

Describe what you expected to happen:
App to build/run

MainApplication.java

package com.enlitened;

import android.app.Application;
import android.content.Context;

import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage;

import com.appboy.AppboyLifecycleCallbackListener;
import com.appboy.support.AppboyLogger;

import java.util.Arrays;
import java.util.List;
import java.lang.reflect.InvocationTargetException;

public class MainApplication extends Application 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.add(new MainReactPackage());
      packages.add(new RNFirebasePackage());
      packages.add(new RNFirebaseAnalyticsPackage());
      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);
    initializeFlipper(this); // Remove this line if you don't want Flipper enabled
    // AppboyLogger.setLogLevel(Log.VERBOSE);
    registerActivityLifecycleCallbacks(new AppboyLifecycleCallbackListener(true, true));
  }

  /**
   * Loads Flipper in React Native templates.
   *
   * @param context
   */
  private static void initializeFlipper(Context context) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */
        Class<?> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
        aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
}


update
Tried upgrading to 0.60.1
Now getting similar error to the above but it is now:

TimePickerAndroid tried to override com.facebook.react.modules.timepicker.TimePickerDialogModule.

Check updated MainApplication.java example.

AccessibilityInfo Bug Android

Most helpful comment

Try remove this line:

packages.add(new MainReactPackage());

All 6 comments

It looks like you are using an older version of React Native. Please update to the latest release, v0.61 and verify if the issue still exists.

The "Resolution: Old Version" label will be removed automatically once you edit your original post with the results of running react-native info on a project using the latest release.

@react-native-bot Have tried updating to 0.60.1 See update at bottom of initial report.

Try remove this line:

packages.add(new MainReactPackage());

Try remove this line:

packages.add(new MainReactPackage());

Also you might want to unlink libraries that are manually linked.

Thank you @gabrieltobi & @radko93

I went through sequencially removing each packages.add(new ...) until the build worked.

Also you might want to unlink libraries that are manually linked.
^ I try to unlink my libraries (RNFirebase etc) but i don't know if maybe i'm just doing it incorrectly but some of the libraries do not unlink properly and then when i manually unlink them they do not auto-link very well.

I've worked around this issue in my app with this deeply disturbing hack in my MainApplication.java:

  public List<ReactPackage> getPackages() {
    ArrayList<ReactPackage> packages = new PackageList(this).getPackages();
    if (packages.get(0).getClass() == MainReactPackage.class) {
      // hack to get around strange error:
      // "Native module TimePickerAndroid tried to override 
      // com.facebook.react.modules.timepicker.TimePickerDialogModule"
      packages.remove(0);
    }
    packages.add(new RNFirebaseMessagingPackage());
    packages.add(new RNFirebaseNotificationsPackage());
    return packages;
  }

I don't understand why, and it may very well have something to do with my app using ExpoKit, but I had to leave this particular bit of madness _somewhere_ so that it didn't just live in my head.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

josev55 picture josev55  路  3Comments

janmonschke picture janmonschke  路  3Comments

TrakBit picture TrakBit  路  3Comments

despairblue picture despairblue  路  3Comments

jlongster picture jlongster  路  3Comments