0

I am working on an Android app project. It contains a file which contains a JSON. One can use it to mock the API call response during the development of the application.

Should I place that file in the raw folder or in the assets folder in the project?

If you answer, kindly provide reasoning behind it as well.

James Z
  • 12,209
  • 10
  • 24
  • 44
mumayank
  • 1,670
  • 2
  • 21
  • 34
  • I store my JSON file in `assets`. You can check out the difference between them here [https://stackoverflow.com/a/9563467/5444161] – Rahul Agrawal Mar 08 '19 at 11:29
  • 2
    Whichever is appropriate. I'd prefer assets in that case, but it's entirely up to you – Zoe Mar 08 '19 at 11:35
  • I'd use `assets` for a group of related things (say help files in different languages) or a font. I'd use `raw` for something unique (a set of sounds, for instance). – Phantômaxx Mar 08 '19 at 12:50
  • I think this question is opinion based. – Gourav Mar 08 '19 at 15:29
  • @Gaurav If preference between 2 things is just opinion based, then it literally means both things are subjectively equal, and hence preferring one over the other is purely subjective. Why would Android keep 2 different distinct folders for doing the exact same thing? Doesn't make sense. – mumayank Mar 08 '19 at 15:38

1 Answers1

2

assets/ is flexible in terms of structure. You can have your own directory tree in there, for organizing lots of files.

res/raw/ is flexible in terms of resource sets. You can have different versions of that resource for different configurations (e.g., res/raw/ as the default, res/raw-zh/ for use on devices configured for Chinese language use).

If you do not need any of those features, assets/ and res/raw/ are about equal in terms of capability. I tend to default to assets/.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491