Skip to content

Latest commit

 

History

History
358 lines (308 loc) · 17.4 KB

build-and-debug-guide.md

File metadata and controls

358 lines (308 loc) · 17.4 KB

MechaHamster: Level Up with Firebase Edition: Build and Debugging Guide

Explanation and Links to Other Resources

The following are respectively

  1. A basic guide to building and deploying the game to a connected Android or iOS device or emulator
  2. A very detailed guide to debugging the build process

In principle you should be able to build the game using the build section but if the process either fails to produce a build or if the build fails when run, go through the steps outlined in the debugging section.

If after doing that, consulting the troubleshooting FAQ and searching documentation and helpful forums (such as Unity Answers) feel free to investigate the existing issues page of MechaHamster: Level Up with Firebase Edition and file an issue there if you don't see one similar to your concern.

While the following are not directly related to issues concerning this project, if you need other sources for possible info and debugging steps, please look into the issues pages for the ORIGINAL Mechahamster and the Firebase Unity Quickstart Guide.







Building

  1. Open the project in at least Unity 2019.
  2. Before building, verify you can play the game in Editor.
  3. Resolve any errors.
  4. Select your build target from File > Build Settings.
    • Supported Targets:
      • iOS
      • Android
  5. If you are building for an Android or iOS Simulator/Emulator enter File > Build Settings > Player Settings:
  6. Select the File > Build Settings menu option then click Build and Run.






Debugging the Build, Install and Run Process

The first time building out the game can be tricky. The process is full of pitfalls and much of the documentation on it is decentralized. To help with this, below is a succinct guide that describes how to investigate and solve many of the more common issues. It is arranged in order of where these errors may occur.

Unity Editor Launch: Compile-time errors and Safe Mode

Unity can catch compilation errors when the editor is loading/initializing. If there are issues building out the project in the current build configuration, Unity will display a dialogue asking if you want to open the project in Safe Mode.

  • The choice is not actually that important:
    You can solve the compilation issues either in or not in safe mode.
    • The major difference is that in safe mode, once you have finished fixing the issues you need to restart Unity.
  • In either case follow the instructions in Play in Editor Compile-time Issues to learn more about how to resolve these issues.


Play in Editor Compile-time Issues

 The first class of build issues will occur before you try to start a mobile build. When Unity starts up or detects changes to dependencies, code or other assets, it will try to rebuild the project. If the project is unable to compile at that time the Editor will log compilation errors to the console and if you attempt to play in editor you will receive a an error popup in Unity's Scene tab that reads "All compiler errors have to be fixed before you can enter playmode!"

Debugging Process
  1. Look at the compilation errors in the Unity Editor's console tab and try to solve them. If play in editor still fails, proceed to the next step.
  2. If you have implemented firebase functionality into the code have you imported the appropriate Firebase packages? If play in editor still fails, proceed to the next step.
  3. If you have imported the packages as .unitypackages, have you made sure they are at the appropriate .NET API level?
  4. Check that your editor is attempting to rebuild.
    • By default the Unity editor is set to rebuild whenever asset or configuration changes are detected.
    • It is possible (and sometimes desirable) that this functionality has been disabled and that your Unity Editor is set to manual refresh/recompile.
    • To Fix this either
      • Invoke manual refresh (Ctrl R on Windows or ⌘ R on Mac)
      • Enter Edit > Preferences > General and enable Auto Refresh


Play in Editor Firebase Runtime Issues

 If your game starts but runs into issues with Firebase while running, proceed through the following steps regarding google-services.json (Android) or GoogleService-Info.plist (iOS) until the problem is resolved.

  1. Make sure your build settings are set for the target you intend (iOS or Android) in File > Build Settings
  2. Download the config file(s) for your app and build target from the Firebase console in Project Settings > Your Apps
    • If you already have these files, delete them in your project and replace them with the most recent version, making sure that they are spelled exactly as displayed above without "(1)" or other numbers attached to the file names.
  3. If the console contains a message regarding files in "Assets/StreamingAssets/", make sure there are no console messages saying unity was unable to edit files there.
  4. Make sure "Assets/StreamingAssets/google-services-desktop.json" is generated and matches the downloaded config file.


