来自世博网站

Expo让web开发者只需用JavaScript编写一次,就能构建出能够在iOS和Android上运行的真正原生应用。

这不是React Native所做的吗?有什么不同?


当你在Expo中编写代码时,你就是在编写React Native代码。世博会已经 两个主要部分:

Expo CLI (expo-cli): a developer tool for creating projects, viewing logs, opening on your device, publishing, etc. Expo client: an app on your phone that lets you open your projects while you're working on them, without needing to go through XCode or Android Studio, and also lets other people view them too! And if you publish it through expo-cli, people can access it at any time through the Expo client on Android or on iOS if signed in to the same account it was published with. Lastly, we also make it possible to build standalone apps so people don't have to use the Expo client to open it, and you can distribute to the app store and play store if you like.

所以Expo是建立在React Native之上的一套工具。这些工具依赖于Expo上的一个关键信念:只要你有一套全面的面向JavaScript的api,就可以构建大多数应用程序,而不需要编写本地代码。

这一点很重要,因为使用React Native,你总是可以下拉到本地代码。这有时是非常有用的,但它是有代价的:如果你想让他们测试你的二进制文件,你需要把你的二进制文件发给他们,世界另一边的人不能在你工作的时候点击一个链接来打开它,你不能像在浏览器中那样一键发布它,让别人访问它。

对于Expo,我们建议尽量避免使用本地代码,如果可以的话。正如我上面提到的,我们认为JavaScript有了一套全面的api,对于大多数应用程序来说,这应该是不必要的。因此,我们的目标是提供这个全面的api集,然后构建所有可以存在于本机运行时共享世界中的强大工具。

但是,如果你必须发现你想要下拉到本地,你可以使用eject并继续使用Expo提供给你的本地api,同时拥有与任何本地项目相同的控制级别。

阅读更多关于弹射的内容

在世博会的官方文件中有解释

Expo和React Native的区别是什么?

Expo is kind of like Rails for React Native. Lots of things are set up for you, so it’s quicker to get started and on the right path. With Expo, you don’t need Xcode or Android Studio. You just write JavaScript using whatever text editor you are comfortable with (Atom, vim, emacs, Sublime, VS Code, whatever you like). You can run XDE (our desktop software) on Mac, Windows, and Linux. Here are some of the things Expo gives you out of the box that work right away: Support for iOS and Android You can use apps written in Expo on both iOS and Android right out of the box. You don’t need to go through a separate build process for each one. Just open any Expo app in the Expo Client app from the App Store on either iOS or Android (or in a simulator or emulator on your computer). Push Notifications Push notifications work right out of the box across both iOS and Android, using a single, unified API. You don’t have to set up APNS and GCM/FCM or configure ZeroPush or anything like that. We think we’ve made this as easy as it can be right now. Facebook Login This can take a long time to get set up properly yourself, but you should be able to get it working in 10 minutes or less on Expo. Instant Updating All Expo apps can be updated in seconds by just clicking Publish in XDE. You don’t have to set anything up; it just works this way. If you aren’t using Expo, you’d either use Microsoft Code Push or roll your own solution for this problem Asset Management Images, videos, fonts, etc. are all distributed dynamically over the Internet with Expo. This means they work with instant updating and can be changed on the fly. The asset management system built-in to Expo takes care of uploading all the assets in your repo to a CDN so they’ll load quickly for anyone. Without Expo, the normal thing to do is to bundle your assets into your app which means you can’t change them. Or you’d have to manage putting your assets on a CDN or similar yourself. Easier Updating To New React Native Releases We do new releases of Expo every few weeks. You can stay on an old version of React Native if you like, or upgrade to a new one, without worrying about rebuilding your app binary. You can worry about upgrading the JavaScript on your own time. But no native modules… The most limiting thing about Expo is that you can’t add in your own native modules without detaching and using ExpoKit.

Brent Vatne的回答很好,但我想补充一些细节。


Expo扩展了React Native的API表面

React Native不能提供所有开箱即用的JavaScript api,只能提供大多数原始功能。React Native开发者应该使用Android Studio或Xcode来链接其他原生库。

Expo旨在增强React Native,并为您最常见的需求提供所需的所有JavaScript api。它基本上是一组定义良好的高质量本机库,已经打包在单个库中:ExpoKit。有时候这些库实际上已经存在于React Native世界中,并集成到ExpoKit中。

同样重要的是要注意,Expo团队不能将所有的库都包含到ExpoKit中(这可能会造成一些挫折),因为Hello, World!应用程序的大小会增加,因为它会发布很多在大多数应用程序中不会使用的API。

Expo提供无线JavaScript更新

与其他系统(CodePush等)一样,Expo提供了一个通过无线更新应用程序的系统。这意味着你在CDN上上传你的JavaScript包,移动应用程序将在下次启动时自动下载并使用新的JavaScript代码(不需要从商店请求发布/评论)。

