MixedReality-WebRTC icon indicating copy to clipboard operation
MixedReality-WebRTC copied to clipboard

[Android] Changes to documentation for a successful build

Open drejx opened this issue 6 years ago • 5 comments

Describe the bug I was following the instructions at https://github.com/microsoft/MixedReality-WebRTC/tree/master/tools/build/android to build the libwebrtc and mrwebrtc .aar files needed for Android. I had to do a few different things in order to get a successful build and wanted to detail them here so (a) the team has some feedback from a fresh installation and (b) info for anyone who is trying to also build them.

Android is still what I would consider a pre-release version so I understand that the documentation isn't 100% up-to-date with changes in master :)

My Setup

  • Synced to commid ID 800e7fcac457cf70a16a6659fc9a415b6314c752
  • Since a proper Linux installation is suggested (as compared to some form of Linux emulation) I setup a Hyper-V VM on my Windows 10 system and installed the available Ubuntu 18.04 distro.
  • Instructions followed at https://github.com/microsoft/MixedReality-WebRTC/tree/master/tools/build/android

Changes I Made To Successfully Compile Android

Instruction section: Building the Chromium WebRTC base library (libwebrtc) https://github.com/microsoft/MixedReality-WebRTC/blob/master/tools/build/libwebrtc/README.md

  • Ensure you have 60GB of disk space. Besides syncing the repo there is Android Studio and various system packages to download (that was my experience with Ubuntu 18.04 in a Hyper-V VM at least). For Hyper-V at least when you launch Ubuntu you'll only see 12 GB of available drive space. Your 60GB is there, but 48GB is unallocated partition space. You need to run the gparted tool to allocate that 48GB to your drive.
  • Before doing the 'sudo apt-get clang' step, run 'apt update' to retrieve the available list of packages (probably only necessary on a fresh Ubuntu/Linux install)
  • Once you finish building the libwebrtc.aar archive it's copied to 'libs/Microsoft.MixedReality.WebRTC.Unity/Assets/Plugins/arm64-v8a/libwebrtc.aar', when I think it should be copied to 'libs/unity/library/Runtime/Plugins/arm64-v8a/libwebrtc.aar'

Instruction section: Build MixedReality-WebRTC for Android https://github.com/microsoft/MixedReality-WebRTC/blob/master/tools/build/android/README.md

  • JRE: not necessary to install separately it as it comes with Android Studio
  • After running the script and opening the resulting project in Android Studio for the first time, Gradle started a project sync and failed with an error message that the required NDK version wasn't installed. I had to manually go into File -> Project Structure and select the directory where the NDK was installed. Once I applied that it automatically triggered a Gradle sync which then successfully completed.
  • The first time building, the compilation failed with "libs/mrwebrtc/src/ref_counted_base.h:46:16: error: no template named 'atomic_uint32_t' in namespace 'std'; did you mean 'atomic_init'?".
  • I fixed that error by replacing it with std::atomic<std::uint32_t>, but just got a bunch more compilation errors, so I figured it must be a clang version problem.
  • clang++ is packaged with the NDK (I think this is a recent change) so I was able to fix the compilation errors by downloading the latest Android NDK (version 21.2.6472646) instead of using the version listed in the instructions (16.1.4479499). This could probably also be fixed by having Android Studio point to the system-installed clang (which should be the most recent from the apt tool).
  • If you want to go the route of updating to the latest NDK:
    • In Android Studio go to File -> Settings -> Appearance and Behavior -> System Settings -> Android SDK
    • Select the SDK Tools tab and look for "NDK (Side by side).
    • To see all the NDK versions available check the "Show Package Details" checkbox on the lower right
    • After the NDK is downloaded you need your project to point to it. In Android Studio go to File->Project Structure and updated the Android NDK location.

Feel free to close this bug as I understand that Android is still pre-release and the documentation is subject to change. Anyone else trying to compile would still be able to search and find this post for reference.

Cheers, Andrej

drejx avatar Jun 03 '20 18:06 drejx

Hi Andrej, thanks for the feeback!