Resolver and Target Device Build Errors

 This is by far the most complicated part of the process and the most prone to errors. The section is divided into three sections which are less chronological and have more to do with your build target. The first section ("General Tips'') applies regardless of your target, while the remaining two have to do with which target you are building for (Android or iOS).

General Tips
  • If at any point you want or need more resolver and/or build information, consider enabling verbose logging and reading the log after trying to build again
    • to enable verbose logging do the following on
      • iOS
        • Enable "Verbose Logging" in Assets > External Dependency Manager > iOS Resolver > Settings
      • Android
        • Enable "Verbose Logging" in Assets > External Dependency Manager > Android Resolver > Settings
  • If literally nothing in this document gets the game to build and run successfully, upgrade your install the newest LTS Unity Editor and update your packages.
Android
Use Force Resolve if having issues with resolution
  • When trying to build, if you receive errors, try to resolve android dependencies by clicking Assets > External Dependency Manager > Android Resolver > Resolve
    • If this fails, try Assets > External Dependency Manager > Android Resolver > Force Resolve
      • While this is slower, it is more dependendable as it clears old intermediate data
    • if the build is still failing try each of the following items in this list
JDK, SDK, NDK, Gradle Issues (including locating)
  • Reasons to do this:
    • If Force Resolution is failing and you have not done this yet, try this.
    • If you receive error logs about Unity being unable to locate the JDK, Android SDK Tools or NDK
  • What it does:
    • Toggling the external tool settings forces Unity to acknowledge them as it may not have loaded them properly.
  • What to do:
    • Enter Unity->Preferences->External Tools
    • Toggle the JDK, Android SDK, Android NDK and Gradle checkboxes such that they have the oppsite value of what they started with
    • Toggle them back to their original values
    • Try force resolve and/or building again
Enable Maintemplate.gradle if you can
  • If you do this you MUST enable Maintemplate.gradle (and custom gradle property template if using 2019.3 )
    • SYMPTOMS SHOWING YOU SHOULD DO THIS
      • When using the NONgradle version EDM4U will fail resolution when trying to bump up a package version number by changing it to <num>.0.
        Unity will TRY to decide on a version.
Enable Jetifier if you can
  • Unless you have a solid reason NOT to enable Jetifier, ENABLE IT in EDM4U using Assets > External Dependency Manager > Android Resolver > Settings.
    • The option name is "Use Jetifier". Run "Resolve" or "Force Resolve" again after the setting is changed.
    • If you enabled Custom Gradle Properties Template, you can verify if Jetifier is properly enabled by checking "Assets/Plugins/Android/gradleTemplate.properties" and ensure EDM4U injected lines like "android.enableJetifier=true".
    • If you do this you MUST enable Maintemplate.gradle (and custom gradle property template if using 2019.3 )
    • SYMPTOMS SHOWING YOU SHOULD DO THIS
      • When using the NONgradle version EDM4U will fail resolution when trying to bump up a package version number by changing it to <num>.0.
        Unity will TRY to decide on a version.
'Single Dex' Issues and Minification
  • If you run into an issue with "single dex"
    • Look into minification
      • Recommendation: Unless you absolutely must, do not apply different minification rules for different build configurations (debug vs release etc) as it can lead to confusion and make debugging more difficult.
iOS
Investigate Cocoapods if iOS resolution fails
Win32 Errors when building Xcode Workspace/Project on Mac
  • If the Unity Editor's console displays build output that mentions win32 errors, upgrade to a more recent LTS version of Unity after 2020.3.40f1.
    • Unity Bug
    • While this might seem extreme since there are a couple workarounds, upgrading is the fastest, most convenient and the most dependable method to deal with it.
Prefer opening Xcode Workspace files in Xcode to opening Xcode Projectr Files
  • Try to build iOS builds from Xcode Workspaces generated by cocoapods rather than Xcode Projects:
    • Why?
      • Unity by default only generates Xcode project (.xcodeproject). If EDM4U is in the project, it, by default, uses Cocoapods to generate the Xcode Workspace (.xcworkspace) using the Podfile generated by EDM4U as well.
      • In this case, it is recommended to open the generated project by double-clicking on ".xcworkspace" instead of ".xcodeproject" since the former contains references to Firebase pods.
    • if you are building in an environment you cannot open Xcode workspaces from (such as unity cloud build) then alternatively go into the iOS resolver settings, enter the dropdown Cocoapods Integration and select "Xcode project"



Target Device Runtime Errors

 This section will cover less about solving on-device Firebase runtime errors and more about how to investigate on-device errors in the first place.

Android
Inspecting Logs
  • On Simulator:
    • Inspect the logs displayed in your Emulator's console or view the Logcat window.
  • On Device
    • Familiarize yourself with adb and adb logcat and how to use it.
      • While you can use your command line environments various tools to filter the output, consider alternatively looking into logcats options.
      • A simple way to start an ADB session with a clean slate and then going about whatever operation you care to do is:
        adb logcat -c && adb logcat <OPTIONS>
        where are whatever flags you pass the command line
Installing and Running on Simulator
  • make sure to specify the CPU architecture of the machine you are running the emulator on in in File > Build Settings > Player Settings > Player > Android > Other Settings > Configuration > Target Architectures
    • If you do not do this, builds may succeed but be unable to install/run on the simulator
iOS
Inspecting Logs
  • On Simulator
    • Look at lldb in Xcode
  • On Device
    • Hook up to a computer and look at lldb in Xcode
Swift Issues
  • If you run into an issues on trying to run the game with error logs that mention swift
    1. Make sure your project generates
      • a podfile AND
      • an xcworkspace file
    2. Make sure you are opening the xcworkspace file in Xcode rather than an Xcode project
    3. If the build is still not properly running on device, enable Enable Swift Framework Support Workaround in Assets > External Dependency Manager > iOS Resolver > Settings. Take a look at the description in the settings menu. Make sure those changes are made to the generated Xcode project.
Installing and Running on Simulator
  • make sure to specify the Simulator SDK in File > Build Settings > Player Settings > Player > iOS > Other Settings > Configuration > Target SDK
    • If you do not do this, builds may succeed but be unable to install/run on the simulator