I have a file - Content/Envs/1_village.tmx, I can load it on Windows, but on Android, this error pops up. I cant load it with Tiled.CS, the file simple does not exist:
I use this at path (with or without Environment.CurrentDirectory, it does not matter)
Environment.CurrentDirectory + content.RootDirectory + "/Envs/1_village.tmx"
If I look into my .apk file (unzip it), there is the file in assets/Content/Envs/1_village.tmx. It is also in the bin folder as on the screenshot. I tried to modify the path with adding “assets” but with no luck.
I have the file in MGCB tool, set only to copy. Also in solution explorer, i set it to copy if newer.
Why it cant find see the file?
I think I found the correct solution, but it is a bit awkward. You must use Stream and AssetManager for reading any non-resource files from assets, in my example it were .tmx and .tsx files from Tiled.
AssetManager assets = this.Assets;
Stream s = assets.Open("Content/my_special_file.txt");
So I set this stream in my Android project to a “Game1” static property and then I use it in my shared project. If it is not set, I use standard File.Open…
Boy, don’t use System.IO for file access. It’s not crossplatform. And don’t use android-specific assetmanager. There is a class in Monogame that is called TitleContainer. It’s still pretty awkward to use, but at least it is crossplatform.
I use isolated storage mainly, this one was only for Android.
TitleContainer is nice, it’s working. I replaced AssetManager with it. Thank you.