How to build a React Native android application locally with Expo 50
Tags: reactnative, tutorial, javascript, react
Published: 2024-07-03 04:48:30

If you have sensitive information that you don't want to get on the Internet and share with Expo, or if you don't have the money to wait your turn in the queue, it's possible to build your application locally, and that's what we're going to look at today. 

> IMPORTANT: You're more likely to get it right if you're on macOS or Linux. For Windows you need to have WSL installed.

## 1. eas(Expo Application Service) account

First of all, go to https://expo.dev/ and create an account. Otherwise it will be difficult to follow this article.

## 2. Install eas-cli

EAS CLI is the command-line application you'll use to interact with EAS services from your terminal. To install it, run the following command:

```
npm install -g eas-cli
```

## 3. Login to your account

```
eas login
```

## 4. Configuring the build 

To configure your project's build, use the command
```
eas build configure
```

This command also initiates your project on your account on the expo servers.

## 5. Credentials.json

This part is important when you want to produce the version of your application that will go on the AppStore or Google Play Store. It contains the credentials and certificates your application will need to be signed and recognized by the Play Store (in our case).

If the credentials are located on your machine, you must specify this in the eas.json file, otherwise it will look for them in your online project. To do this, you can add this line to your eas.json file on the appropriate build profile.

```
credentialsSource: 'local'
```

## 6. Java 17

![screenshot of error log when java 17 is not used](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z2x8e84yfftx4zlw4v2n.png)

You must have Java installed on your machine, otherwise you'll get the above error. Version 17 is the recommended one. I haven't tested higher versions, so I can't say.

## 7. Environment variables

When you do a local build, **EAS secrets** are not supported. Instead, you need to use environment variables. If you have environment variables, expo will not take .env.local into account. So you'll need to create an .env file and then delete it every time you finish a build.  Don't add your `.env` file to your `.gitignore` file - it will be ignore.  We'll look at how to automate the whole process from step 5 onwards in a future article.

## 8. Files not to be committed:

As I said earlier, the informations contained in these files are sensitive, so it must not be possible to find them online:

- credentials.json
- Your keystore file (.jks)
- .env

## 9. Launch the build

Once all the elements are ready, you just need to know the profile for which you want to produce the application and launch the command:

```
eas build --platform android --profile (development/preview/production) --local 
```

![screenshot of build startup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h3fzswzl9dr4rswac2w0.png)

If you take the time to observe you'll see that Expo logs everything it does during the process and in the first 2 lines you can see that it:

- loads environment variables
- Uses local credentials (if specified)

Once the process has started, you wait a few minutes for it to finish and tell you where to find your application's compiler file, and voila!


![screenshot of build completed without errors](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5nhj5f3dxxhxpwdsclyy.png)

## Limitations

Some of the options available when building online are not available locally:

- You can only do one build at a time and for one specific platform (android or iOS).

- You'll have to update the `expo.android.versionCode` or `expo.ios.buildNumber` yourself.

- Caching is not supported.

- You must ensure that the environment has all the necessary tools: 
  - Node.js/Yarn/npm 
  - Fastlane (iOS only)
  - CocoaPods (iOS only)
  - Android SDK and NDK

I hope you've found this article useful, and I'll see you soon to automate the process. Ciao!