Expo提供了一个CLI工具来上传/管理CDN上的JavaScript包。对于开发,你也可以选择成为CDN并在本地主机上托管JavaScript包。Expo XDE只是CLI上的一个可视化包装器。

Expo提供了一个通用客户端

Expo客户端是一个通用客户端,允许加载任何与Expo兼容的应用程序。所有的Expo应用程序共享完全相同的本机运行时(React native + ExpoKit)。唯一的区别是我们提供给它们的JavaScript代码。你发布到应用商店的Expo应用有你的JavaScript包URL硬编码在里面。Expo客户端以特定的方式构建,因此您可以通过扫描二维码或提供URL来选择加载JS的URL。

注意,这个客户端也可以从localhost加载JavaScript包,让你的开发体验更简单:不需要任何Xcode或Android Studio,它可以更快地获得你的第一个Hello, World!手机上运行的应用程序(从小时到分钟)。你可以在没有Mac的情况下在iPhone上开发游戏,设置过程只需要2分钟。

实际上,由于Expo SDK可以升级,所以Expo客户端包含了一个兼容层,以便能够运行前五个SDK版本。

Expo提供构建服务

由于所有的Expo应用程序共享相同的本机代码,Expo能够轻松地为您构建这些应用程序。他们创建了一个云构建服务。

由Expo构建的两个应用程序的主要区别在于硬编码的URL,应用程序应该将JavaScript包下载到该URL中运行。

Expo还为你做了一些其他的事情,比如提供一种声明式的方式来设置应用程序图标、方向、权限、API键,帮助你设置推送通知、配置文件……许多设置必须在构建时在应用程序中硬编码,并且不能在空中更改。

Expo之于React Native,就像PhoneGap之于Cordova

React Native类似于Cordova。它不是相同的视图技术(原生视图和webview),但都允许你通过JavaScript控制原生特性,并且都提供插件系统,以便开发人员可以轻松添加新的JavaScript和原生绑定。

PhoneGap类似于Expo。它们都试图用一组预定义的附加本地插件来丰富它们所基于的底层平台的原始API。PhoneGap还提供构建服务,并有一个通用的客户端,只要你使用批准的插件就可以工作。

结论

如您所见,Expo是一套工具。最后,它允许轻松地开发,共享和发布到商店你的移动项目。它与PhoneGap的体验非常相似(但要好得多,也不那么令人困惑)。

对于React Native的新项目,我肯定会推荐Expo,除了以下两种情况:

你已经知道你需要的API在世博会中是不可用的,而且不会很快 你非常关心应用的大小(Hello, World!)由于ExpoKit的大小超过25 MB,但之后它不会增加太多,因为它只是JavaScript)

世博员工的回答和文件摘要:

React Native init:

优势

您可以添加用Java或Objective-C(可能是唯一但也是最强的一种)编写的本机模块。

缺点

Needs Android Studio and Xcode to run the projects You can't develop for iOS without having a Mac Device has to be connected via USB to use it for testing Fonts need to be imported manually in Xcode If you want to share the app you need to send the whole .apk / .ipa file Does not provide JavaScript APIs out of the box, e.g., Push-Notifications, Asset Manager, they need to be manually installed and linked with npm for example Setting up a working project properly (including device configuration) is rather complicated and can take time

Expo

优势

Setting up a project is easy and can be done in minutes You (and other people) can open the project while you're working on it Sharing the app is easy (via a QR code or link), you don't have to send the whole .apk or .ipa file No build necessary to run the app Integrates some basic libraries in a standard project (Push Notifications, Asset Manager, etc.) You can eject it to ExpoKit and integrate native code continuing using some of the Expo features, but not all of them Expo can build .apk and .ipa files (distribution to stores possible with Expo)

缺点

You can't add native modules (probably a game changer for some) You can't use libraries that use native code in Objective-C/Java The standard Hello World app is about 25MB big (because of the integrated libraries) If you want to use: FaceDetector, ARKit, or Payments you need to eject it to ExpoKit Ejecting it to ExpoKit has a trade-off of features of Expo, e.g. you cannot share via a QR code When ejecting to ExpoKit you are limited to the react-native version that is supported by ExpoKit then Debugging in ExpoKit (with native modules) is a lot more complicated, since it mixes two languages and different libraries (no official Expo support any more)

来源:

将Expo应用分离到ExpoKit:概念 react-native-init和create-react-native-app #516的区别 弹出到ExpoKit

世博会CLI

优点:

无需安装Android Studio或Xcode即可开始构建。 不需要很多配置。 使用条形码扫描在Android和iPhone上轻松查看移动UI。通过在线iPhone和Android模拟器也更容易查看。 更快的设置和开发。

缺点:

无法添加本机依赖项。 创建。apk和。ipa文件是困难的。 apk/ipa的大小很大。

React Native CLI

优点:

轻松添加本机依赖项。 创建。apk和。ipa文件比使用Expo要容易得多

注意:React Native CLI是用来直接使用React Native框架的框架。

缺点:

需要高水平的配置。 基本了解Android和iOS文件夹结构。

