DEV Community

Cover image for How To Generate apk Using React Native Expo
Chinmay Mhatre
Chinmay Mhatre

Posted on • Updated on

How To Generate apk Using React Native Expo

Introduction

Hey everyone! Here is a quick article on how to generate an apk for your react native expo app.


Install expo CLI

I assume, if you are reading a blog on exporting the app , you have already installed the expo CLI 👀.

To check if you have expo CLI install run



 expo -V


Enter fullscreen mode Exit fullscreen mode

In the command line, If you get a version number that indicates you have expo install.

image

In case you don't. You can install it using npm.

We also need the eas build tools



npm install --global expo-cli eas-cli


Enter fullscreen mode Exit fullscreen mode

Create expo account and login

First requirement for generating the apk file is creating an expo account.
Create an account here

expologin

After logging in, you will be redirected to your expo dashboard.

image


Login to expo CLI

  • Open cmd
  • Login to expo account using the command : ```

expo login

![login](https://user-images.githubusercontent.com/51131670/126795309-6f36664b-4edd-4bab-9710-d332635f6dea.PNG)
To check which user you are logged in with, use the command
Enter fullscreen mode Exit fullscreen mode

expo whoami

![image](https://user-images.githubusercontent.com/51131670/127814587-67a4f021-fd70-4b9f-943c-b635e67ba5bd.png)

---

## Edit Config
By default the eas build tool will give you a playstore build file.

If you want a .apk file you need to create a `eas.json` file and add a `buildType` as `apk`.


Enter fullscreen mode Exit fullscreen mode

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



You can check out more about the eas build tool [here](https://docs.expo.dev/build/introduction/).

---

## Build
Open cmd in your app directory.

Run the build command 
```sh


eas build -p android --profile preview


Enter fullscreen mode Exit fullscreen mode

Wait for the build to complete...


Download apk

After the build is complete you can go to the builds section in your dashboard and download the apk.

apk


Hope you found this useful. See you in the next one!

Top comments (32)

Collapse
 
aryaweb profile image
Arya Shreyas

Thanks man! Easy and simple.

Collapse
 
amahuika profile image
amahuika

Hey, Great post thanks for sharing!.

Collapse
 
mrjeanmichell profile image
Jean Michell

Loved it! thank you.

Collapse
 
mehdinoori5233 profile image
Info Comment hidden by post author - thread only accessible via permalink
MehdiNoori5233

Hi There.
After I runned this command: "expo build:android" in the VS Code,
I see this error:
"Uploading JavaScript bundles
read ECONNRESET
Error: read ECONNRESET
at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20)
"

Please give me a solution.

Collapse
 
chinmaymhatre profile image
Chinmay Mhatre

Hey,
Expo sdk recently had an update. A new cli has been put in place to build apks. you can take a look at this : expo.dev/eas

Collapse
 
azharuddin1801734 profile image
azharuddin1801734

i am facing this issues or errors during follow these steps for generate apk using expo
can anyone help me for solve these problems during generate apk using expo in react native project

Running 'gradlew :app:assembleRelease' in /home/expo/workingdir/build/android

Downloading services.gradle.org/distributions/...

10%

20%.

30%.

40%.

50%.

60%.

70%.

80%.

90%.

100%

Welcome to Gradle 7.5.1!

Here are the highlights of this release:

  • Support for Java 18

  • Support for building with Groovy 4

  • Much more responsive continuous builds

  • Improved diagnostics for dependency resolution

For more details see docs.gradle.org/7.5.1/release-note...

To honour the JVM settings for this build a single-use Daemon process will be forked. See docs.gradle.org/7.5.1/userguide/gr....

Daemon will be stopped at the end of the build

[stderr]
FAILURE: Build failed with an exception.

[stderr]

  • Where:

[stderr]
Script '/home/expo/workingdir/build/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 250

[stderr]

  • What went wrong:

[stderr]
A problem occurred evaluating script.

[stderr]

[stderr]
Calling [node, /home/expo/workingdir/build/node_modules/@react-native-community/cli/build/bin.js, config] finished with an exception. Error message: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object

[stderr]

[stderr]
The current character read is 'E' with an int value of 69

