简体   繁体   中英

sourceSets with awsconfiguration.json

I am using AWS Amplify and have two environments that I am switching between, therefore I have two awsconfiguration.json files, but need a way to switch between the two at runtime. I've heard you can use sourceSets, but can't figure out how. I tried the following, but with no success. I believe I have to setup a productFlavor and/or buildType ?

sourceSets {
    prod {
        res.srcDirs = ['res-prod']
    }

    dev {
        res.srcDirs = ['res-dev']
    }
}

Put your awsconfiguration.json under assets directory per each product flavor, see the directory structure as shown below:

在此处输入图片说明

For how to configure product flavor and build types, please refer to: https://developer.android.com/studio/build/build-variants for more details.

Then inside your code refer to your assets using code like below:

AssetManager am = context.getAssets();
InputStream is = am.open("awsconfiguration.json");

Reference:

  1. Android get file from asset/raw
  2. https://developer.android.com/reference/android/content/res/AssetManager

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM