avatar

Tips for Android Development

codermic writes a diary

Recently, I’ve been working more with Android tablets to deploy our games there. Unity3D has been, as usual, very accommodating in its deployment features. All you need to build on your device is the Android SDK, matching drivers for your device and you’re set. There are still a few things to watch out for and some little tricks to help you do your work faster.

General

First, a hint on disappearing devices. We experimented with a Samsung device (Galaxy Tab 2 10.1), which had the Kies driver. Occasionally Unity3D stopped registering the device, even after reconnecting it. The solution to this was simply killing Kies and restarting it, after which Unity3D happily deployed directly to the device again.

texturesettings
If your textures look grainy like on the left, it is because Android devices require different import-settings. This mostly happens to textures with an alpha-channel. To fix it, simply set the Texture Type to Advanced and then Format to RGBA 32 bit.
Overall texture quality can be improved for things like UI planes by setting Non Power of 2 to ToLarger and by increasing the Max Size.

Reading and writing files only works in certain paths that your app has write-access to. Unity3D conveniently provides a direct link to this via Application.persistentDataPath.
Accessing an external storage device requires the full path, which usually includes the mountpoint. On our Samsung device the drive „UsbDriveA“ was mounted to /mnt/UsbDriveA/, which requires you set write access to External in your player settings.

ADB

To use the Android Debug Bridge (ADB) to connect your device to the Unity3D profiler, you have to first set up a forward:

Code   
adb forward tcp:54999 localabstract:Unity-*your bundle indentifier*

After which you can simply access the running app through the profiler, provided you checked Development Build and Autoconnect Profiler (this might not be neccessary anymore) in the build settings.

Another useful feature of the ADB is logcat, which enables you to see errors and prints on your device:

Code   
adb logcat -s Unity:IWEF

When hitting „Build and Run“ Unity3D automatically installs and starts your app. You can do the installing and starting yourself with ADB by doing this:

Code   
adb install -r *Path to your apk*
adb shell am start -S -a android.intent.action.MAIN -n *identifier*/com.unity3d.player.UnityPlayerProxyActivity

Edit: This seems to have changed to com.unity3d.player.UnityPlayerNativeActivity since 4.3

And likewise you can also stop your app with ADB:

Code   
adb shell am force-stop *identifier*
This entry was posted in Code and tagged , . Bookmark the permalink.