available lang for this post:en
trouble shooting for Fenix build (Apple M4 Pro chip)
Fenix is Firefox for android. It's different from ordinary Firefox in many ways.
docs for build Fenix
summary (not 100% guaranteed)
- I'd already built Firefox on bookmarks/central.
- I followed the doc.
- Ran softwareupdate --install-rosetta.
- Ran ./mach --no-interactive bootstrap --application-choice="GeckoView/Firefox for Android".
- Then I have to set $JAVA_HOME and $ANDROID_HOME as this doc says.
export JAVA_HOME=$HOME/.mozbuild/jdk/jdk-<latest-version>/Contents/Home export ANDROID_HOME=$HOME/.mozbuild/android-sdk-<os_name>
- You may possibly have to set $CPPFLAGS as empty when it fails.
- I think those who installed jdk via homebrew might have to be careful about if switching jdk by $JAVA_HOME really works.
- Usually osx can switch jdk version by changing $JAVA_HOME thanks to /usr/libexec/java_home.
- But if your $PATH includes /opt/homebrew/opt/openjdk/bin, that may disable the switching.
- I removed /opt/homebrew/opt/openjdk/bin from $PATH and confirmed this had enabled the switching.
- Now run java --version. If your terminal answers OpenJDK Runtime Environment Temurin-17.0.14+7 (build 17.0.14+7), let's build by ./mach build. That's it.
log
- I use Mac with an Apple M4 Pro chip.
- I followed the doc: https://firefox-source-docs.mozilla.org/mobile/android/index.html#id1
- I'd already built Firefox on bookmarks/central.
- So started from running softwareupdate --install-rosetta. It succeeded.
- Ran ./mach --no-interactive bootstrap --application-choice="GeckoView/Firefox for Android". It succeeded.
- Then, ./mach build caused an error. So installed Android Studio for the moment. But ./mach build still caused an error.
$ ./mach build ......... 0:01.76 security/nss/lib/pki 0:01.81 security/nss/lib/smime 0:02.13 /Users/XXXXXX/mozilla-unified/mozglue/android/APKOpen.cpp:114:44: error: cannot initialize a parameter of type 'void **' with an rvalue of type 'JNIEnv **' (aka 'JNIEnv_ **') 0:02.13 114 | sJavaVM->AttachCurrentThreadAsDaemon(&env, nullptr) != JNI_OK) { 0:02.13 | ^~~~ 0:02.13 /opt/homebrew/opt/openjdk/include/jni.h:1959:45: note: passing argument to parameter 'penv' here 0:02.13 1959 | jint AttachCurrentThreadAsDaemon(void **penv, void *args) { 0:02.13 | ^ 0:02.24 1 error generated. 0:02.25 make[4]: *** [APKOpen.o] Error 1 0:02.25 make[3]: *** [mozglue/android/target-objects] Error 2 0:02.25 make[3]: *** Waiting for unfinished jobs.... 0:03.52 make[2]: *** [compile] Error 2 0:03.52 make[1]: *** [default] Error 2 0:03.52 make: *** [build] Error 2 0:03.62 W 82 compiler warnings present.
- The error message implied version-mismatch. Checked the current default java location and version.
$ java --version openjdk 23.0.2 2025-01-21 OpenJDK Runtime Environment Homebrew (build 23.0.2) OpenJDK 64-Bit Server VM Homebrew (build 23.0.2, mixed mode, sharing) $ which java /opt/homebrew/opt/openjdk/bin/java
- Confirmed that Android Studio used the jbr runtime for Gradle. This runtime had another version.
$ /Applications/Android\ Studio.app/Contents/jbr/Contents/Home/bin/java --version openjdk 21.0.4 2024-07-16 OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1) OpenJDK 64-Bit Server VM (build 21.0.4+-12422083-b607.1, mixed mode)
- Seemed like better to use the jbr one. idk. Anyway set it to the fenix build setting.(ref: https://firefox-source-docs.mozilla.org/mobile/android/fenix.html#building-firefox-for-android)
$ export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home $ printenv JAVA_HOME /Applications/Android Studio.app/Contents/jbr/Contents/Home
- Tried again. But the same.
$ ./mach clobber # reset build $ ./mach build # same error
- Searching bugzilla, found the issue about JDK version: https://bugzilla.mozilla.org/show_bug.cgi?id=1785929
- Installed JDK 17 and set it to the setting. Same error.
$ brew install openjdk@17 $ /opt/homebrew/opt/openjdk@17/bin/java --version openjdk 17.0.14 2025-01-21 OpenJDK Runtime Environment Homebrew (build 17.0.14+0) OpenJDK 64-Bit Server VM Homebrew (build 17.0.14+0, mixed mode, sharing) $ export JAVA_HOME=/opt/homebrew/opt/openjdk@17 $ printenv JAVA_HOME /opt/homebrew/opt/openjdk@17 $ ./mach clobber # reset build $ ./mach build ........ 0:02.01 /Users/XXXXXX/mozilla-unified/mozglue/android/APKOpen.cpp:114:44: error: cannot initialize a parameter of type 'void **' with an rvalue of type 'JNIEnv **' (aka 'JNIEnv_ **') 0:02.01 114 | sJavaVM->AttachCurrentThreadAsDaemon(&env, nullptr) != JNI_OK) { 0:02.01 | ^~~~ 0:02.01 /opt/homebrew/opt/openjdk/include/jni.h:1959:45: note: passing argument to parameter 'penv' here 0:02.01 1959 | jint AttachCurrentThreadAsDaemon(void **penv, void *args) { 0:02.01 | ^ 0:02.16 1 error generated. 0:02.17 make[4]: *** [APKOpen.o] Error 1 0:02.17 make[3]: *** [mozglue/android/target-objects] Error 2 0:02.17 make[3]: *** Waiting for unfinished jobs.... 0:03.31 make[2]: *** [compile] Error 2 0:03.31 make[1]: *** [default] Error 2 0:03.31 make: *** [build] Error 2 0:03.42 W 82 compiler warnings present.
- The error said 0:02.01 /opt/homebrew/opt/openjdk/include/jni.h:1959:45: note: passing argument to parameter 'penv' here. Clearly the version was not switched.
- To switch JDK versions, OSX uses /usr/libexec/java_home but my mac can't perform it. Google told me I had to set a symbolic link if I installed jdk by homebrew: https://formulae.brew.sh/formula/openjdk
$ /usr/libexec/java_home -V The operation couldn’t be completed. Unable to locate a Java Runtime. Please visit http://www.java.com for information on installing Java. $ sudo ln -sfn $(brew --prefix)/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk $ /usr/libexec/java_home -V Matching Java Virtual Machines (1): 23.0.2 (arm64) "Homebrew" - "OpenJDK 23.0.2" /opt/homebrew/Cellar/openjdk/23.0.2/libexec/openjdk.jdk/Contents/Home /opt/homebrew/Cellar/openjdk/23.0.2/libexec/openjdk.jdk/Contents/Home
- Added 17, too. (idk i should've added jbr also.)
# you have to add "-17" at last! # https://engineering.mobalab.net/2022/06/06/how-to-install-java-on-macos-in-2022/ $ sudo ln -sfn $(brew --prefix)/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk $ /usr/libexec/java_home -V Matching Java Virtual Machines (2): 23.0.2 (arm64) "Homebrew" - "OpenJDK 23.0.2" /opt/homebrew/Cellar/openjdk/23.0.2/libexec/openjdk.jdk/Contents/Home 17.0.14 (arm64) "Homebrew" - "OpenJDK 17.0.14" /opt/homebrew/Cellar/openjdk@17/17.0.14/libexec/openjdk.jdk/Contents/Home /opt/homebrew/Cellar/openjdk/23.0.2/libexec/openjdk.jdk/Contents/Home
- But switching doesn't succeed. PATH was not set appropriately. Specifically, export PATH="/opt/homebrew/opt/openjdk/bin:$PATH" was a problem. This prenveted switching. So commented it out and wrote aliases.
// .zshrc // # comment out these two. # export PATH="/opt/homebrew/opt/openjdk/bin:$PATH" # export CPPFLAGS="-I/opt/homebrew/opt/openjdk/include" alias setjdk17='export JAVA_HOME=$(/usr/libexec/java_home -v 17.0.14); export CPPFLAGS="-I$JAVA_HOME/include"' alias setjdk23='export JAVA_HOME=$(/usr/libexec/java_home -v 23.0.2); export CPPFLAGS="-I$JAVA_HOME/include"'
- Now switching worked.
$ java --version openjdk 23.0.2 2025-01-21 OpenJDK Runtime Environment Homebrew (build 23.0.2) OpenJDK 64-Bit Server VM Homebrew (build 23.0.2, mixed mode, sharing) $ setjdk17 $ java --version openjdk 17.0.14 2025-01-21 OpenJDK Runtime Environment Homebrew (build 17.0.14+0) OpenJDK 64-Bit Server VM Homebrew (build 17.0.14+0, mixed mode, sharing) $ echo $CPPFLAGS -I/opt/homebrew/Cellar/openjdk@17/17.0.14/libexec/openjdk.jdk/Contents/Home/include $ setjdk23 $ java --version openjdk 23.0.2 2025-01-21 OpenJDK Runtime Environment Homebrew (build 23.0.2) OpenJDK 64-Bit Server VM Homebrew (build 23.0.2, mixed mode, sharing) $ echo $CPPFLAGS -I/opt/homebrew/Cellar/openjdk/23.0.2/libexec/openjdk.jdk/Contents/Home/include
- Finally, built Fenix with jdk17. But it caused another error.
$ ./mach clobber $ setjdk17 $ java --version openjdk 17.0.14 2025-01-21 OpenJDK Runtime Environment Homebrew (build 17.0.14+0) OpenJDK 64-Bit Server VM Homebrew (build 17.0.14+0, mixed mode, sharing) $ ./mach build ...bluh bluh... /opt/homebrew/Cellar/openjdk@17/17.0.14/libexec/openjdk.jdk/Contents/Home/include/jni.h:45:10: fatal error: 'jni_md.h' file not found
- I set CPPFLAGS back to /opt/homebrew/opt/openjdk/include. But it caused the error, again.
- Finally, I tried the below. And under these settings, the build succeeded!
$ echo $JAVA_HOME /Users/XXXXXX/.mozbuild/jdk/jdk-17.0.14+7/Contents/Home $ echo $ANDROID_HOME /Users/XXXXXX/.mozbuild/android-sdk-macosx $ echo $CPPFLAGS $ java --version openjdk 17.0.14 2025-01-21 OpenJDK Runtime Environment Temurin-17.0.14+7 (build 17.0.14+7) OpenJDK 64-Bit Server VM Temurin-17.0.14+7 (build 17.0.14+7, mixed mode, sharing) $ cat mozconfig # Build GeckoView/Firefox for Android: ac_add_options --enable-project=mobile/android # If --target is not specified it will default to host architecture for fast # emulation (x86_64 or aarch64). For testing on physical phones you most likely # want to use an aarch64 (ARM64) target. # ac_add_options --target=aarch64