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
RN0.60.5 react-native run-androidDescribe what you expected to happen:
App to build/run
MainApplication.javapackage 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.
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.
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.
Most helpful comment
Try remove this line:
packages.add(new MainReactPackage());