- Home /
Can't access assets folder on Android.,For Android, file doesn't exist in assets folder for apk file
When I run my game on ios and unity, there are no problems. Everything runs smoothly. When I run my game on Android is where things start to not work. I've narrowed it down to that fact that the game isn't able to see any files in the assets folder.
I've Exported the Android build project game into an Android Studio project. Within Android Studio, I built and ran/installed the game on an emulator. Within the emulator, I'm able to read some of the logs that print in the Run console on Android Studio.
When the game is running, it doesn't see any of the asset files in the assets directory. I doubled-checked to make sure when I did the Export that it Exported all the StreamingAssets to the assets directory...and it did. So, for some reason, when it builds, it doesn't build the asset files.
Is there something I need to configure in the gradle scripts to include the assets directory in the building of the apk? Am I missing something and exporting or in unity?
Here is my Unity code to gain access to the file:
#if UNITY_ANDROID
string filePath = "jar:file://" + Application.dataPath + "!/assets/weapons.json";
#elif UNITY_IOS
string filePath = Application.dataPath + "/Raw/weapons.json";
#else
string filePath = Path.Combine(Application.streamingAssetsPath, "weapons.json");
#endif
Using recommendations from here: https://docs.unity3d.com/Manual/StreamingAssets.html
P.S. I'm an intermediate mobile developer, but this is my first Unity game.
Answer by alirostami9690 · Dec 22, 2019 at 11:27 AM
put your files in a folder and name it StreamingAssets then use Application.streamingAssetsPath to get the path of StreamingAssets folder. you can access your files there.