1--- 2title: Android build process 3description: Learn how an Android project is built on EAS Build. 4--- 5 6This page describes the process of building Android projects with EAS Build. You may want to read this if you are interested in the implementation details of the build service. 7 8## Build process 9 10Let's take a closer look at the steps for building Android projects with EAS Build. We'll first run some steps on your local machine to prepare the project, and then we'll build the project on a remote service. 11 12### Local steps 13 14The first phase happens on your computer. EAS CLI is in charge of completing the following steps: 15 161. If `cli.requireCommit` is set to `true` in **eas.json**, check if the git index is clean - this means that there aren't any uncommitted changes. If it's not clean, EAS CLI will provide an option to commit local changes for you or abort the build process. 171. Prepare the credentials needed for the build unless `builds.android.PROFILE_NAME.withoutCredentials` is set to `true`. 18 19 - Depending on the value of `builds.android.PROFILE_NAME.credentialsSource`, the credentials are obtained from either the local **credentials.json** file or from the EAS servers. If the `remote` mode is selected but no credentials exist yet, you're prompted to generate a new keystore. 20 211. Create a tarball containing a copy of the repository. Actual behavior depends on the [VCS workflow](https://expo.fyi/eas-vcs-workflow) you are using. 221. Upload the project tarball to a private AWS S3 bucket and send the build request to EAS Build. 23 24### Remote steps 25 26Next, this is what happens when EAS Build picks up your request: 27 281. Create a new Docker container for the build. 29 30 - Every build gets its own fresh container with all build tools installed there (Java JDK, Android SDK, NDK, and so on). 31 321. Download the project tarball from a private AWS S3 bucket and unpack it. 331. [Create **.npmrc**](/build-reference/private-npm-packages) if `NPM_TOKEN` is set. 341. Run the `eas-build-pre-install` script from **package.json** if defined. 351. Run `npm install` in the project root (or `yarn install` if `yarn.lock` exists). 361. Run `npx expo-doctor` to diagnose potential issues with your project configuration. 371. Additional step for **managed** projects: Run `npx expo prebuild` to convert the project to a bare one. This step will use the versioned Expo CLI for projects that use Expo SDK 46+. In SDK 48 and lower, you can still choose to use the (deprecated) global Expo CLI installation by setting `EXPO_USE_LOCAL_CLI=0` in the build profile. 381. Restore a previously saved cache identified by the `cache.key` value in the [build profile](/build/eas-json). 391. Run the `eas-build-post-install` script from **package.json** if defined. 401. Restore the keystore (if it was included in the build request). 411. Inject the signing [configuration into **build.gradle**](#configuring-gradle). 421. Run `./gradlew COMMAND` in the **android** directory inside your project. 43 44 - `COMMAND` is the command defined in your **eas.json** at `builds.android.PROFILE_NAME.gradleCommand`. It defaults to `:app:bundleRelease` which produces the AAB (Android App Bundle). 45 461. **Deprecated:** Run the `eas-build-pre-upload-artifacts` script from **package.json** if defined. 471. Store a cache of files and directories defined in the [build profile](/build/eas-json/). Subsequent builds will restore this cache. 481. Upload the application archive to AWS S3. 49 50 - The artifact path can be configured in **eas.json** at `builds.android.PROFILE_NAME.applicationArchivePath`. It defaults to `android/app/build/outputs/**/*.{apk,aab}`. We're using the [fast-glob](https://github.com/mrmlnc/fast-glob#pattern-syntax) package for pattern matching. 51 521. If the build was successful: run the `eas-build-on-success` script from **package.json** if defined. 531. If the build failed: run the `eas-build-on-error` script from **package.json** if defined. 541. Run the `eas-build-on-complete` script from **package.json** if defined. The `EAS_BUILD_STATUS` env variable is set to either `finished` or `errored`. 551. Upload the build artifacts archive to a private AWS S3 bucket if `buildArtifactPaths` is specified in the build profile. 56 57## Project auto-configuration 58 59Every time you want to build a new Android app binary, we validate that the project is set up correctly so we can seamlessly run the build process on our servers. This mainly applies to bare projects, but similar steps are run when building managed projects. 60 61### Android keystore 62 63Android requires you to sign your application with a certificate. That certificate is stored in your keystore. The Google Play Store identifies applications based on the certificate. This means that if you lose your keystore, you may not be able to update your application in the store. However, with [Play App Signing](https://developer.android.com/studio/publish/app-signing#app-signing-google-play), you can mitigate the risk of losing your keystore. 64 65Your application's keystore should be kept private. **Under no circumstances should you check it in to your repository.** Debug keystores are the only exception because we don't use them for uploading apps to the Google Play Store. 66 67### Configuring Gradle 68 69Your app binary needs to be signed with a keystore. Since we're building the project on a remote server, we had to come up with a way to provide Gradle with credentials which aren't, for security reasons, checked in to your repository. In one of the remote steps, we inject the signing configuration into your **build.gradle**. EAS Build creates the **android/app/eas-build.gradle** file with the following contents: 70 71{/* prettier-ignore */} 72```groovy android/app/eas-build.gradle 73// Build integration with EAS 74 75import java.nio.file.Paths 76 77android { 78 signingConfigs { 79 release { 80 // This is necessary to avoid needing the user to define a release signing config manually 81 // If no release config is defined, and this is not present, build for assembleRelease will crash 82 } 83 } 84 85 buildTypes { 86 release { 87 // This is necessary to avoid needing the user to define a release build type manually 88 } 89 debug { 90 // This is necessary to avoid needing the user to define a debug build type manually 91 } 92 } 93} 94 95tasks.whenTaskAdded { 96 android.signingConfigs.release { 97 def credentialsJson = rootProject.file("../credentials.json"); 98 def credentials = new groovy.json.JsonSlurper().parse(credentialsJson) 99 def keystorePath = Paths.get(credentials.android.keystore.keystorePath); 100 def storeFilePath = keystorePath.isAbsolute() 101 ? keystorePath 102 : rootProject.file("..").toPath().resolve(keystorePath); 103 104 storeFile storeFilePath.toFile() 105 storePassword credentials.android.keystore.keystorePassword 106 keyAlias credentials.android.keystore.keyAlias 107 if (credentials.android.keystore.containsKey("keyPassword")) { 108 keyPassword credentials.android.keystore.keyPassword 109 } else { 110 // key password is required by Gradle, but PKCS keystores don't have one 111 // using the keystore password seems to satisfy the requirement 112 keyPassword credentials.android.keystore.keystorePassword 113 } 114 } 115 116 android.buildTypes.release { 117 signingConfig android.signingConfigs.release 118 } 119 120 android.buildTypes.debug { 121 signingConfig android.signingConfigs.release 122 } 123} 124 125``` 126 127The most important part is the `release` signing config. It's configured to read the keystore and passwords from the **credentials.json** file at the project root. Even though you're not required to create this file on your own, it's created and populated with your credentials by EAS Build before running the build. 128 129This file is imported in **android/app/build.gradle** like this: 130 131```groovy android/app/build.gradle 132// ... 133 134apply from: "./eas-build.gradle" 135``` 136