I am exploring the possibility of using react-native to create a iOS framework (android library), which can be distributed and can be integrated with apps by including while building a app.
For example, maintaining single codebase to create a ".framework" for ios, or .jar for android (basically compiled code instead of react component code) as distribution for developer community.
React native recommended way to install react dependencies is via npm install
. A very basic solution can be to ship your library without react native and then let SDK users install react native via react recommended way.
https://facebook.github.io/react-native/docs/integration-with-existing-apps.html
Problem with this approach is that native developers are not familiar with npm install
and they are not very comfortable in fixing npm install
related issues. Native developers are more used to gradle and cocoapods for building their app and unfortunately react native has stopped supporting it. As an SDK developer, we can’t force our SDK users to start using npm and follow react native integration guidelines.
This is how we solved this problem for our use case,
Android:
Host react native on private maven repo and ask SDK users to add below line in their project-level build.gradle file,
allprojects {
repositories {
jcenter()
maven {
// All of React Native (JS, Android binaries) is installed from private maven repo
url "<Your private maven repo url.>"
}
}
}
Add below line in app’s build.gradle file,
dependencies {
compile 'com.facebook.react:react-native:0.53.+'
}
You can also use this private maven repo to host your SDK’s aar file.
With this change, it’s going to be very easy for Android developers to include your SDK and react native in their app. Problem with this approach is that you will end up maintaining many react versions on your own private maven repo (Maintenance overhead).
iOS:
Our first solution was to include react libraries inside the .framework
file and creating a fat binary file. This requires you to include, libReact.a and other react related .a files
inside your framework file and link them.
With this solution, Your .framework
includes all the dependencies. Integration with SDK will be very easy (Just drag and drop to Frameworks folder). Problem with this approach was that React native library is growing in size. Latest libReact.a file is 105 Mb in size. This means that framework file size will be huge and SDK users will have difficulty in pushing it to github.
We recently moved to a solution where we are hosting React native dependencies in private pod and SDK users can download react dependencies by adding few lines in their Podfile. This solution is like react native recommended way and the only thing we are avoiding is npm install
. We want to give our SDK users both the options (one with npm install and other without it). Based on the feedback from SDK users, we will decide our build process in future.
Please note that there are multiple limitations and maintenance overhead with this solution but it’s solving our use case. It might not work for everyone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With