CloudRail and Unity for Android
In this guide, we will share how you can integrate our Android SDK into your Unity project.
Using CloudRail in Unity does come with some limitations which will be covered in this guide as well. So if you are developing an Android application in Unity and would like to put some of the features of CloudRail into your app, this is how you could do it:
Add the SDK to your project
- Download CloudRail from [GitHub](https://github.com/CloudRail/cloudrail-si-android-sdk) and copy the .aar file into your project at Assets/Plugins/Android (the folders might need to be created beforehand)
- You have to adjust the minimum Android API level: Go to Edit –> Project Settings –> Player –> Change the minimum API level to 15
- Depending on how you configured Unity you might need to tell Unity to use Java 8, this can be done here: Unity –> Preferences… –> External Tools –> Point Unity to the folder where you installed the JDK v1.8
Use CloudRail within your C# scripts
To quickly illustrate how you can access the SDK within your C# scripts we will compare the code for receiving the users Twitter-ID in Android as well as in C#. The Android code would look like this:
If you want more information about how to use Android plugins check the Unity documentation here.
As mentioned above, using the Android SDK in Unity is not an ideal way and hence comes with some limitations or disadvantages:
- As you have seen, it is a bit more code and less intuitive to use as our Android equivalent
- Due to the fact that Unity invokes Android plugins through the Java native interface, these calls are quite expensive and might slowdown your application
- If you want to use the upload or download functionality of the CloudStorage interface be aware of the fact that every file needs to reside within main memory in order to pass it to / read it from the Android plugin. The reason of which is that the Android SDK works with Java streams and there is no way (as far as I’m aware) to pass a Java stream from C# code through the Java native interface, the only option is to completely read the file into main memory
I hope this guide was of use for you. If you have any suggestions how this could be improved, for example solving some of the limitations, feel free to get in touch.