[stderr]
Unable to determine the current character, it is not a string, number, array, or object

[stderr]
line number 1

[stderr]
index number 0

[stderr]
Error: Package name not found in /home/expo/workingdir/build/android/app/src/main/AndroidManifest.xml at Object.projectConfig (/home/expo/workingdir/build/node_modules/@react-native-community/cli-platform-android/build/config/index.js:74:11) at Object.get project as project at filterConfig (/home/expo/workingdir/build/node_modules/@react-native-community/cli/build/commands/config/config.js:13:20) at Object.func (/home/expo/workingdir/build/node_modules/@react-native-community/cli/build/commands/config/config.js:27:32) at Command.handleAction (/home/expo/workingdir/build/node_modules/@react-native-community/cli/build/index.js:192:23) at Command.listener (/home/expo/workingdir/build/node_modules/@react-native-community/cli/node_modules/commander/index.js:315:8) at Command.emit (node:events:513:28) at Command.parseArgs (/home/expo/workingdir/build/node_modules/@react-native-community/cli/node_modules/commander/index.js:651:12) at Command.parse (/home/expo/workingdir/build/node_modules/@react-native-community/cli/node_modules/commander/index.js:474:21) at setupAndRun (/home/expo/workingdir/build/node_modules/@react-native-community/cli/build/index.js:271:24)info Run CLI with --verbose flag for more details.

[stderr]
^. Output: Error: Package name not found in /home/expo/workingdir/build/android/app/src/main/AndroidManifest.xml at Object.projectConfig (/home/expo/workingdir/build/node_modules/@react-native-community/cli-platform-android/build/config/index.js:74:11) at Object.get project as project at filterConfig (/home/expo/workingdir/build/node_modules/@react-native-community/cli/build/commands/config/config.js:13:20) at Object.func (/home/expo/workingdir/build/node_modules/@react-native-community/cli/build/commands/config/config.js:27:32) at Command.handleAction (/home/expo/workingdir/build/node_modules/@react-native-community/cli/build/index.js:192:23) at Command.listener (/home/expo/workingdir/build/node_modules/@react-native-community/cli/node_modules/commander/index.js:315:8) at Command.emit (node:events:513:28) at Command.parseArgs (/home/expo/workingdir/build/node_modules/@react-native-community/cli/node_modules/commander/index.js:651:12) at Command.parse (/home/expo/workingdir/build/node_modules/@react-native-community/cli/node_modules/commander/index.js:474:21) at setupAndRun (/home/expo/workingdir/build/node_modules/@react-native-community/cli/build/index.js:271:24)info Run CLI with --verbose flag for more details.

[stderr]

  • Try:

[stderr]

Run with --stacktrace option to get the stack trace.

[stderr]

Run with --info or --debug option to get more log output.

[stderr]

Run with --scan to get full insights.

[stderr]

[stderr]
BUILD FAILED in 18s

Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.

please provide me solutions of these errors

Image description

Collapse
 
anujawas profile image
Anuj Awasthi

I am Calling an Inside my expo App which is being successfully implemented, But same is not being called in APK. Can you help me with that?

Collapse
 
dipeshsah profile image
Info Comment hidden by post author - thread only accessible via permalink
Dipesh Kumar Sah

It's not working on EXPO version 45.0.0. you have to give another method to create apk using expo.

Collapse
 
chinmaymhatre profile image
Chinmay Mhatre

Updated the blog for the new method

Collapse
 
ahmadnoor4050 profile image
AhmadNoor4050

Using EXPO 45 butt know 47verion how to create APK.

Collapse
 
chinmaymhatre profile image
Chinmay Mhatre

I believe this methods works with version 47

Collapse
 
ashwith25 profile image
Ashwith Poojary

Very well explained! 🙌

Collapse
 
raushankp75 profile image
Raushan Kumar

After build apk it will not run on Android when i install on Android device and open it will show keeps stopping. Please help me what is the issue and how can i solve this issue anyone can help please... I am frustrating about 2 day's and not able to find the solution..
Image description

Collapse
 
awais882s profile image
Muhammad Awais

Thank You Brother

Collapse
 
rubainriyam profile image
RubainRiyam

Very Usefull

Some comments have been hidden by the post's author - find out more