Android Development - MisterGrumpyPants/Tower GitHub Wiki
General Remarks
Checklist for developing for Android with Unity (assuming 64-bit Windows development machine):
- Unity 3D / Android build support
- Android SDK / Java SDK (JDK)
- An Android emulator
- An Android device or two / their associated drivers
- Unity Remote
Based on my research (see links below), we should either be using the Genymotion emulator (made for Android developers) or Visual Studio's Android emulator. Since I HIGHLY recommend that we do all coding in Visual Studio, the latter seems most appropriate. Also, I was able to find a nice helpful video for using that one with Unity, but none for Genymotion. In addition, the VS emulator appears to have some extra, awesome features like webcam emulation, simulation of 3D orientation and GPS location, etc. Lastly, anytime that the game is stable enough for a build, we should also test it out on a physical device, using the Unity Remote app. The more screen sizes and API levels we physically test, the better.
Cookbook Instructions
Here's my attempt to outline the setup instructions as clearly as possible, like a cookbook. I would've like to have more pictures then words, but adding images to GitHub's wiki is too tricky for me at the moment :/
-
UNITY WITH ANDROID SUPPORT
You probably already have Unity installed, but double check to make sure you have the latest version; each new release has very important bug fixes and may add awesome new features. The download link is here. The Unity installer gives you the option to (not) add a lot of features. I recommend at least installing the latest version of Unity (first option), Microsoft Visual Studio Tools for Unity (if you're using Visual Studio for scripting, which you should be!), and Windows Build Support (and/or Mac and/or Linux Build Support). For developing for Android, you'll also obviously want Android Build Support (and possibly iOS Build Support). The Web Player is outdated and the Documentation just takes up hard drive space, but the Standard Assets and Example Project might be useful for learning purposes. Note that if you've previously installed the Microsoft Visual Studio Tools for Unity (VSTU), then you will probably get an error dialog saying "The specified account already exists", but you can just click OK and then Ignore. If you have Visual Studio set up for scripting (which you should!), then you can also use that to install Unity. Go to File > New > Project, then under the Installed > Templates tab on that pop up, locate Game, and you can then click "Install Unity" (or Unreal if you so desire!) This option is less customizeable though. Finally, we need to tell Unity where the Android SDK is located. In Unity, go to Edit > Preferences > External Tools, and browse to the location of your Android SDK and JDK installations. If you do not see these options, then make sure you installed Android Build Support during Unity installation. Also make sure that when you actually want to build for Android, you go to File > Build Settings, select Android, and click Switch Platform (the little Unity symbol should appear next to Android when its done). If Unity says "No Android module loaded," make sure again that you have installed Android Build Support. -
ANDROID SDK AND JDK
SDK stands for Software Development Kit, and you see this term all over the place when you're preparing to develop for a new platform. The Android SDK is, naturally, the official set of virtual machines, code libraries, and command prompts, needed to develop for the Android platform. The Android SDK further requires the Java Development Kit (JDK), which is basically an SDK for working with the Java programming language. Even though you don't use Java in Unity, the Android SDK still requires it. You can get the Android SDK in two ways. If you have Visual Studio installed (which you should!), then I would recommend the second way (MUCH more user friendly).
- The official download pages: First, get the JDK. The official download page is a nightmare. Just make sure you click a link inside one of the boxes with a title like "Java SE Development Kit 8u73," click the "Accept License Agreement" bubble, and choose the appropriate download link for your operating system. The installer is pretty straight forward, just make sure to install the "Development Tools" and the "Public JRE" (Java Runtime Environment), source code is there if you want to take up hard drive space. Also, separate JDK/JRE versions can coexist on the same machine, so when you are done, you may want to uninstall any previous versions of the JRE. Now we can get the Android SDK. Here is it's official download page. You'll probably read a lot there about Android Studio. This is Google's official IDE for writing Java code for the Android platform. Since Unity doesn't use Java, and since Visual Studio can do everything Android Studio can do and more, I recommend avoiding the latter. The Android SDK's installer should locate your JDK installation in the first step.
- Through Visual Studio: Look up your version of Microsoft Visual Studio in Programs and Features, as if you were going to uninstall it, but then right click and click Change. After an annoying period of loading, the Visual Studio installer will come up, and you can click Modify. There are a million features to check/uncheck here, but make sure you open Cross Platform Mobile Development > Common Tools and Software Development Kits. In there, check "Android SK" (which automatically checks "Java SE Development Kit"), and any Android SDK Setup boxes that you want. Here is a nice link that breaks down the percent of phones using different API levels, so choose accordingly (this link is also in the Helpful Links section below). If you already have Hyper-V enabled, then you can also check the Visual Studio Emulator for Android here; if not, we'll get to that in the next step.
- VISUAL STUDIO EMULATOR FOR ANDROID
This is perhaps the most annoying part of this setup. You will inevitably have to Google some error that I cannot anticipate for you here. Having an emulator is absolutely essential for mobile development, unless you want to buy one of every physical device that your consumers might have, so you can test your game on each of them in turn. You should obviously have SOME physical devices for testing, say one phone and one tablet, but emulator is still pivotal. And the Visual Studio one has some awesome features like 3D device rotation, emulation for GPS, webcam, and battery percent, and more. Plus, Microsoft is working closely with Unity Technologies to keep these two softwares communicating nicely. The official system requirements for the VS Android Emulator can be found here, but in a nutshell:
- Windows 8 or higher, 64 bit, Pro (this part got me, make sure you're using Pro!)
- 6GB memory or higher
- Hyper-V enabled
- Hyper-V requires hardware-assisted virtualization, SLAT, and DEP (you'll probably need to restart and enable these things in your BIOS)
Hyper-V is Microsoft's way of creating virtual machines and comes with out-of-the-box Windows Pro editions. To enable it, go to Programs and Features, like you were going to uninstall something, then in the left pane click "Turn Windows features on or off". Make sure the box next to Hyper-V is checked, and you'll probably have to restart.
Finally, you can go here to download the VS Android emulator. If you already have Visual Studio installed (which you should!), then you can also just Modify your version of Visual Studio like we did in Step 1, and check Visual Studio Emulator for Android.
-
ANDROID DEVICE SETUP AND DRIVERS
The charge cord that came with your Android device should have a USB that can be plugged right into your development machine. You will need to enable Devloper Options on that device. Go to Settings > About phone and tap Build Number seven times (and spin around three times and stand on your head). Now you have Developer options item under Settings. Go into that menu and turn Developer options on, then turn on USB debugging. At that point, you can plug your device in, and your operating system should automatically start installing the necessary drivers. To verify, you can use the Android Debug Bridge (ADB) that comes with the Android SDK. You can run ADB from command prompt in Windows. I recommend editing your Path environment variable to make this task easier in the future (instructions to set this up can be found here). Then, at the command prompt, you can type "adb devices", hit enter, and you should get at least one line of seemingly random numbers identifying your device! ADB is very powerful and can do a lot more; a full list of its commands is located here. Note, if you are currently running a virtual device in an Android emulator, then ADB will also show this as a device! -
UNITY REMOTE
This is final step. Having an emulator is great for testing official builds and all, but when you're deep in the middle of a development session and just want to quickly run a new scene or debug a new script, you'll want to have the Unity Remote app. This official Unity Technologies app is available on the App Store or Google Play. Once you install it on your device, plug that device into your computer, run Unity Remote, and then start Unity Remote. You must do it in that order or Unity will not recognize your device. Furthermore, if you close Unity Remote on your device, you will have to restart Unity for the device to be recognized again. This can be a major annoyance if your USB connection is unreliable. But when everything is working, you'll feel extremely pumped when you click play in Unity, and see the game start running simultaneously on your computer and on the Android device! Remember, Unity Remote should only be for debugging; legitimate performance tests of your game should be done with an actual build, installed to a physical device as an .apk file. Read over the end of step 1 for instructions on building in Unity for Android.
So there you go! Hopefully that was all clear as mud and didn't take more than 5 hours to get through...
Helpful Links
Here's a list of some good Android Emulators:
6 best Android emulators for PC
And a video about using Visual Studio Emulator for Android with Unity:
Testing Unity games on Android in Visual Studio
Here's the official breakdown of the percent of devices using certain Android versions, screen sizes/densities, and OpenGL versions:
Dashboards | Android Developer
Here's the official breakdown of Android versions, codenames, and API levels:
Codenames, Tags, and Build Numbers
And Unity's page on the Unity Remote app:
Unity Remote 4