Cannot install multiple variants of android app in my phone

I am creating an android app and currently have my environment variables as described in the docs “Installing app variants on the same device”.
my app.config.js looks like the docs:

const IS_DEV = process.env.APP_VARIANT === 'development';

export default {
  // You can also switch out the app icon and other properties to further
  // differentiate the app on your device.
  name: IS_DEV ? 'MyApp (Dev)' : 'MyApp',
  slug: 'my-app',
  ios: {
    bundleIdentifier: IS_DEV ? 'com.myapp.dev' : 'com.myapp',
  },
  android: {
    package: IS_DEV ? 'com.myapp.dev' : 'com.myapp',
  },
};

I also have an android folder generated from expo prebuild.
I have two issues:

  1. When I build, the app name remains the same irrespective of environment and I cannot install different environment apps at the same time in my phone.
  2. How do I run APP_VARIANT=development expo start ? It always gives an error:
At line:1 char:1
+ APP_VARIANT=development expo start
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (APP_VARIANT=development:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Hi @jeremiahtam

OK, I suspect you’ll need to run npx expo prebuild --clean to regenerate the native projects whenever you change the APP_VARIANT environment variable. Or else you will need to follow the " In bare project" part of the docs.

Note: Running npx expo prebuild --clean will delete and regenerate the android and ios directories. So if you’ve made any changes in there, you might want to save them and re-apply them afterwards or something like that.

Can I ask why you ran npx expo prebuild?

Are you running PowerShell? I suspect that’s where that ugly error message is coming from :slight_smile:

That way of running a command will only work on Unix/macOS. On Windows you would need to do this:

npx cross-env APP_VARIANT=development npx expo start
1 Like

Running the above snippet worked. Unfortunately, it still does not change the app variant. I am about to run the prebuild again.

I created the prebuild because of Notifee. I had to make adjustment to:

 compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '31')
        targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '31')

changed 31 to 33 for it to work.

Ah yes, it won’t work if you’re using prebuild. If you’ve run prebuild you should rather follow the “bare workflow” instructions, because that’s essentially what you have.

However…

This is not necessary. You can specify the compile/target SDK versions using BuildProperties - Expo Documentation

If I were you I would cleanup the prebuild changes and things should be a lot less confusing.

See: expo.fyi/prebuild-cleanup

1 Like

Thank you very much sir. It worked just as you said. Just one more thing before I go.
How do I start the variant server using the shortcut. My script looks like this in my package.json

 "scripts": {
    ...
    "development": "npx cross-env APP_VARIANT=development ROOT_API=http://api expo start",
    "liveTest": "npx cross-env APP_VARIANT=liveTest ROOT_API=http://api expo start",
    "preview": "npx cross-env APP_VARIANT=preview ROOT_API=http://api expo start",
    ...
  },

Once again, I am really grateful. You have saved me hours of search. Wish the docs were a bit more detailed for me to understand.
Is there a way I can give you a star on here for all the help. I am not too familiar with hos this works
EDIT:
Was able to just use yarn run liveTest and it worked. Thanks For everything.

1 Like

Glad I could help :slight_smile:

FYI, you can also abbreviate that to:

yarn liveTest
1 Like