'React Native: Build apk file using Expo CLI
I'm a new learner on this platform.
I code a simple react native app using expo. But I want to build a .apk file.
I tried this command:
expo build:android
Then I sign up an expo account. After completing the building process it shows the download button.
Just like the following picture: But its not apk file. It is .aab file.
So, I want to build an actual apk file.
How can I do that?
Solution 1:[1]
Update for new users:
Run the following:
› npm install -g eas-cli
› eas build -p android
https://docs.expo.dev/build/setup/
expo build:android will be discontinued on January 4, 2023
Solution 2:[2]
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
Solution 3:[3]
From expo documentation : When building for android you can choose to build APK (expo build:android -t apk) or Android App Bundle (expo build:android -t app-bundle).
Solution 4:[4]
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
buildType
toapk
- setting
developmentClient
totrue
- setting gradleCommand to
:app:assembleRelease
,:app:assembleDebug
or 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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | BYIRINGIRO Emmanuel |
Solution 3 | Sofyane MAKERRI |
Solution 4 |