Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export React-Native App as a Android Library (.aar)?

Tags:

I am new to React-Native, I have an objective of creating React-Native based components that can be used in other Android native Apps . However, we would to export this react native component as an Android library (.aar) and then distribute to other consumers.

  1. How can I export react-native module as a library.?
  2. Is there something similar to export the components to be used in IOS app development?

I have seen this question has been asked couple of times in SOF, however do not see a clear answer, hence Im posting again.

like image 403
BALA CHANDAR Avatar asked Oct 03 '19 09:10

BALA CHANDAR


People also ask

How do I create a React Native library?

Open the package. json file and under name — change react-native-native-toast-library to react-native-native-toast-library-XXXX, where XXXX is your unique part. If you don't have an npm account create it [here]. Open the terminal in the project directory, and type npm adduser and then your username details.


1 Answers

In the following project, their goal was to add react-native dependencies to a vanilla Android app:

https://github.com/glung/react-native-as-an-android-lib

They note some drawbacks that the user of the Android library will face:

  • React-native requires the application to implement the ReactApplication interface to run. This means that the app needs to add a dependency to 'com.facebook.react:react-native`.

  • Final APK size will be bigger. There is not much we can do about that since about 6M comes from react-native ndk libraries (compiled for arm64-v8a, armeabi, armeabi-v7a x86 , x86_64).

    • 1.5M normal.apk
    • 8.5M react_native.apk
    • 7.9M react_native.apk proguarded
like image 169
Thanh Cao Avatar answered Oct 12 '22 02:10

Thanh Cao