A few comments:

Ensure you have 60GB of disk space.

That is indeed my experience too, we should update that. I think you can manage with less in a CI config where the image has less clutter, but from a standard desktop image like Ubuntu 18.04 with all UI packages installed etc. 60GB is indeed necessary.

Your 60GB is there, but 48GB is unallocated partition space. You need to run the gparted tool to allocate that 48GB to your drive.

That really depends on how you set it up; that's an Hyper-V thing here.

Once you finish building the libwebrtc.aar archive it's copied to 'libs/Microsoft.MixedReality.WebRTC.Unity/Assets/Plugins/arm64-v8a/libwebrtc.aar', when I think it should be copied to 'libs/unity/library/Runtime/Plugins/arm64-v8a/libwebrtc.aar'

That's already fixed on master.

I fixed that error by replacing it with std::atomicstd::uint32_t, but just got a bunch more compilation errors, so I figured it must be a clang version problem.

I had no issue. Can you please check with the recent change from yesterday? I fixed a bunch of small quirks on Android, and merged the two AAR archives.

clang++ is packaged with the NDK...

I appreciate some users are not overly familiar with Linux/Android and that asking them to build there when they're familiar with Windows or iOS only is a pain. However that is more of a general Linux setup thing here, and we don't really have the resources to right a full-blown Linux getting started unfortunately.

If you want to go the route of updating to the latest NDK: ...

Unity requires a very specific version of NDK that now ships with the Unity editor, so I recommend sticking with that one (or the closest you can find to that one) to avoid any issue. I am not sure why they do that, but they specifically state that no user-installed version is supported, only the one they ship with the editor (which may or may not be modified, no idea; didn't have an issue using a stock install so far).

I'll see to integrate some of those feedbacks when we write a proper Android documentation, as soon as we're done with the last blocker (video capture). Thanks!

jehumb-havok avatar Jun 03 '20 19:06 jehumb-havok

Hi Jerome,

No problem, glad to help out even for docs :)

I agree some of my notes are specific to Hyper-V, but I wanted to include them as it's a great option for Windows users and it can be daunting if one has never used Linux. These days though the UI is pretty mint! And of course butler Google helps ;)

Unity requires a very specific version of NDK that now ships with the Unity editor, so I recommend sticking with that one (or the closest you can find to that one) to avoid any issue. I am not sure why they do that, but they specifically state that no user-installed version is supported, only the one they ship with the editor (which may or may not be modified, no idea; didn't have an issue using a stock install so far).

My understanding is it's not a technical requirement per-se, but more that they test against the currently released NDK and likely by the time Unity releases a new version of the Editor it requires a NDK a few versions older.

I kinda pieced this together and you can see how Unity 2019.3 (latest version) requires NDK version r19 (19.2.5345600). See the table at the bottom of the page:

https://docs.unity3d.com/Manual/android-sdksetup.html

Cheers, Andrej

drejx avatar Jun 03 '20 23:06 drejx

@drejx Did you encounter any issues running running this on Unity? Specifically with the much newer NDK you used to build it? Finally got the Android build succeeding; the last problem I was facing was the atomic_uint32_t issue that I resolved by updating the NDK as you pointed out, I can't test for a couple of days so I'd to know your experience ahead of time if you wouldn't mind sharing. (P.S. I'm on Unity 18.4)

OmarAYousry avatar Jul 04 '20 04:07 OmarAYousry

I had the same problems, and one more after using ./build -c Release and then in Android Studio "Make Project" it was error with Path, it was looking for src/out/Debug folder but there was only "src/out/Release" after using "-c Debug" everything worked perfect.

In unity everything works, but i had to add permissions for camera and audio in AndroidManifest.

desto12 avatar Jul 21 '20 16:07 desto12

@desto12 I tried just now and there's no issue, the Debug build uses the Debug version of libwebrtc.a as expected, and the Release one the corresponding Release variant. Check that the Release configuration is actually selected in Android Studio.

jehumb-havok avatar Jul 23 '20 13:07 jehumb-havok