The above solutions are all correct, but let me explain a little bit,some of above solutions suggest to override the following method.
@Override
public boolean canOverrideExistingModule() {
return true;
}
But question is where to override? first of all, you can't override inside MainActivity.java or MainApplication.java file.
You should override it in the class inside some node_modules project folder and that class will be extending from ReactContextBaseJavaModule class.
In my case, it was not getting repeated in imports/adding duplicate packages but it was mainly because of auto linking at the and that was making it to repeat.
I am using react-native-contacts npm package to interact so what I did is that went inside
node_modules\react-native-contacts\android\src\main\java\comrt2zz\reactnativecontacts\
ContactsManager.java
and this ContactsManager was extending from the ReactContextBaseJavaModule and I override there and got the problem resolved.
So as general there could be a lot of classes that will be extending from ReactContextBaseJavaModule under different projects inside node_modules, but you need to go for specific a project that will be creating duplication problem and there you should override it.