Sunday, March 3, 2013

Unity to Android (Nexus 7) with Windows, notes / workflow troubleshooting

Some misc. "quirks" I encountered in setting up a build pipeline from Unity (on Windows) to Android on a Nexus 7... some is mentioned on Unity's Android quickstart docs, some required additional research. Anyway, if you're having problems, here's a pile of different things to try:
  • Unity Remote on Android doesn't work, or at least it heavily resists efforts to make it work.
  • Download and install the Android SDK, non-Eclipse version. (We won't need to use Eclipse unless we need some special third-party Android stuff; Unity will build the .apk bundle automatically.) Follow the instructions. Make sure you download packages that are API level 9 or above.
  • In Unity, go to Edit > Preferences, click External Tools, and specify the Android SDK root folder location.
  • (Maybe?:) Download and install the Java Developers Kit. (I only had the Java Runtime Environment, and the Android SDK said I was okay, but it seems I actually wasn't?)
  • On Windows 7, double-check two environmental variables (documented here) by going to Control Panel > System > Advanced (tab) > Environment Variables:
    Double-check the paths to JRE / JDK. If they're not there already, add your Java paths onto the variable "Path", e.g. "C:\Program Files\Java\jre6\bin;F:\JDK\bin;" and keep in mind that order matters, JRE should be before JDK.
    If you're encountering heapsize errors upon building in Unity: Set or add a variable: "_JAVA_OPTIONS" to "-Xmx512M"
  • Enable developer options on Android: in the Nexus 7, that means going to Settings > About [phone or device]... then tapping the "Build number" area seven (7) times, and it'll magically enable developer mode. Then in Android's "Developer Options" menu, enable USB debugging, Allow mock locations, and Stay awake. (Pictures + more details here.)
  • (Maybe?:) In Android's "Security" menu, enable apps from Unknown sources.
  • On the Nexus 7, I had to tap the "connected as media device" notification, check "Use as Camera (PTP mode)" instead of "Media (MTP)" mode. One protocol is much better supported, or something.
  • In Unity's player settings for Android, set the right API level and define a personal bundle identifier, or else the build process will error out.
Pretty convoluted... but, I'm told it could always be worse.