Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question : Following the guide from reactnative native modules for Android throws error #3075

Closed
gs-akhan opened this issue Sep 27, 2015 · 5 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@gs-akhan
Copy link

Hi devs.
In process of creating Native modules for Android (Following what is mentioned in https://facebook.github.io/react-native/docs/native-modules-android.html#content)

I get this error while app compilation .

..src/main/java/com/azharapp/AnExampleReactPackage.java:15:error: AnExampleReactPackage is not abstract and does not override abstract method createViewManagers(ReactApplicationContext) in ReactPackage

Thanks.

@gs-akhan
Copy link
Author

And also please tell us where to write the Java files for the native modules. Can they be siblings to MainActivity.java.. ?

Thanks

@satya164
Copy link
Contributor

You need to implement the createViewManagers and createJSModules methods. The package file will be something like this,

class AnExampleReactPackage implements ReactPackage {
    @Override
    public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
        return Arrays.<NativeModule>asList(
                new WebSocketModule(reactContext),
                new IntentModule(reactContext)
        );
    }

    @Override
    public List<Class<? extends JavaScriptModule>> createJSModules() {
        return Collections.emptyList();
    }

    @Override
    public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
        return Arrays.asList();
    }
}

I don't think the package for the native modules really matters. As long as you can access the package class in the MainActivity, you should be good to go.

@gs-akhan
Copy link
Author

Worked Perfectly .. Thank you very much !!
Closing.

@gopidon
Copy link

gopidon commented Oct 11, 2015

For those, visiting this link for similar issues, some more info. I realised that your react package should be added in addition to the MainReactPackage. So it goes like this

mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new AwesomeReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();

@raihanabbas232
Copy link

raihanabbas232 commented Sep 12, 2017

well i am getting

method does not override from its superclass

error while implementing ReactPackage interface... ReactPackage does not contain such method I've seen

@facebook facebook locked as resolved and limited conversation to collaborators Jul 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants