常见问题
有关 Expo 及相关服务的常见问题和限制列表。
本页面列出了一些关于 Expo 及相关服务的常见问题及答案。如果你有这里未解答的问题,请参见 Forums 获取更多常见问题。
🌐 This page lists some of the common questions and answers about Expo and related services. If you have a question that is not answered here, see Forums for more common questions.
Expo 是用来做什么的?
🌐 What is Expo used for?
Expo 是一个用于在 Android、iOS 和网页上原生运行应用的开源框架。Expo 将移动端和网页的最佳特性融合在一起,并提供了构建和扩展应用所需的许多重要功能,例如实时更新、即时分享应用以及网页支持。expo npm 包为 React Native 应用提供了一套强大的功能。expo 包几乎可以安装在任何 React Native 项目中。欲了解更多信息,请参阅 Expo 提供的内容。
🌐 Expo is an open-source framework for apps that run natively on Android, iOS, and the web. Expo brings together the best of mobile and the web and enables many important features for building and scaling an app such as live updates, instantly sharing your app, and web support. The expo npm package enables a suite of incredible features for React Native apps. The expo package can be installed in nearly any React Native project. See what Expo offers for more information.
公司使用 Expo 吗?
🌐 Do companies use Expo?
是的,Expo 被全球顶层公司使用,为数亿终端用户提供服务。请查看我们的展示。
🌐 Yes, Expo is used by top companies worldwide, serving hundreds of millions of end users. See our showcase.
为什么 Expo 有自己的 SDK?
🌐 Why does Expo have its own SDK?
当 Expo 刚创建时,React Native 还未公开发布。这意味着当时没有第三方包。为了让 React Native 的开发者体验更加合理,我们创建了几个实现常用功能的库。这些库中的许多后来被分叉并修改以满足不同的需求。我们欢迎用户根据需要自由组合使用任何自定义的原生代码,以打造出色的应用。
🌐 When Expo was first created, React Native had yet to be publicly released. This means there were no third-party packages. To make React Native's developer experience reasonable, we created several libraries to achieve common functionalities. Many of these libraries have since been forked and modified to meet various needs. We welcome users to mix and match whichever custom native code they need to make their app great.
Expo SDK 经过充分测试,使用 TypeScript 编写,提供文档,并支持 Android、iOS 和 Web。Expo SDK 中的每个模块协同工作,以确保版本始终匹配。这带来了良好的升级体验。
🌐 The Expo SDK is well-tested, written in TypeScript, documented, and built for Android, iOS, and the web. Every module in the Expo SDK works together to ensure versioning always matches. This creates a nice upgrading experience.
Expo SDK 也使用 Expo Modules API 编写,以便更容易进行贡献、维护和理解。
🌐 The Expo SDK is also written with the Expo Modules API to make contributing, maintaining, and understanding easier.
Expo 和 React Native 有什么区别?
🌐 What is the difference between Expo and React Native?
expo 包提供了一系列功能,使开发和扩展复杂的 React Native 应用变得更容易。你几乎可以在任何 React Native 应用中安装 expo。使用 Expo Application Services (EAS) 或 React Native 并不需要 expo 包,但强烈推荐安装。更多信息请参见 Expo 提供的内容。
🌐 The expo package provides a suite of features that make it easier to develop, and scale complex React Native applications. You can install expo in nearly any React Native app. The expo package is not required to use Expo Application Services (EAS) or React Native, however, it is highly recommended. See what Expo offers for more information.
我需要从 React Native 切换到使用 Expo 吗?
🌐 Do I need to switch from React Native to use Expo?
不,expo npm 包和 CLI 可以用于任何 React Native 应用。Expo 应用服务 (EAS) 也支持所有 React Native 应用,提供对构建、更新、应用商店提交等的全方位支持。
🌐 No, the expo npm package and CLI work with any React Native app. Expo Application Services (EAS) also works with all React Native apps with first-class support for builds, updates, app store submissions, and more.
Expo 花费多少钱?
🌐 How much does Expo cost?
Expo 平台是免费且开源的。这包括构成Expo SDK的库以及用于开发的Expo CLI。最快速入门的方式 Expo Go 应用,也可以在应用商店免费下载。
🌐 The Expo platform is free and open source. This includes the libraries that make up the Expo SDK and the Expo CLI used for development. The Expo Go app, the easiest way to get started, is also free from the app stores.
Expo 应用服务(EAS) 是由 Expo 团队提供的 React Native 应用可选云服务套件。EAS 可以更轻松地构建应用、提交到应用商店、保持应用更新、发送推送通知等等。如果 免费计划 的配额足够你的应用使用,你可以免费使用 EAS。更多信息请参见 价格页面。
如何将自定义原生代码添加到我的 Expo 项目?
🌐 How do I add custom native code to my Expo project?
Expo 支持添加自定义原生代码并自定义这些原生代码(Android/Xcode 项目)。要使用任何自定义原生代码,你可以创建一个开发构建并使用配置插件。我们确实建议尽可能使用Expo SDK中的模块,以便于升级并改善开发者体验。
🌐 Expo supports adding custom native code and customizing that native code (Android/Xcode projects). To use any custom native code, you can create a development build and config plugins. We do recommend using the modules in the Expo SDK when possible for easier upgrades and improved developer experience.
我可以在使用 React Native CLI 创建的应用中使用 Expo 吗?
🌐 Can I use Expo in the app that is created with React Native CLI?
是的!所有 Expo 工具和服务在任何 React Native 应用中都运行良好。例如,你可以使用 Expo SDK、expo-dev-client 以及 EAS Build、Submit 和 Update 的任何部分——它们运行得非常顺利!了解更多关于 在你的项目中安装 expo、采用预构建 以及 设置 EAS Build 的信息。
🌐 Yes! All Expo tools and services work great in any React Native app. For example, you can use any part of the Expo SDK, expo-dev-client and EAS Build, Submit, and Update — they work great! Learn more about installing expo in your project, adopting prebuild, and setting up EAS Build.
我如何分享我的 Expo 项目?我可以提交到应用商店吗?
🌐 How do I share my Expo project? Can I submit it to the app stores?
分享你的项目的最快方式是使用 EAS Update 发布,并在 开发版本 中启动。这会为你的应用生成一个 URL;你可以将这个 URL 分享给任何拥有 Android 或 iOS 开发版本 的人。这个 URL 也可以在 Android 的 Expo Go 中打开。
🌐 The fastest way to share your project is to publish with EAS Update and launch in a development build. This gives your app a URL; you can share this URL with anybody who has the development build for Android or iOS. URLs can also be opened in Expo Go for Android.
准备好后,你可以创建生产版本(.aab 和 .ipa)并提交到应用商店。你可以使用 EAS Build 通过一条命令构建应用,并使用 EAS Submit 提交到商店。
🌐 When ready, you can create a production build (.aab and .ipa) to submit to the app stores. You can build your app in a single command with EAS Build and submit it to the stores with EAS Submit.
你也可以使用内部分发在 Android 上通过 APK 分享你的应用,在 iOS 上通过临时或企业配置文件分享。
🌐 You can also use internal distribution to share your app with an APK on Android and ad-hoc or enterprise provisioning on iOS.
我可以在 Windows 计算机上开发 iOS 应用吗?
🌐 Can I develop iOS apps on a Windows computer?
传统上,你需要 macOS 才能开发 iOS 应用,但你可以使用 EAS Build 在云端构建你的应用。你还可以使用 EAS Submit 将应用提交到应用商店。测试可以在实体 iOS 设备上使用 Expo Go 或 开发构建 进行。
🌐 Traditionally you needed a macOS to develop iOS apps, however, you can use EAS Build to build your app in the cloud. You can also use EAS Submit to submit your app to the stores. Testing can be done on a physical iOS device using Expo Go or a development build.
Expo SDK 支持哪些版本的 Android 和 iOS?
🌐 What versions of Android and iOS are supported by the Expo SDK?
目前,Expo SDK 支持 Android 7+ 和 iOS 15.1+。更多信息,请参见对 Android 和 iOS 版本的支持。
🌐 Currently, Expo SDK supports Android 7+ and iOS 15.1+. For more information, see Support for Android and iOS versions.
一个“hello world” Expo 应用的最小尺寸是多少?
🌐 What is the minimal size of a "hello world" expo app?
使用纯 Expo 创建的最基本生产应用小于 3 MB。对于 iOS,Expo 采用了较新的最低 iOS 版本,这使应用商店优化成为可能。
🌐 A bare minimum production app created using pure Expo is less than 3 MB. For iOS, Expo targets a newer minimum iOS version which enables app store optimizations.
如果你的应用中包含 expo 包,它只会在应用商店的最终应用大小中增加 1 MB。expo 包的大小成本很小(例如,在 Android 上是 150 KiB)。其余的大小来自语言运行时(例如 Android 上的 Kotlin)。
🌐 If the expo package is included in your app, it only adds 1 MB one time to the final size of apps on app stores. The expo package has a marginal size cost (for example, 150 Kib on Android). The rest of the size comes from the language runtime (such as Kotlin on Android).
我可以将 Expo 与我的原生库一起使用吗?
🌐 Can I use Expo with my native library?
你可以通过使用 Swift 和 Kotlin 创建自定义原生模块来在 Expo 中使用原生 Android 和 iOS 库。许多流行的库已经有了自定义原生模块。查看我们的React Native 目录以找到适合你使用场景的流行库。
🌐 You can use native Android and iOS libraries with Expo by creating a custom native module with Swift and Kotlin. Many popular libraries already have custom native modules. Check out our React Native directory to find popular libraries for your use case.
我可以将 Expo 与此网络库一起使用吗?
🌐 Can I use Expo with this web library?
许多流行的Webpack如 three.js 都可以与 Expo 和 React Native 一起使用。更多信息请参见 Expo 示例。
🌐 Many popular web packages such as three.js work with Expo and React Native. See Expo examples for more information.
Expo 与 Web 开发的 React 类似吗?
🌐 Is Expo similar to React for web development?
Expo 是一个用于在 Android、iOS 和网页上原生运行应用的开源框架。React Native 类似于网页开发中的 react-dom,它可以让你在特定平台上运行 React,但它有一些关键的不同点:
🌐 Expo is an open-source framework for apps that run natively on Android, iOS, and the web. React Native is similar to react-dom from web development, enabling you to run React on a particular platform, however, it has a few key differences:
- React Native 不支持 HTML 或 CSS。
- React Native 不使用 DOM,而是使用原生组件。例如,使用
<View />而不是<div />。原生组件比 DOM 性能更好,并且提供更出色的用户体验。 - 与可以访问浏览器 API 的 React.js 不同,React Native 使用自定义的原生 API。例如,不是使用
navigator.geolocation,而是使用expo-location来获取用户的位置。自定义原生 API 类似于浏览器 API,但你可以完全控制它们。这意味着你可以在浏览器提供这些功能之前就访问到新的特性。
就像 React.js 框架帮助用户轻松创建更大的网站一样,Expo 也帮助用户轻松创建更大的应用。Expo 提供了一套经过充分测试的 React Native 模块,可在 Android、iOS 和网页上运行。Expo 还提供了一套工具,用于构建、部署和更新你的应用。
🌐 In the same way React.js frameworks help users create larger websites with ease, Expo helps users create larger apps with ease. Expo provides a suite of well-tested React Native modules that run on Android, iOS, and the web. Expo also provides a suite of tools for building, deploying, and updating your app.
关于解释代码的商店政策是什么?
🌐 What are the store policies regarding interpreted code?
React Native 使用 JavaScript 解释器(JSC、V8 或 Hermes)来运行你的应用代码。请直接参考 Google Play 政策中心 和 Apple 开发者计划许可协议 以获取最新的政策信息。
🌐 React Native uses a JavaScript interpreter (JSC, V8, or Hermes) to run your application code. Refer to the Google Play Policy Center and Apple Developer Program License Agreement directly for the most up-to-date policy information.
以下是截至2024年4月25日的相关政策摘录。
🌐 The following are excerpts of related policies, as of April 25, 2024.
谷歌应用商店
🌐 Google Play Store
...an app may not download executable code (such as dex, JAR, .so files) from a source other than Google Play. This restriction does not apply to code that runs in a virtual machine or an interpreter where either provides indirect access to Android APIs (such as JavaScript in a webview or browser). Apps or third-party code, like SDKs, with interpreted languages (JavaScript, Python, Lua, etc.) loaded at run time (for example, not packaged with the app) must not allow potential violations of Google Play policies.
来源:Google Play 政策中心。
🌐 Source: Google Play Policy Center.
苹果应用商店
🌐 Apple App Store
...Interpreted code may be downloaded to an Application but only so long as such code: (a) does not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store, (b) does not create a store or storefront for other code or applications, and (c) does not bypass signing, sandbox, or other security features of the OS.
🌐 Source: 3.3.1 APIs and Functionality - B. Executable Code.
我应该使用 Expo CLI 还是 React Native Community CLI?
🌐 Should I use Expo CLI or React Native Community CLI?
Expo CLI 提供与 React Native Community CLI(也称为 “React Native CLI”)相同的核心功能,同时增加了额外的功能,如自动 TypeScript 设置、网页支持、自动安装兼容库、改进的原生构建命令、隧道功能、预构建 及 更多。
🌐 Expo CLI offers the same core functionality as React Native Community CLI (also known as "React Native CLI") with additional features such as automatic TypeScript setup, web support, auto installing compatible libraries, improved native build commands, tunneling, Prebuild, and more.
它可以与 React Native Community 同时使用。无论你使用哪种 CLI,都可以在你的项目中使用 Expo SDK 和 Expo 应用服务 的任何部分。欲了解更多信息,请参见:
🌐 It can be used simultaneously with React Native Community. Regardless of which CLI you use, you can use any part of the Expo SDK and Expo Application Services with your project. For more information, see:
- 了解如何将现有的 React Native 项目迁移以使用 Expo CLI。
- 了解使用框架构建 React Native 应用的好处 使用框架构建 React Native 应用。
- 了解迁移到 Expo CLI 的好处,例如提升应用性能、加快发布速度以及促进团队更紧密的协作,请参阅这篇博客文章。
注意: EAS Build 与现有的 React Native 项目兼容(即原生目录已经被纳入版本控制的项目)。当这些目录存在时,EAS Build 不会执行预构建步骤,因为这可能会覆盖你对原生项目文件所做的任何手动自定义。你需要使用 Android Studio 或 Xcode 等原生工具自行配置原生目录。
Expo Go 是开源的吗?
🌐 Is Expo Go open source?
是的,Expo Go 的源代码可以在 expo/expo GitHub 仓库 的 apps/expo-go 目录中找到。Expo Go 应用也是使用 Expo 和 React Native 构建的。
🌐 Yes, the source for Expo Go can be found in the expo/expo GitHub repository in the apps/expo-go directory. The Expo Go app is also built with Expo and React Native.
Expo Go 可以做什么或不能做什么?
🌐 What can I do or cannot do with Expo Go?
Expo Go 是一个供学生和学习者快速测试 Expo 并了解基础知识的实验平台。它允许你使用 Expo SDK 中包含的库,以及不需要自定义原生代码的库。
Expo Go 不能使用需要自定义原生代码的第三方库,并且你无法在 Expo Go 中直接编辑原生代码。它功能有限,对于构建生产级项目并不实用。
🌐 Expo Go cannot use third-party libraries that require custom native code and you cannot edit native code directly in Expo Go. It's limited and not useful for building production-grade projects.
我们强烈建议在任何实际项目中使用开发版本。这就像为你的应用需求专门定制一个 Expo Go 版本。
弹出功能是否已弃用?
🌐 Is ejecting deprecated?
是的,“eject”是一个已弃用的术语,现在已经不再必要。当 Expo 刚发布时,应用的本地二进制文件较大,并且如果不“eject”,无法支持自定义的本地代码。2020 年 12 月,随着 EAS Build 的发布,这一情况发生了变化,它支持任何 React Native 应用。在 SDK 41(2021 年 4 月)中,‘ejecting’ 的概念被 npx expo prebuild 命令取代,该命令会根据项目中的库和应用配置(app.json)持续生成本地项目。expo eject 命令在 SDK 46(2022 年 8 月)被完全弃用。
🌐 Yes, eject is a deprecated term and is no longer necessary. When Expo was first released, apps had larger native binary sizes and didn't support custom native code without "ejecting". This changed in December 2020 with the release of EAS Build which supports any React Native app. The concept of "ejecting" was replaced by the npx expo prebuild command in SDK 41 (April 2021), which continuously generates native projects based on the libraries in your project and the app config (app.json). The expo eject command was fully deprecated in SDK 46 (August 2022).
与之前的弹出工作流不同,开发者可以通过创建一个 配置插件 来配置其库以与 Expo Prebuild 一起使用。这意味着你可以在 Expo Prebuild 中使用任何库。你还可以通过创建一个 开发构建 在 Expo Prebuild 中使用任何自定义原生代码。更多信息请参阅 Expo Prebuild 文档。
🌐 Unlike the previous eject workflow, authors can configure their libraries to work with Expo Prebuild by creating a config plugin. This means you can use any library with Expo Prebuild. You can also use any custom native code with Expo Prebuild by creating a development build. Learn more in the Expo Prebuild documentation.