-
Notifications
You must be signed in to change notification settings - Fork 112
Guide: How to make the Spectator-View work on Hololens 2 + AndroidΒ #464
Description
Intro
After weeks of being stuck on error after error on this project, I wanted to share a complete guide on how to make this project work for Hololens 2 + Android, so that others don't have to spend this much time in developer hell.
This guide is split into two parts:
1: Building the MRSV-Unity Package
2: Building, deploying and using the package for Hololens 2 and Android.
If you want to skip building the Unity Package, I have provided a pre-build package here.
You can download it & directly go to part 2!
Prerequesites
-
Unity 2019.2.21 It is very important that you use this specific version of Unity, other Versions, even with only minor differences will make the builds fail!
- Add the Android, UWP and Windows build packages to the Unity install
- Select all options (Install JDK, NDK ect..) for the Android package
-
Inside of Visual Studio Enterprise, you have to install:
- .Net Desktop Development, C++ Desktop Development
- Universal-Windows Platoform Development
- Game Development with Unity
- MSVC v142 - VS 2019 C++ ARM64 Buildtools (latest)
- MSVC v142 - VS 2019 C++ ARM64 Libraries (latest)
- MSVC v142 - VS 2019 C++ ARM Buildtools (latest)
- MSVC v142 - VS 2019 C++ ARM Libraries (latest)
- Windows 10 SDK 10.0.18362.0
- USB Device Connectivity (optional)
- C++ UWP Support for v142 Buildtools (ARM64)
-
Git installed, check the Option to add it to the path during installation
-
Nuget command line downloaded and added to your path
-
At least 40 GB of free disk space
Part 1: Building the MRSV-Unity Package
Before starting with the building process, it is extremely important that you have the exact software that is described here installed on your system. If you don't use the exact same version, the build might fail
Step 1: Downloading & Setup all files
To download all the neccessary files, we first need to specify the folders in which we want the files to be downloaded into. To avoid conflicts during build that can arise due to exceeding the max path length limit, you should create a folder that is very close to the root of your drive. For example, I created a folder C:\Dev\Software and a folder C:\Dev\Tools.
I put the nuget.exe into the C:\Dev\Tools folder and added it to the path.
Now open a command line window with administrator rights and navigate to your path:
cd C:\Dev\Software
Now we'll clone this repository as a submodule. Type the following command into the command line and wait until git has finished:
git init
git submodule add https://github.com/microsoft/MixedReality-SpectatorView
We should have a copy of this repo in our folder now. Now we execute a .bat file inside of the repo, that will download, install and build the Unity Package...at least in theory. The process will fail a at first, but we'll fix that later. Nevertheless, it is still very important that you execute this command once, so that all files are being downloaded. While doing this, pay very close attention the the console output! Luckily, the logging is quite good and will remind of any errors that exist.
Let's start by executing MixedReality-SpectatorView\tools\scripts\CreateUnityPackage.bat -HardCopySymbolicLinks
Depeding on your internet connection and CPU, this might take from ten minutes to a few hours. A lot of files will be downloaded now and a build attempt will be made.
When the process is done, you should see something similar to this:
Notice all the 'FALSE' flags on the build results, which indicate an unsuccessfull build. Let's find the culprit!
2: Fixing TIFF UWP
When we scroll up on our log we see this error:
This is caused by an incompatibility of the TIFF library with the UWP-Platform. To fix this, we need to patch the source code file.
Luckily, vcpkg (the library manager used in this repo) allows us to patch faulty files.
To do this, we'll go into the Tiff-Lib Source folder with the command line via this line ( Replace vX.X.X-xxxxxx.clean with whatever your folder is called there):
cd MixedReality-SpectatorView\external\vcpkg\buildtrees\tiff\src\vX.X.X-xxxxxxxxx.clean
Then we initiate an empty git repository, which allows us the create the patch file, add the current version of the files to it and commit it:
git init .
git add .
git commit -m "temp"
Now we can modifiy the files. To do that, we go into the MixedReality-SpectatorView\external\vcpkg\buildtrees\tiff\src\vX.X.X-xxxxxxxxx.clean\libtiff\ folder and open tif_win32.c inside of a text editor
Now we need to delete this code at around line 280:
fd = (thandle_t)CreateFileA(name, (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, NULL);
And replace it with this code:
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) fd = (thandle_t)CreateFile2(name, (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), FILE_SHARE_READ | FILE_SHARE_WRITE, dwMode, NULL); #else fd = (thandle_t)CreateFileA(name, (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, NULL); #endif
And the same for this code at around line 330, delete:
fd = (thandle_t)CreateFileW(name, (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, NULL);
replace it with:
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) fd = (thandle_t)CreateFile2(name, (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ | GENERIC_WRITE), FILE_SHARE_READ | FILE_SHARE_WRITE, dwMode, NULL); #else fd = (thandle_t)CreateFileW(name, (m == O_RDONLY)?GENERIC_READ:(GENERIC_READ|GENERIC_WRITE), FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwMode, (m == O_RDONLY)?FILE_ATTRIBUTE_READONLY:FILE_ATTRIBUTE_NORMAL, NULL); #endif
Now save the file and close it.
Back in our command line, we get the difference between our last commit and the changed file, and output it as a diff file. This is our Patch file. To do this, we enter:
git diff --ignore-space-at-eol --output Fix_UWP_Tiff.patch
Now we should have a Fix_UWP_Tiff.patch file in our vX.X.X-xxxxxxxxx.clean folder. Move this file to MixedReality-SpectatorView\external\vcpkg\ports\tiff\
To apply the patch, we open the "portfile.cmake" in the same folder, and add Fix_UWP_Tiff.patch after "FindCMath.patch" on line 66, save it.
Now we can go back to the parent folder of the MRSV-Repo with cd C:\Dev\Software\ and then try to build again MixedReality-SpectatorView\tools\scripts\CreateUnityPackage.bat -HardCopySymbolicLinks
Now after the build has concluded, most build results should be "TRUE" (Exept for the optional stuff like Elgato, Blackmagic ect.)
3: Fixing the QR-Code dependencies
In the current state of the project, important C-Sharp files for the QR-Code detection are simply removed from the package. Without them however, the QR-Code detection won't work. To fix this problem, open MixedReality-SpectatorView\tools\Scripts\ExternalDependencyHelpers-psm1 inside of a text editor, and remove these lines, then save it:
# TODO - remove this deletion step once qr code nuget packages don't break mac builds Write-Host "Removing c# files that break in Unity packages for QRCode Dependencies in directory $contentFolder\*.cs*" Remove-Item -Recurse $contentFolder -Include *.cs*
Rebuild the package again with the command MixedReality-SpectatorView\tools\scripts\CreateUnityPackage.bat -HardCopySymbolicLinks
4: Copy QR-Code dependencies into the package
The package has been built, but they are missing the QR-Code dependencies. So we need to copy the contents of the folder "MixedReality-SpectatorView\external\MixedReality-QRCodePlugin\UnityFiles" into the folder "MixedReality-SpectatorView\packages\com.microsoft.mixedreality.spectatorview.1.2.0\SpectatorView.ExternalDependencies\UnityFiles"
Done! The package is now ready to be used inside of Unity π
Part 2: Building the Hololens 2 & Android Apps
For this tutorial, I'll be using the sample scenes that are shipped with this repository.
If you skipped Part 1 and just downloaded the package, you still need to clone this git repository, to use the Sample scenes in there. Clone the repository somewhere close to the root of your C:\ drive (For example C:\Dev\Software).
Step 1: Configuring the project
Open up the "C:\Dev\Software\MixedReality-SpectatorView\samples\SpectatorView.Example.Unity" folder with Unity 2019.2.21.
If asked about upgrading/reimporting the project due to a newer Unity version, go ahead. Ignore the errors in the console for now.
Now we'll add the MRSV-Package via Window > Package Manager > + > Add Package from Disk
Select the package.json from our package (C:\Dev\Software\MixedReality-SpectatorView\packages\com.microsoft.mixedreality.spectatorview.1.2.0\package.json)
There are two remaining errors in the console, you can ignore them for now.
Now we open our Sample Scene (Assets > Scenes > SpectatorView.Hololens) and Update the Asset Caches (Spectator View > Update All Assets Caches)
Step 2: Setting the right Windows SDK in the registery
MRSV only works with SDK 10.0.18362.0. Later SDKs have a bug in the Networking sockets. You can theoretically choose which SDK Unity should use in the build dialog, but this doesn't actually work. Instead we need to do this in the windows register:
Open the windows search bar and type "Registry", open the Registry-Editor. Open the folder:
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0
In there, open the Entry "ProductVersion" and change it's value to "10.0.18362.0". Done!
Step 3: Building the Hololens App
In the SpectatorView.Hololens Scene, select the "SpectatorView" GameObject and click on "Hololens" on the Platform switcher. This should configure the project correctly for the Hololens. Also make sure that the "Role" is set to "User" on the Spectator View Script.
Now, open the build settings, and make sure they look like this:
You can disable "Development Build", "Script Debugging" and "Wait For Managed Debugger", but I'd recommend it, so that you can notice any errors that might have.
Hit Build, and build the project to any directory you want.
When the build is done, open the newly created Visual Studio solution inside your build folder with Visual Studio 2019.
Power on your Hololens, and connect your Hololens to the same network as your computer.
Check that The "SpectatorViewExampleUnity" Projekt is set as startup project (Bold text)

Now, configure your project as Release | ARM64 | Remote Machine

Go to Configuration Properties > Debugging > Machine Name and enter the IP of your Hololens

Now hit the "Play/Build" button, and your app will be uploaded to the Hololens.
Step 4: Building for Android
In the SpectatorView.Hololens Scene, select the "SpectatorView" GameObject and click on "Android" on the Platform switcher. Also make sure that the "Role" is set to "Spectator" on the Spectator View Script.
Now, open the build settings, and make sure they look like this:
"Development Build" and "Script Debugging" is optional again, but is helpful for debugging if anything goes wrong. You can use Android Logcat to watch for errors.
Build it! If asked about a gradle conflict, select "No". Install it on your Android device with ADB
Step 5: Running the Apps
Connect both of your devices to the same network. You may have to disable mobile data on your phone.
Start both apps. When you can see the three boxes on your Hololens, enter the IP adress of your hololens in the Android App and connect. When a QR-Code shows up, grant permissions to use the camera inside of the Hololens and hold to it's front camera to scan it. You may have to restart the Hololens 2 and Android app after granting permissions.
The scene should now hopefully also show on your android device! Good Luck!






