How to setup different configuration(awsconfiguration.json) with AWSMobileClient for debug and release build types

懵懂的女人 提交于 2020-01-02 15:03:18

问题


I want to have different configuration for debug and release builds. All the configuration is stored inside awsconfiguration.json, for example I have two different config files how can I set which file should be used.

When using AWSMobileClient.getInstance() it gets default configuration from file awsconfiguration.json

Configuration file example:

{
  "Version": "1.0",
  "CredentialsProvider": {
    "CognitoIdentity": {
      "Default": {
        "PoolId": "DIFFERENT_VALUES",
        "Region": "DIFFERENT_VALUES"
      }
    }
  },
  "IdentityManager": {
    "Default": {}
  },
  "CognitoUserPool": {
    "Default": {
      "AppClientSecret": "DIFFERENT_VALUES",
      "AppClientId": "DIFFERENT_VALUES",
      "PoolId": "DIFFERENT_VALUES",
      "Region": "DIFFERENT_VALUES"
    }
  }
}

Update There is option to use different awsconfiguration.json by puting different files in main\res\raw and release\res\raw, for example by following this answer and it works. But I'm wondering whether there is an option to do it programmatically.


回答1:


I've been trying to achieve something similar; selecting an AWS configuration at runtime based on a selected profile. I got it partially working by hacking the AWS SDK but then stumbled across release notes for AWS SDK version 2.11.0. Quoting:

Added the option of passing the configuration as an in-memory object (i.e. [String: Any]/NSDictionary) instead of the default awsconfiguration.json through the new API

I've also found it documented(!) in the amplify getting started guide here.

So since 9th September 2019 it IS possible to select an AWS configuration at runtime.


Edit: Just noticed that this question is for Android rather than iOS. I'm not an Android developer but a quick searched revealed something similar in AWS Android SDK release 2.13.6 (7th June 2019). Quoting the release notes:

Add AWSConfiguration(JSONObject) constructor to construct a AWSConfiguration object from the configuration passed via a JSONObject

... which looks promising.




回答2:


This can be done with source sets; eg. directories main & debug or directories debug & release, where res/raw or assets are not being processed by AAPT2. Adding credentials alike that is only suggested for internal use, because they can be easily extracted from the package.



来源:https://stackoverflow.com/questions/56771885/how-to-setup-different-configurationawsconfiguration-json-with-awsmobileclient

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!