React Native: Android Native Module

2020-07-07 11:32发布

问题:

I implemented native module on React Native / Android Project. In android native project, I used startActivity function to move to the new activity I created manually. I will share some of the codes.

//MainApplication.java

public class MainApplication extends MultiDexApplication {
  ...
  // Needed for `react-native link`
  public List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
      new AnExampleReactPackage(this)
    );
  }
  ...
}

Here, if I use the code new MainReactPackage() then I see the error while running app on my android device.

Native module AccessibilityInfoModule tried to override AccessibilityInfoModule for module name AccessibilityInfo. If this was your intention, set canOverrideExistingModule=true

But I'm not sure how I can set the canOverrideExistingModule. How can I solve this?

Relative Question: React Native: Android activity go back

回答1:

Do you really want to override AccessibilityInfoModule? If yes then simply add this to your NativeModule class

@Override    
public boolean canOverrideExistingModule() {        
  return true;    
} 


回答2:

Check your

MainApplication.java

(under .\android\app\src\main\java\com\projectName) To see if you have the duplicate declarations in method getPackages().

and also check in import.