Reputation: 1417
Is it possible to build the APK of an expo app locally?
The doc says:
If you haven’t used exp before, the first thing you’ll need to do is login with your Expo account using
exp login
.
I tried exp start
, exp build:android
but the commands require a login.
I don't want to build the APK using expo server. Is there a way to run this build locally? So no login and push of source code required?
If not, can I view the whole source code of the generated APK?
Upvotes: 34
Views: 73759
Reputation: 1140
Run gradlew commands inside the android folder.
./gradlew assembleRelease for apk
./gradlew bundleRelease for aab
APK will be located in android/app/build/outputs/apk/release/
AAB will be located in android/app/build/outputs/bundle/release/
Upvotes: 3
Reputation: 555
Run npx expo run:android
.
This will create an android
folder. Open it in Android Studio.
Click on ≡ > Build > Select Build variant. Change active build variant to release
.
Then again go to Build > Build app bundle/apk > APK.
Once Gradle finishes (it takes a while), locate the apk in android\app\build\outputs\apk\release
.
Upvotes: 0
Reputation: 766
Just local and good, as copied from my other post: https://stackoverflow.com/a/76987065
First you need to generate the native app files by executing expo prebuild:
npx expo prebuild
To directly run the build have a device connected or an emulator running:
npx react-native run-android --mode="release"
Build with:
npx react-native build-android --mode=release
For signing the apk for release, follow the instructions on react natives website: https://reactnative.dev/docs/signed-apk-android
Upvotes: 4
Reputation: 8698
The new way of building locally as described in the documentation is:
eas build --platform android --local
Note: Actually there is a limitation / workaround for Windows (from doc):
On Windows, you can use WSL for local EAS Builds. However, we do not officially test against this platform and do not support Windows for local builds (macOS and Linux are supported)
Upvotes: 12
Reputation: 10416
New to the party, so guessing this wasn't available at the time of the post - Instructions for building expo apps locally: Building Standalone Apps on Your CI
Update Jan, 2023:
You may want to check out the updated version:
This doc was archived in August 2022 and will not receive any further updates. SDK 46 is the last SDK supported by Classic Builds and the Classic Build service will stop running for all SDK versions after January 4, 2023. Check out Running builds on your own infrastructure and Triggering builds from CI.
Upvotes: 16
Reputation: 1679
Motivation: build local, test performance of release build on a real device.
Environment: Expo SDK 46 managed project, on AlmaLinux 8.6 (ymmv)
Caution:
I keep a copy of my entire project dir in case things get messed up:
cd <project *parent* dir>
\cp -far <project dir name> <project dir name>.bak
and update that when appropriate with
cd <project dir> # if not there
rsync -atvi --delete . ../<project dir name>.bak/
Steps to create android project dirs/files and a debug build apk :
cd <project dir>
npx expo run:android # not the same as "npm run android"
see ref in official expo docs here
release build:
cd <projectDir>/android/app
keytool -genkey -v -keystore <projectName>.keystore -alias <<projectName>> -keyalg RSA -keysize 2048 -validity 10000
ammend android/app/build.gradle
file - see details here but do not use the build instructions (atow). Then ...
cd ../../ # to project dir
npx expo run:android --no-install --no-bundler --variant release
(although tbh I'm guessing for now that --no-bundler
is to do with the Metro server)
You should find a release apk in
<project dir>/android/app/build/outputs/apk/release
Note this includes full expo and the build can take quite a while. It took more than 12 mins on the following:
Operating System: AlmaLinux 8.6
KDE Plasma Version: 5.23.3
KDE Frameworks Version: 5.88.0
Qt Version: 5.15.2
Kernel Version: 4.18.0-372.32.1.el8_6.x86_64 (64-bit)
Graphics Platform: X11
Processors: 12 × Intel® Xeon® CPU E5-2620 v3 @ 2.40GHz
Memory: 31.1 GiB of RAM
Graphics Processor: AMD CEDAR
You can reduce build time and the final apk size by going for an expo development build or moving your code to a porn project (plain old react-native) :-)
Upvotes: 2
Reputation: 516
If you want to build the app locally without using the turtle CLI of expo, you can build it just how you would build a normal react native app
But beware that you will have to touch some native android code (gradle only)
But only one or two files....
Steps:
keytool
build.gradle
filecd android && ./gradlew assembleRelease
to build the apkCheck out this post to follow these steps in detail
Upvotes: 4
Reputation: 79
I've straggled with similar issue, I managed to solve it following several steps found on the web, and tweaking a bit: https://forums.expo.io/t/expokit-full-local-build-without-publish-android/31400/2
Run the https server your machine, note that the server must have a certificate since it is a HTTPS server (I used port 4443), but it does not need to be trusted by your machine - it works anyway
(I found it easy to use: https://gist.github.com/dergachev/7028596 - Python 2.7,
https://gist.github.com/dergachev/7028596#gistcomment-1989299 - Python 3.X)
Go to your Expo project folder, make sure there is no dist
folder in it; alternatively you can provide dist path with the --output-dir
flag
(the react-native bundle and assets will be generated to it).
Open command line and run:
expo export -t bare --dev --public-url https://localhost:4443/
, once done you will have the android bundle and assets in the output-dir
(default - dist
)
Copy the android bundle from dist/bundles/android-<bunch of numbers (MD5)>.js
to <YourExpoProjectFolder>/android/app/src/main/assets/index.android.bundle
and to <YourExpoProjectFolder>/android/app/build/generated/assets/react/release/index.android.bundle
(note: the name of the bundle must be index.android.bundle)
In /dist/bundles/assets you'll have your assets files, but they would be named as their MD5 value, copy each of them to <YourExpoProjectFolder>/android/app/src/main/assets/
, but add the asset_
prefix and .<ext>
for each.
e.g. for a PNG image file with MD5 value of de57a0c7a3a23aabcaceaf1185b1e79e:
copy <YourExpoProjectFolder>/dist/bundles/assets/de57a0c7a3a23aabcaceaf1185b1e79e <YourExpoProjectFolder>/android/app/src/main/assets/asset_de57a0c7a3a23aabcaceaf1185b1e79e.png
cd android
gradlew.bat assemble
expo diagnostics output:
Expo CLI 3.18.6 environment info:
System:
OS: Windows 10 10.0.18363
Binaries:
Node: 12.16.2
Yarn: 1.22.0
npm: 6.14.4
npmPackages:
expo: ~37.0.3 => 37.0.8
react: ~16.9.0 => 16.9.0
react-native: ~0.61.5 => 0.61.5
react-navigation: ^4.3.9 => 4.3.9
Upvotes: 2
Reputation: 61
if you want to generate apk eject the CRNA with npm run eject command. Then you will get android and ios folders suppurate in mac and you will get an only android folder in windows. and follow the instruction which is in a given link below
"https://facebook.github.io/react-native/docs/signed-apk-android.html"
Upvotes: 6