Im trying to load an asset from flutter project "asset" folder into native code. For example I want this file /assets/labels.txt (Flutter folder) to load it in a Kotlin script in the path android/app/main/kotlin/MainActivity.kt.
I successfully connect Flutter into Kotlin but I have errors when I try to load it.
class MainActivity : FlutterActivity() {
private val CHANNEL = "your_channel_name"
private val LABELS_PATH = "assets/labels.txt" //
private fun loadLabels() {
try {
Log.d("LoadLabels", "Loading labels...")
val reader = BufferedReader(InputStreamReader(assets.open(LABELS_PATH)))
labels = reader.readLines()
reader.close()
labels.forEach { line ->
Log.d("TextFileContent", line)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
// ...
}
These are my errors :
D/LoadLabels(11123): Loading labels...
W/System.err(11123): java.io.FileNotFoundException: assets/labels.txt
So my question is this :
I must load the assets always from Flutter project folder or from the same folder that the native code script is? Also what is my error here?
Thanks.