Embed (inline) file into variable

Hello, what is the way to embed (inline) file into variable in Kotlin (with Android, so, no extra permissions needed)? F. e.:

@Embed(name = 'mock.json')
val jsonFile: String

Is there a better way to use it with Moshi?

The bad way I found is to use an ad-hoc (JSON sample):

val mock =

There’s no Kotlin specific solution for resources that I’ve seen. You just embed resources the same way you would normally for the platform being used (JVM, Android, JS, Native). For Android, see App resources overview

1 Like

I inject compile timestamps, unique serial numbers, …
via RegEx-replace directly into the source code.

To reduce errors, I replace variable contents in small classes used for this purpose only.

Can you do it without a separate script/tools?

No, of cause not.

If you will have fixed one-time resources to insert into the source, you can do it per hand.
If you have dynamically created resources, you already have external tools to create them.

No no need for such a Kotlin function.

Yeah, for Android it could be the best way to read a resource like R.raw.mock from res/raw/mock.json

I use this one:

Though I was also looking for alternative as embedded content does not get updated unless you rebuild your project.

You could use something like BuildConfig to read the file at compile time and output it into a string.