Skip to content

Instantly share code, notes, and snippets.

@makotokato
Last active May 10, 2023 01:55
Show Gist options
  • Save makotokato/f817716228b9f3e552a8f2bdbd4c6346 to your computer and use it in GitHub Desktop.
Save makotokato/f817716228b9f3e552a8f2bdbd4c6346 to your computer and use it in GitHub Desktop.
How to build GeckoView on Windows workstation

How to build GeckoView on Windows workstation

Actually, we can build GeckoView on WSL and VMs. but since Android Studio runs under Windows, not WSL, if using WSL, you cannot use Android Studio to debug GeckoView. We have limited support to build GV on the mozilla-build environment.

Using WSL (Bash for Windows, Windows Subsystem for Linux)

Same as Linux. But,

  • You cannot use Android Studio to debug GV
  • WSL doesn't support USB. So ./mach install or ./mach run doesn't work. But this has workaround (see using ADB).
  • WSL2 (comming in Windows 10 20H1)'s filesystem is fast, but if using NTFS filesystem's directory, it will be too slow (microsoft/WSL#4197).
  • WSL2 may have limited USB support, but I don't know about adb (microsoft/WSL#2195)

Using ADB (WSL1)

  • Although WSL has no USB support, adb command on WSL can communicate to another adb process on Windows native. Before using adb command on WSL or running ./mach install, we should run adb command on windows version. (ex. ~/.mozbuild/android-sdk-windows/platform-tools/adb device).

Using ADB (WSL2)

  • See Using ADB with WSL2. platform-tools path in our mach environment is $env:USERPROFILE + "\.mozbuild\android-sdk-windows\platform-tools"

Using virtual machines

Yes, you can use Linux image on your VMs, but

  • VMWare and VirtualBox support USB.
  • Hyper-V doesn't support USB. So adb command doesn't work to install APK. Also, WSL2 (coming in Windows 10 20H1) might not support non-Hyper-V VMs such as VMWare and VirtualBox (microsoft/WSL#4112 and etc). If you want to enable/use WSL2 for some situations, we may not be able to choose VMWare and etc.

Using mozilla-build environment

artifact build

This is a sample of mozconfig.

mk_add_options AUTOCLOBBER=1
ac_add_options --enable-application=mobile/android
ac_add_options --enable-debug
ac_add_options --enable-tests
ac_add_options --target=x86_64
ac_add_options --enable-artifact-builds

no-artifact build

This is a sample of mozconfig.

mk_add_options AUTOCLOBBER=1
ac_add_options --enable-application=mobile/android
ac_add_options --enable-debug
ac_add_options --enable-debug-symbols
ac_add_options --enable-optimize
ac_add_options --enable-tests
ac_add_options --target=x86_64

# Since our lld isn't built with zlib, so some cpu type requires --enable-linker to use bfd or gold.
# ac_add_options --enable-linker=bfd

# Host compiler has to use clang-cl.
HOST_CC=clang-cl.exe
HOST_CXX=clang-cl.exe

NOTES: you have to use same drive for source path and NDK path. If different drive, generating moz.build phase is failed. It means that Gecko's source code has to be on C: drive. (bug 1600541)

Android Studio

Now, gradle script of GV requires some environment variables from mozilla-build setting. So if you want to use Android Studio, you have to set the following environment variables.

  • Set MOZILLABUILD environment variable (C:\mozilla-build\ as default install path. You must set \ as tail) to detect mozilla-build.

Running tests

You have to apply the patch from https://raw.githubusercontent.com/makotokato/gecko-mq/master/windows-ndk-build. This Python bug (NamedTemporaryFile doesn't use share mode. https://bugs.python.org/issue14243 etc and https://developercommunity.visualstudio.com/idea/880630/support-file-share-delete-for-open-and-sopen.html for VC++).

Other issues

  • If gradle runs as deamon mode, ./mach build may not be finished. So it is better to add org.gradle.daemon=false line to $HOME/.gradle/gradle.properties to avoid this.
  • When re-building GeckoView, some environments will be failure during gradle phase. If so, you have to modify "${mozillabuild}/python3/python3.exe" to "python3.exe" in https://searchfox.org/mozilla-central/source/settings.gradle#14.
  • gradle task will be failed due to stack overflow. If occured, you have to upgrade build tools to 33.0.1 (Modify android-packages.txt and android-sdk.configure.
@makotokato
Copy link
Author

Yes, since there is some changes, I update this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment