将本机反应项目捆绑为iOS框架或(.aar)Android库 [英] Bundling react-native project as iOS framework or (.aar) Android library

查看:81
本文介绍了将本机反应项目捆绑为iOS框架或(.aar)Android库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在探索使用react-native创建iOS框架(Android库)的可能性,该框架可以分布式,并且可以通过在构建应用程序时包括在内而与应用程序集成.

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.

例如,维护单个代码库为ios创建一个".framework",为Android创建一个.jar(基本编译的代码而不是React组件代码)作为开发者社区的发行版.

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来安装react依赖项的方法是通过npm install.一个非常基本的解决方案可以是在没有反应本机的情况下运送您的库,然后让SDK用户通过反应推荐的方式安装本机反应.

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

这种方法的问题在于,本机开发人员对npm install并不熟悉,并且他们不太愿意解决与npm install相关的问题.原生开发人员更习惯于为构建其应用程序进行分级和协作,不幸的是,反应是原生已停止支持它.作为SDK开发人员,我们不能强迫我们的SDK用户开始使用npm并遵循反应本机集成准则. 这就是我们为用例解决此问题的方式,

  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:

主机对私有Maven存储库进行本地响应,并要求SDK用户在其项目级别的build.gradle文件中添加以下行,

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.>"
        }
    }
}

在应用的build.gradle文件中添加以下行,

  Add below line in app’s build.gradle file,  

dependencies {

    compile 'com.facebook.react:react-native:0.53.+'

}

您还可以使用此私有Maven存储库来托管SDK的aar文件.

You can also use this private maven repo to host your SDK’s aar file.

有了这一更改,Android开发人员可以很轻松地包含您的SDK并在其应用程序中进行本机响应. 这种方法的问题是,您最终将在自己的私有Maven存储库中维护许多React版本(维护开销).

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:

我们的第一个解决方案是在.framework文件中包含react库并创建一个胖二进制文件.这要求您在框架文件中包含libReact.a和其他与反应有关的.a files并将其链接.

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.

使用此解决方案,您的.framework包括所有依赖项.与SDK集成将非常容易(只需将其拖放到Frameworks文件夹).这种方法的问题在于React本机库的大小正在增长.最新的libReact.a文件大小为105 Mb.这意味着框架文件将会很大,SDK用户将很难将其推送到github.

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.

我们最近转移到了一个解决方案,在私有pod中托管React本机依赖关系,SDK用户可以通过在其Podfile中添加几行来下载react依赖关系.此解决方案就像是对本机推荐的反应方式,我们唯一要避免的是npm install.我们希望为我们的SDK用户提供这两个选项(一个带有npm install,另一个没有它).根据SDK用户的反馈,我们将在以后决定构建过程.

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.

这篇关于将本机反应项目捆绑为iOS框架或(.aar)Android库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