1--- 2title: Installing app variants on the same device 3--- 4 5import ImageSpotlight from '~/components/plugins/ImageSpotlight'; 6 7When creating [development, preview, and production builds](../eas-json.mdx#common-use-cases), it's common to want to install one of each build on your device at the same time. This allows you to do development work, preview the next version of your app, and run the production version all on the same device, without needing to uninstall and reinstall the app. 8 9In order to be able to have multiple instances of an app installed on your device, each instance must have a unique Application ID (Android) or Bundle Identifier (iOS). 10 11**If you have a bare project**, you can accomplish this using flavors (Android) and targets (iOS). To configure which flavor is used, use the `gradleCommand` field on your build profile; to configure which target is used, use the `scheme` field for iOS. 12 13**If you have a managed project**, this can be accomplished by using **app.config.js** and environment variables in **eas.json**. 14 15## Example: configuring development and production variants in a managed project 16 17Let's say we wanted a development build and production build of our managed Expo project. Your **eas.json** might look like this: 18 19```json 20{ 21 "build": { 22 "development": { 23 "developmentClient": true 24 }, 25 "production": {} 26 } 27} 28``` 29 30And your **app.json** might look like this: 31 32```json 33{ 34 "expo": { 35 "name": "MyApp", 36 "slug": "my-app", 37 "ios": { 38 "bundleIdentifier": "com.myapp" 39 }, 40 "android": { 41 "package": "com.myapp" 42 } 43 } 44} 45``` 46 47Let's convert this to **app.config.js** so we can make it more dynamic: 48 49```javascript 50export default { 51 name: 'MyApp', 52 slug: 'my-app', 53 ios: { 54 bundleIdentifier: 'com.myapp', 55 }, 56 android: { 57 package: 'com.myapp', 58 }, 59}; 60``` 61 62Now let's switch out the iOS `bundleIdentifier` and Android `package` (which becomes the Application ID) based on the presence of an environment variable in **app.config.js**: 63 64```js 65const IS_DEV = process.env.APP_VARIANT === 'development'; 66 67export default { 68 // You can also switch out the app icon and other properties to further 69 // differentiate the app on your device. 70 name: IS_DEV ? 'MyApp (Dev)' : 'MyApp', 71 slug: 'my-app', 72 ios: { 73 bundleIdentifier: IS_DEV ? 'com.myapp.dev' : 'com.myapp', 74 }, 75 android: { 76 package: IS_DEV ? 'com.myapp.dev' : 'com.myapp', 77 }, 78}; 79``` 80 81> **Note**: if you are using any libraries that require you to register your application identifier with an external service to use the SDK, such as Google Maps, you will need to have a separate configuration for that API for the iOS Bundle Identifier and Android Package. You can also swap this configuration in using the same approach as above. 82 83To automatically set the `APP_VARIANT` environment variable when running builds with the "development" profile, we can use `env` in **eas.json**: 84 85```json 86{ 87 "build": { 88 "development": { 89 "developmentClient": true, 90 "env": { 91 "APP_VARIANT": "development" 92 } 93 }, 94 "production": {} 95 } 96} 97``` 98 99Now when you run `eas build --profile development`, the environment variable `APP_VARIANT` will be set to `"development"` when evaluating **app.config.js** both locally and on the EAS Build worker. When you start your development server, you will need to run `APP_VARIANT=development expo start` (or the platform equivalent if you use Windows); a shortcut for this could be to add a script to your **package.json** such as `"dev": "APP_VARIANT=development expo start"`. 100 101When you run `eas build --profile production` the `APP_VARIANT` variable environment will not be set, and the build will run as the production variant. 102 103> **Note**: if you use EAS Update to publish JavaScript updates of your app, you should be cautious to set the correct environment variables for the app variant that you are publishing for when you run the `eas update` command. Refer to the EAS Build ["Environment variables and secrets" guide](/build/updates.mdx) for more information. 104 105## Example: configuring development and production variants in a bare project 106 107### Android 108 109In **android/app/build.gradle**, create a separate flavor for every build profile from **eas.json** that you want to build. 110 111```groovy 112android { 113 ... 114 flavorDimensions "env" 115 productFlavors { 116 production { 117 dimension "env" 118 applicationId 'com.myapp' 119 } 120 development { 121 dimension "env" 122 applicationId 'com.myapp.dev' 123 } 124 } 125 ... 126} 127``` 128 129> **Note**: Currently, EAS CLI supports only the `applicationId` field. If you use `applicationIdSuffix` inside `productFlavors` or `buildTypes` sections then this value will not be detected correctly. 130 131Assign Android flavors to EAS build profiles by specifying a `gradleCommand` in the **eas.json**: 132 133```json 134{ 135 "build": { 136 "development": { 137 "android": { 138 "gradleCommand": ":app:assembleDevelopmentDebug" 139 } 140 }, 141 "production": { 142 "android": { 143 "gradleCommand": ":app:bundleProductionRelease" 144 } 145 } 146 } 147} 148``` 149 150By default, every flavor can be built in either debug or release mode. If you want to restrict some flavor to a specific mode, see the snippet below, and modify **build.gradle**. 151 152```groovy 153android { 154 ... 155 variantFilter { variant -> 156 def validVariants = [ 157 ["production", "release"], 158 ["development", "debug"], 159 ] 160 def buildTypeName = variant.buildType*.name 161 def flavorName = variant.flavors*.name 162 163 def isValid = validVariants.any { flavorName.contains(it[0]) && buildTypeName.contains(it[1]) } 164 if (!isValid) { 165 setIgnore(true) 166 } 167 } 168 ... 169} 170``` 171 172The rest of the configuration at this point is not specific to EAS, it's the same as it would be for any Android project with flavors. There are a few common configurations that you might want to apply to your project: 173 174- To change the name of the app built with the development profile, create a **android/app/src/development/res/value/strings.xml** file. 175 ```xml 176 <resources> 177 <string name="app_name">MyApp - Dev</string> 178 </resources> 179 ``` 180- To change the icon of the app built with the development profile, create `android/app/src/development/res/mipmap-*` directories with appropriate assets (you can copy them from **android/app/src/main/res** and replace the icon files). 181- To specify **google-services.json** for a specific flavor put it in a **android/app/src/{flavor}/google-services.json** file. 182- To configure sentry, add `project.ext.sentryCli = [ flavorAware: true ]` to **android/app/build.gradle** and name your properties file `android/sentry-{flavor}-{buildType}.properties` (e.g. **android/sentry-production-release.properties**) 183 184### iOS 185 186Assign a distinct scheme to every build profile in **eas.json**: 187 188```json 189{ 190 "build": { 191 "development": { 192 "ios": { 193 "buildConfiguration": "Debug", 194 "scheme": "myapp-dev" 195 } 196 }, 197 "production": { 198 "ios": { 199 "buildConfiguration": "Release", 200 "scheme": "myapp" 201 } 202 } 203 } 204} 205``` 206 207`Podfile` should have a target defined like this: 208 209```ruby 210target 'myapp' do 211 ... 212end 213``` 214 215Replace it with an abstract target, where common configuration can be copied from the old target. 216 217```ruby 218abstract_target 'common' do 219 # put common target configuration here 220 221 target 'myapp' do 222 end 223 224 target 'myapp-dev' do 225 end 226end 227``` 228 229Open project in Xcode, click on the project name in the navigation panel, right click on the existing target, and click "Duplicate": 230 231<ImageSpotlight 232 alt="Duplicate Xcode target" 233 src="/static/images/eas-build/variants/1-ios-duplicate-target.png" 234 style={{ maxWidth: 720 }} 235/> 236 237Rename the target to something more meaningful, e.g. `myapp copy` -> `myapp-dev`. 238 239Configure a scheme for the new target: 240 241- Go to `Product` -> `Scheme` -> `Manage schemes`. 242- Find scheme `myapp copy` on the list. 243- Change scheme name `myapp copy` -> `myapp-dev`. 244- By default, the new scheme should be marked as shared, but Xcode does not create `.xcscheme` files. To fix that, uncheck the "Shared" checkbox and check it again, after that new `.xcscheme` file should show up in the **ios/myapp.xcodeproj/xcshareddata/xcschemes** directory. 245 246<ImageSpotlight 247 alt="Xcode scheme list" 248 src="/static/images/eas-build/variants/2-scheme-list.png" 249 style={{ maxWidth: 720 }} 250/> 251 252By default, the newly created target has separate **Info.plist** file (in our case it's **ios/myapp copy-Info.plist**). To simplify your project we recommend using the same file for all targets: 253 254- Delete **./ios/myapp copy-Info.plist**. 255- Click on the new target. 256- Go to `Build Settings` tab. 257- Find `Packaging` section. 258- Change **Info.plist** value - **myapp copy-Info.plist** -> **myapp/Info.plist**. 259- Change `Product Bundle Identifier`. 260 261<ImageSpotlight 262 alt="Xcode build settings" 263 src="/static/images/eas-build/variants/3-target-build-settings.png" 264 style={{ maxWidth: 720 }} 265/> 266 267To change the display name: 268 269- Open **Info.plist** and add key `Bundle display name` with value `$(DISPLAY_NAME)`. 270- Open `Build Settings` for both targets and find `User-Defined` section. 271- Add key `DISPLAY_NAME` with the name you want to use for that target. 272 273To change the app icon: 274 275- Create a new image set (you can create it from the existing image set for the current icon, it's usually named `AppIcon`) 276- Open `Build Settings` for the target that you want to change icon. 277- Find `Asset Catalog Compiler - Options` section. 278- Change `Primary App Icon Set Name` to the name of the new image set. 279