Follow the below steps to create an apk using expo cli
Install expo CLI To check if you have expo CLI install run
expo -V
you need the eas build tools
npm install --global expo-cli eas-cli
First requirement for generating the apk file is creating an expo account. Create an account here
Login to expo CLI
Open cmd
Login to expo account using the command :
expo login
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
{
"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.
Build
Open cmd in your app directory.
Run the build command
eas build -p android --profile preview
Download apk
After the build is complete you can go to the builds section in your expo dashboard and download the apk.
https://expo.dev/accounts/username/projects/projectname/builds/0cecd3ee-41aa-4a5a-9cc7-6f7b3ea6fc52
make sure in app.json
{
"expo": {
"name": "your app name",
"description": "your app desc",
....,
"ios": {
"supportsTablet": true
},
"android": {
"package": "com.yourcompany.yourappname"
}
}
}
then run expo build:android or expo ba
after that
run expo build:status
you'll find, something like this, the Apk's is hosted on amazon aws
[exp] Android:
[exp] APK: https://HOST/yourapp.apk
You will need to run expo build:status. When building process is complete you will see link to download apk (Android) or ipa(IOS) file.
to build a apk out of the file first you need to do some changes to your eas.json file.
By default, EAS Build produces Android App Bundle, you can change it by:
- setting
buildTypetoapk - setting
developmentClienttotrue - setting gradleCommand to
:app:assembleRelease,:app:assembleDebugor any othergradle command that produces APK
after changing the config you can run eas build -p android --profile preview to build the application
you can read more about this in docs https://docs.expo.dev/build-reference/apk/
and here's a sample config i used for a basic project to build ( also you can find on docs )
{
"cli": {
"version": ">= 0.52.0"
},
"build": {
"preview": {
"android": {
"buildType": "apk"
}
},
"preview2": {
"android": {
"gradleCommand": ":app:assembleRelease"
}
},
"preview3": {
"developmentClient": true
},
"production": {}
}
}
--
also alternatively another possible way would be to get the bundle ( .aab ) file and convert it to apk using a too like bundletool. and you can find the apk ( universal.apk ) inside app.apks
bundletool build-apks --bundle=bundle.aab --output=app.apks --mode=universal
https://github.com/google/bundletool
By default Expo, CLI builds the app into a .aab file format. this format is better for Google Play Store as it will be optimized for every device CPU architecture which results in a smaller app size.
In case you want to test for your device or emulator, run:
expo build:android -t apk