如何使用 React Native Expo 生成 apk

2025-05-24

如何使用 React Native Expo 生成 apk

介绍

大家好!这是一篇关于如何为你的 React Native Expo 应用生成 APK 的简短文章。


安装 expo CLI

我假设,如果您正在阅读有关导出应用程序的博客,那么您已经安装了 expo CLI 👀。

要检查您是否已安装 expo CLI,请运行

 expo -V
Enter fullscreen mode Exit fullscreen mode

在命令行中,如果您获得一个版本号,则表明您已安装 expo。

图像

如果没有,您可以使用 npm 安装它。

我们还需要 EAS 构建工具

npm install --global expo-cli eas-cli
Enter fullscreen mode Exit fullscreen mode

创建博览会账户并登录

生成 apk 文件的首要条件是创建一个 expo 账户。
点击此处创建账户

解释

登录后,您将被重定向到您的博览会仪表板。

图像


登录 expo CLI

  • 打开cmd
  • 使用以下命令登录 expo 帐户:
expo login
Enter fullscreen mode Exit fullscreen mode

登录
要检查您使用哪个用户登录,请使用命令

expo whoami
Enter fullscreen mode Exit fullscreen mode

图像


编辑配置

默认情况下,eas 构建工具将为您提供一个 playstore 构建文件。

如果您想要一个 .apk 文件,您需要创建一个eas.json文件并添加一个buildTypeas apk

{
  "build": {
    "preview": {
      "android": {
        "buildType": "apk"
      }
    },
    "preview2": {
      "android": {
        "gradleCommand": ":app:assembleRelease"
      }
    },
    "preview3": {
      "developmentClient": true
    },
    "production": {}
  }
}
Enter fullscreen mode Exit fullscreen mode

您可以在此处查看有关 eas 构建工具的更多信息


建造

在您的应用程序目录中打开 cmd。

运行构建命令

eas build -p android --profile preview
Enter fullscreen mode Exit fullscreen mode

等待构建完成...


下载 APK

构建完成后,您可以转到仪表板中的构建部分并下载 apk。

APK


希望本文对你有帮助。下期再见!

文章来源:https://dev.to/chinmaymhatre/how-to-generate-apk-using-react-native-expo-kae
PREV
像专业人士一样使用 Git:我后悔没早点知道的 10 件事 我后悔没早点知道的 10 件事
NEXT
🚀#1 JavaScript 项目系列让您成为专业人士。