I am working on this app that uses Microsoft.ML to predict certain things, it stores it’s models in zip files.
During execution, a Microsoft.ML script would go ahead and use those zip files to make predictions.
However whenever I build my game for android, then the whole app would crash saying it couldn’t load those files.
This is the code calling for the file inside the Microsoft.ML script, it works great in editor but not whenever I build.
private static string MLNetModelPath = Path.GetFullPath($"DifficultyAdjustementModels/intrudersCount predictor corrector.zip");
I could really use some help thank you.
I don’t know why it crash, but you can load files in two ways.
Either a resource placed in your “Assets/Resource” project folder at build time (this file is then put in a a resource and can’t be changed). Or you can put it in Application.persistentDataPath, or perhaps in other places in the file system at any time manually (you will have to copy the file to the device yourself). Application.persistentDataPath can be read or written to without any special android permissions, other folders may need permission.
The resource way need you to read the file as a resource like this:
//Place file in "Projectpath/Assets/Resources/Levels/file.txt"
TextAsset f = (TextAsset)Resources.Load("Levels/file"); //note no file extension
string fileText = System.Text.Encoding.UTF8.GetString(f.bytes);
The other way is just like reading a normal file in the correct path.