amplify-android icon indicating copy to clipboard operation
amplify-android copied to clipboard

Configure amplifyconfiguration.json for development and Production

Open shanmugpriyan306 opened this issue 4 years ago • 6 comments

How to configure and maintain two different environment details for CognitoUserPool, awsCognitoAuthPlugin, CredentialsProvider and Auth information present in amplifyconfiguration.json android. Is there any way to achieve it using build variant or flavour etc.

Current these information are stored under res/raw/amplifyconfiguration.json

shanmugpriyan306 avatar Dec 14 '20 09:12 shanmugpriyan306

Amplify Android currently does not support developing under multiple environments. We can track this as a feature request and prioritize it depending on how much traction it receives.

raphkim avatar Dec 14 '20 19:12 raphkim

it is possible to load the configuration file from different locations. We do this in our tests. You can select a config to load at runtime, and then use an alternate version of the configure method, which takes an explicit configuration object:

@RawRes val resourceId = if (BuildConfig.DEBUG) R.raw.debugConfig else R.raw.releaseConfig
val config = AmplifyConfiguration.fromConfigFile(applicationContext, resourceId)
Amplify.configure(config, applicationContext)

h/t to @jamesonwilliams who shared this approach in Discord.

I'm going to leave this open as a feature request though, because I think we could come up with a more streamlined approach that doesn't require manually creating config files, and trying to keep them up to date with the generated one.

richardmcclellan avatar Dec 17 '20 18:12 richardmcclellan

Is there any update on this?

pcanas avatar Jun 16 '22 10:06 pcanas

Any update on this since v2?

tfreeman82 avatar Apr 19 '23 18:04 tfreeman82

Hello, We have different build flavors for development and production environment. To achieve this, we stored the file under the specific path for each build flavor:

  • production: src/main/res/raw/amplifyconfiguration.json
  • development: src/dev/res/raw/amplifyconfiguration.json

reisfernanda avatar May 11 '23 18:05 reisfernanda

Olá, Temos diferentes tipos de construção para ambiente de desenvolvimento e produção. Para conseguir isso, armazenamos o arquivo no caminho específico para cada tipo de compilação:

  • produção: src/main/res/raw/amplifyconfiguration.json
  • desenvolvimento: src/dev/res/raw/amplifyconfiguration.json

I tested it here and it worked, thanks for the help

joicerodrigues avatar May 11 '23 18:05 joicerodrigues