we use the path the JDK path `/usr/lib/jvm/java-11-openjdk-amd64` in this doc. Use what ever is on your system, in some cases the arch is dropped and it's `/usr/lib/jvm/java-11-openjdk`. Also this has been tested with and works with `/usr/lib/jvm/java-17-openjdk-amd64` as well. For Mac (if using homebrew) its `/opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk/Contents/Home/` for arm64 and `/usr/local/Cellar/openjdk@11/11.0.21/libexec/openjdk.jdk/Contents/Home` for x86_64.
we use the path the JDK path `/usr/lib/jvm/java-11-openjdk-amd64` in this doc. Use what ever is on your system, in some cases the arch is dropped and it's `/usr/lib/jvm/java-11-openjdk`. Also this has been tested with and works with `/usr/lib/jvm/java-17-openjdk-amd64` as well.
## Prepping Tools (skip this section for mac, we get our clang via Android Studio)
## Prepping Tools
Get a copy of [tor-browser-build](http://eweiibe6tdjsdprb4px6rqrzzcsi22m4koia44kc5pcjr7nec2rlxyad.onion/tpo/applications/tor-browser-build/) and checkout the branch that matches your build target
Get a copy of [tor-browser-build](https://gitlab.torproject.org/tpo/applications/tor-browser-build/) and checkout the branch that matches your build target
*(2023.07.13: for 115.x.0-13.0 we still need [pierov:bug_40855_android](http://eweiibe6tdjsdprb4px6rqrzzcsi22m4koia44kc5pcjr7nec2rlxyad.onion/pierov/tor-browser-build/-/tree/bug_40855_android?ref_type=heads) please delete once merged to tbb propper)*
*(2023.07.13: for 115.x.0-13.0 we still need [pierov:bug_40855_android](https://gitlab.torproject.org/pierov/tor-browser-build/-/tree/bug_40855_android?ref_type=heads) please delete once merged to tbb propper)*
We need to build a clang compiler for our target, aarch64, and we need a few armv7 tools for packaging. The compiler we will use is `clang` and we also need a few extras found in `llvm-runtimes`
...
...
@@ -33,14 +33,12 @@ And now both arm7 and aarch64 llvm-runtimes are installed in your clang and it's
Geckoview is the core browser engine. It will be compiled for android and prepared for packaging in an android browser.
clone a copy of [tor-browser](http://eweiibe6tdjsdprb4px6rqrzzcsi22m4koia44kc5pcjr7nec2rlxyad.onion/tpo/applications/tor-browser) and check out the relevant branch (eg: tor-browser-115.2.1-13.5-1)
clone a copy of [tor-browser](https://gitlab.torproject.org/tpo/applications/tor-browser) and check out the relevant branch (eg: tor-browser-115.0b5-13.0-1)
create an `android-env.sh` and fill it accordingly to your setup with the following
For Linux:
```
export MOZ_BUILD_DATE=20230710165010 # This should match the data in [firefox-android](http://eweiibe6tdjsdprb4px6rqrzzcsi22m4koia44kc5pcjr7nec2rlxyad.onion/tpo/applications/firefox-android)/android-components/plugins/dependencies/src/main/java/Gecko.kt ~ln 12's def of the variable *version*, the date component
export MOZ_BUILD_DATE=20230601093525 # This should match the data in [firefox-android](https://gitlab.torproject.org/tpo/applications/firefox-android)/android-components/plugins/dependencies/src/main/java/Gecko.kt ~ln 12's def of the variable *version*, the date component
export ANDROID_HOME=$HOME/.mozbuild/android-sdk-linux/ # or $HOME/Android/Sdk/ # Or .../android-toolchain/android-sdk-linux if you extract android-toolchain from tor-browser-build
export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/23.2.8568313/ # for 115esr
...
...
@@ -49,17 +47,6 @@ export LOCAL_DEV_BUILD=1
export PATH=/FULL/PATH/TO/tor-browser-build/out/clang/clang-16.x.y-arm/bin/:$PATH # prepend our newly built and assembled clang to the path so it gets used to build geckoview
```
For Mac: (default is arm64, note the different paths for x86_64). Make sure to download the appropriate NDK's via Android Studio's SDK manager (you can select the specific version by checking the box in the bottom right that says "Show Package Details") 
```
export MOZ_BUILD_DATE=20230710165010 # This should match the data in [firefox-android](http://eweiibe6tdjsdprb4px6rqrzzcsi22m4koia44kc5pcjr7nec2rlxyad.onion/tpo/applications/firefox-android)/android-components/plugins/dependencies/src/main/java/Gecko.kt ~ln 12's def of the variable *version*, the date component
export JAVA_HOME=/opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk/Contents/Home/ # for arm64. Or JAVA_HOME=/usr/local/opt/openjdk@11/libexec/openjdk.jdk/Contents/Home/ for x86_64.
export ANDROID_HOME=$HOME/Library/Android/sdk # or $HOME/.mozbuild/android-sdk-macosx/
export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/23.2.8568313 # will need to download NDK 23.2.8568313 via android studio
export GRADLE_HOME=/opt/homebrew/Cellar/gradle@7/7.6.3 # for arm64 or /usr/local/Cellar/gradle@7/7.6.3 for x86_64. Make sure the version is up to date
export LOCAL_DEV_BUILD=1
export PATH=$ANDROID_HOME/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/bin/:$PATH # prepend android studios latest ndk to the path so it's clang gets used to build geckoview. NDK 25.2.9519653 uses clang 14.0.7, ideally we'd use clang 16 (to be the same as Linux) but that's not an option yet for android studio. NDK 26.1.10909125 uses clang 17.0.2, which we should evaluate with the esr128 migration
```
Make sure that the variables defined are all valid for your setup, and that PATH is now using our newly built clang.
then build (this may take a while depending on your machine, ranging from 10 minutes to over an hour as of 2023)
then build
```
MOZCONFIG=mozconfig-android-aarch64 ./mach build
...
...
@@ -116,7 +103,7 @@ and after all this we should be able to confirm by running `ls ~/.m2/repository
## Building firefox-android
Get a copy of the repo [firefox-android](http://eweiibe6tdjsdprb4px6rqrzzcsi22m4koia44kc5pcjr7nec2rlxyad.onion/tpo/applications/firefox-android) and check out the relevant build branch (eg: firefox-android-115.2.0-13.0-1)
Get a copy of the repo [firefox-android](https://gitlab.torproject.org/tpo/applications/firefox-android) and check out the relevant build branch (eg: firefox-android-115.2.0-13.0-1)
You will also need the artifacts from `tor-android-service` and `tor-onion-proxy-library`.
You will also need to fetch the artifacts from `tor-android-service` and `tor-onion-proxy-library`,
If ever ran an Android build with tor-browser-build, you can use the `fenix/tools/tba-fetch-deps.sh` script.
It assumes `tor-browser-build.git` has been checked out at the same level of `firefox-android.git`, but you can also specify another directory with the `TOR_BROWSER_BUILD` environment variable.
Open `fenix` in android studio and build (`Build > Make Project`).
#### Generating non dev builds (nightly, beta(alpha), release)
As an alternative, you can also build from the command line:
where `$variant` must be one of `Release`, `Beta` or `Nightly` (notice the capital letter to make the result camelCase).
## Running
From Android Studio with `fenix` loaded simply select from the menu `Run > Run 'app'` with an appropriate android device with USB debugging enabled plugged in.
#### Running
Otherwise, you can sign the apks with the same QA key we use for the builds from tor-browser-build with `fenix/tools/tba-sign-devbuilds.sh`.
This binary assumes that you have `tor-browser-build.git` at the same level of `firefox-android.git`, but you can override this with the `TOR_BROWSER_BUILD` environment variable.
### For MacOS:
For quickly building, aligning, signing, and installing (to an emulator or device plugged in) the following is useful. Replace the values for variant and Variant with the variant of your choice. Also point the apksigner to your keystore, see https://developer.android.com/studio/publish/app-signing#generate-key for generating a key.
From Android Studio with `fenix` loaded simply select from the menu `Run > Run 'app'` with an appropriate android device with USB debugging enabled plugged in and you will build and run a dev build.
The last line assumes "Android SDK Build-Tools 34" is installed
If you have built a specific *variant* for firefox-android as shown above, you can sign the apks with the same QA key we use for the builds from tor-browser-build with `fenix/tools/tba-sign-devbuilds.sh`.
This binary assumes that you have `tor-browser-build.git` at the same level of `firefox-android.git`, but you can override this with the `TOR_BROWSER_BUILD` environment variable. Then you can use `adb` to install the package with something like `adb install ./app/build/outputs/apk/fenix/beta/app-fenix-arm64-v8a-beta-signed.apk`