-
Notifications
You must be signed in to change notification settings - Fork 5
Android Build Environment Setup on PC
Unlike iOS, it is possible to directly build and deploy Android binaries on a PC. This guide aims to document the steps needed to set up a live Android build and debug environment, and possible issues that might be encountered.
- Unity Editor with Android build support
- Android SDK and JDK, either installed separately, or bundled with Unity Editor
- An Android phone with USB debugging enabled
To check whether your Unity Editor has Android build support, open Unity Hub and go to the "Installs" section. You should see your Unity Editor install listed with an array of symbols indication the various features supported:
If you have the "Android" symbol, then you are all set. If not, click the handle on the upper-right corner, and go to "Add Modules" to install Android Build Support.
When installing Android build support, you will have the option to install the optional Android SDK (and NDK) and JDK components. If you have them already installed, you can deselect them to avoid installing multiple copies, otherwise, just install the version bundled with Unity.
Once finished installing Android build support, load the project into Unity Editor. Then go to File - Build Settings and make sure your project is set to target Android.
If the project is not set to target Android, you can select the "Android" option and click the "Switch Platform" button.
Then close the Build Settings screen, and go to Edit - Preferences - External Tools, and scroll down to the "Android" section.
If you have decided to use your own versions of JDK, Android SDK, or NDK, you need to specify it here. In my case, I have opted to use my own JDK. However, note that JDK versions other than JDK 8 is not officially supported, though different builds of JDK 8 (i.e. AdoptOpenJDK, Azul Zulu, Amazon Corretto, Oracle JDK, etc.) should all work. In my case, I have used AdoptOpenJDK 8 with Eclipse OpenJ9.
Then close the External Tools screen, and connect your Android phone to your PC. Then go to File - Build and Run, and Unity will ask you where to save the APK-formatted build artifact. You can save it either in the source tree or out of the tree (our Git project is configured to ignore the APK artifacts). Your phone might also prompt you to allow debugging from your specific PC, just select "Yes" to continue. Once build is finished, the APK will be automatically installed, and launched for you to debug live.
Try killing all adb.exe
processes from the command prompt: taskkill /f /im adb.exe
and if it does not work, try re-starting Unity Editor and reconnecting your phone. Some Android phones might also need specific drivers for accessing via ADB, if that is the case, please consult your phone's vendor and https://www.xda-developers.com/ for more information.
The method varies. Usually this can be done by go to Settings - About Phone, and find the "Build Number" entry. Quickly tap the entry five time and you will unlock developer mode. In developer mode, you can toggle USB debugging on. If you are checking out devices from USC, there might be a security policy enforced by MDM that blocks developer mode. If that is the case, try contacting the professor, so that we can work out a solution with USC ITS.