如你所见,这两种方法各有利弊;您应该始终根据项目的需要来决定使用哪一种。

这里我要说明的是,Expo使用的是React的旧版本16.5,这将禁止你使用新的hooks功能。

如果您决定使用Expo,请注意您的版本控制。例如,如果遇到奇怪的错误,就需要在16.5版本中使用旧版本的反应导航。

关于Expo和React Native CLI的优点和缺点的答案是完整的。我还想谈谈我的个人经历。

在项目中,默认情况下,Expo包含许多模块,这使得使用它更容易。但它在制作阶段存在一个大问题,因为Android和iOS版本的尺寸太大了。例如,如果你有一个带有“Hello, World!”’,APK文件大小约为19 MB。在React Native CLI中使用相同的项目将导致应用程序大小为6 MB。

所以就我个人而言,如果你想开发一款商业应用,我不建议你使用Expo。

我在世博工作了一年多。 如果应用的大小对你来说不重要,使用Expo,因为它比React-native更容易实现Map和Push,但在项目结束时,如果你想在谷歌Play或其他商店发布应用,你会遇到一个挑战,删除APK中的一些权限。

在React Native中,你可以改变一切,但对于导入一些库,如推送通知或地图,它也需要一些挑战,因为你必须手动将这些库添加到Android和iOS项目中。

Expo是React Native CLI的包装,它在底层为开发人员提供方便。Expo解决的最常见的问题是,开发人员不必担心React Native CLI中经常出现的库链接问题。Expo现在提供了大量的库,这些库对健壮的开发非常有帮助。Expo的好处之一是,你可以在没有Mac的情况下通过Expo手机应用开发Android和iOS应用。

虽然它有很多好处,但使用Expo也有一些缺点:

应用程序的大小迅速增加。一个简单的Hello, World!app大小超过30mb 有时候,当你需要在你的应用程序中实现一些本地功能时,你将需要从Expo中弹出并返回React native CLI。而且您永远无法将其恢复到Expo CLI。

世博员工的回答和文件摘要:

React Native init: 优势

您可以添加用Java或Objective-C(可能是唯一但也是最强的一种)编写的本机模块。

Disadvantages Needs Android Studio and Xcode to run the projects You can't develop for iOS without having a Mac Device has to be connected via USB to use it for testing Fonts need to be imported manually in Xcode If you want to share the app you need to send the whole .apk / .ipa file Does not provide JavaScript APIs out of the box, e.g., Push-Notifications, Asset Manager, they need to be manually installed and linked with npm for example Setting up a working project properly (including device configuration) is rather complicated and can take time

世博会 优势

Setting up a project is easy and can be done in minutes You (and other people) can open the project while you're working on it Sharing the app is easy (via a QR code or link), you don't have to send the whole .apk or .ipa file No build necessary to run the app Integrates some basic libraries in a standard project (Push Notifications, Asset Manager, etc.) You can eject it to ExpoKit and integrate native code continuing using some of the Expo features, but not all of them Expo can build .apk and .ipa files (distribution to stores possible with Expo)

Disadvantages You can't add native modules (probably a game changer for some) You can't use libraries that use native code in Objective-C/Java The standard Hello World app is about 25MB big (because of the integrated libraries) If you want to use: FaceDetector, ARKit, or Payments you need to eject it to ExpoKit Ejecting it to ExpoKit has a trade-off of features of Expo, e.g. you cannot share via a QR code When ejecting to ExpoKit you are limited to the react-native version that is supported by ExpoKit then Debugging in ExpoKit (with native modules) is a lot more complicated, since it mixes two languages and different libraries (no official Expo support any more)

Expo and React Native are two popular tools for building mobile apps, but they have some differences. Expo is a free and open-source platform that allows developers to quickly build apps with JavaScript and React Native. It provides a set of tools, libraries, and services that make it easier to get started with building a mobile app. React Native, on the other hand, is a framework for building mobile apps using React. React Native provides a more direct way to access native APIs and components, and allows for more customization and control over the app development process. In summary, Expo provides a faster and easier way to get started with building a mobile app, while React Native provides more control and customization.

Another difference between Expo and React Native is the deployment process. With Expo, you can publish your app directly to the app stores with just a few clicks. You can also take advantage of other services that Expo provides, such as push notifications and authentication. On the other hand, when building a React Native app, you'll need to use tools like Xcode or Android Studio to compile and package the app for deployment. Additionally, you'll have to handle the distribution process yourself, which can be time-consuming and complex.

在性能方面,React Native通常比Expo有更好的性能,因为它可以直接访问本地api和组件,而Expo依赖于它的SDK。然而,在许多情况下,性能差异可能并不显著。

总之,Expo和React Native都有各自的优点和缺点,它们之间的选择取决于项目的具体需求和目标。如果你刚刚开始移动应用程序开发,想要一个快速简单的方法开始,Expo是一个很好的选择。然而,如果你想要更多的控制和定制,React Native可能是更好的选择。