What a React Native library with native Android code looks like.

June 16, 2019

Package structure (boilerplate) for a react native library containing native Android code.

If you’ve ever wondered what a react-native library with native Android code looks like, you’ve come to the right place. This post highlights the things you need to make one and how the folders generally look like.

Say we’re working on an npm package for react native called “react-native-awesomeness” which contains native Android implementation written in Java. Well, this is how the bare bones structure or boilerplate of that package would look like.


So you'll eventually end up with a structure like this.

Initial Structure

To see what to include in each file, you can take a look at this GitHub repository of a react native package that which provides accurate location updates on Android using its FusedLocation API.


If you have the above structure laid down and contents of files are what they should be. This should be enough to make it work for your users and be installable using
npm install react-native-awesomeness and
react-native link react-native-awesomeness.


Adding the goodies.

Now, at some point you would want users to actually use your package so it’s a pretty good idea to add a README.md file. The contains of this file appear of the package’s npm page and the home page of its GitHub repository. Ideally, this file should contain installation instructions, examples and gif demos (if any).
Here’s a good example of such a README.md file. If you plan to support TypeScript, it’s also a good idea to make a index.d.ts file that will house type definitions for your package.

The final structure of the package would now look like. Final Structure

Well, now you have a decent idea of how a bare bones npm package for an android react-native package would look like. Do not hesitate to add more source code files as your package grows along.
Also, a whole lot of people would thank you if your package has semantic versioning. Do read about it from here.

Cheers for sticking around!