Robin Fischer

Game programmer that wants to share and document.

Automatically let Unity copy files to Android APK 'assets' directory

TL;DL; For more info skip to next paragraph. Create a ‘assets’ directory in “Assets/Plugins/Android” to let Unity automatically copy all containing files to the APK ‘assets’ directory.

Solution

I recently had to integrate a SDK it an Android app made with Unity 3D. I had to place some configuration files directly into the ‘assets’ directory inside the APK. Naturally Unity packs my game nice and tidy into the desired APK format. But what if I want to change the content? I would have to unpack it using APK Tool and add my files. Then repack with an aligned zip.

There must be a better way. I would assume that a lot of game developers have to do this kind of stuff and that Unity would provide an easy way. Unfortunately the documentation only mentions the magic Plugins directory. Which is very useful to include native libraries and binaries. But the Plugins directory has more secret features built in. You can just create an ‘assets’ directory directly in the Plugins directory. Unity will copy the contents to the APK. Nice and handy but undocumented.

As noted by @ffyhlkain the ‘Assets/StreamingAssets’ directory can also be used to let Unity copy files to the Android ‘assets’ directory. The only difference I see is that the files in ‘Assets/StreamingAssets’ are copied on every platform and the files in ‘Assets/Plugins/Android/assets’ are only copied when building Android. Thanks for the mention. Both methods are viable options depending what you want to achieve.

This is just a little trick. But I felt like sharing it. Of course you could export an Android Studio project and add the assets in there. So many possibilities.