Loading assets from Flutter in Java doesn't work if the path has spaces:
val assetPath2 = "sound_packs/packs/Blaze_Kit/Clap.wav"
val loader = FlutterInjector.instance().flutterLoader()
val key = loader.getLookupKeyForAsset(assetPath2)
val inputStream: InputStream = context.assets.open(key)
val assetFD: AssetFileDescriptor = context.assets.openFd(key)
With underscore:
val assetPath2 = "sound_packs/packs/Blaze_Kit/Clap.wav"
it worked
but for
val assetPath2 = "sound_packs/packs/Blaze Kit/Clap.wav"
it doesn't work:
JNI DETECTED ERROR IN APPLICATION: JNI NewStringUTF called with pending exception java.io.FileNotFoundException: flutter_assets/sound_packs/packs/Blaze Kit/Clap.wav
12-20 16:40:26.544 12887 12887 F zygote64: java_vm_ext.cc:523] at long android.content.res.AssetManager.openAsset(java.lang.String, int) (AssetManager.java:-2)
12-20 16:40:26.544 12887 12887 F zygote64: java_vm_ext.cc:523] at java.io.InputStream android.content.res.AssetManager.open(java.lang.String, int) (AssetManager.java:374)
12-20 16:40:26.544 12887 12887 F zygote64: java_vm_ext.cc:523] at java.io.InputStream android.content.res.AssetManager.open(java.lang.String) (AssetManager.java:348)
12-20 16:40:26.544 12887 12887 F zygote64: java_vm_ext.cc:523] at boolean com.example.flutter_app.JNI$Companion.loadWavAsset(java.lang.String, java.lang.String, float) (JNI.kt:47)
This is the pubspec.yaml:
assets:
- 'sound_packs/packs/Blaze Kit/'
- 'sound_packs/packs/Blaze_Kit/'
I have the 2 folders named Blaze Kit
and Blaze_Kit
with the same file Clap.wav
inside of it.
Is this a bug or desired behaviour? Is there a way to encode the space in the path for the assets?