tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

index.rst (10365B)


      1 Firefox for Android
      2 ===================
      3 .. _firefox_for_android:
      4 
      5 Firefox for Android consists of three layers:
      6 
      7 - GeckoView: This is a library that brings the Gecko API to Android.
      8 
      9 - Android Components: This is a library of reusable browser building blocks.
     10 
     11 - Frontend (Fenix): This refers to the frontend interface.
     12 
     13 All three components can be found in ``mozilla-central``.
     14 To contribute to any of the three, you will need to get set up as a contributor to Firefox.
     15 
     16 Mozilla Central Setup
     17 ---------------------
     18 .. _mozilla-central-setup:
     19 
     20 To set up Mozilla Central, you can follow the general instructions provided in the Mozilla Source Docs:
     21 
     22 - :ref:`Getting Set Up To Work On The Firefox Codebase <Getting Set Up To Work On The Firefox Codebase>`
     23 
     24 Additionally, to set up specifically for mozilla-central, you can refer to the following guide:
     25 
     26 - :ref:`Quick Start Guide for Git Users <contribute_with_git>`
     27 
     28 Bootstrap
     29 ----------
     30 .. _bootstrap-setup:
     31 
     32 Bootstrap configures everything for GeckoView and Fenix (Firefox for Android) development.
     33 
     34 -  Ensure you have ``mozilla-central`` checked out. If this is the first
     35   time you are doing this, it may take some time.
     36 
     37 .. code:: bash
     38 
     39   git checkout central/default
     40 
     41 If you are on a mac, you will need to have the Xcode build tools
     42 installed. You can do this by either `installing
     43 Xcode <https://developer.apple.com/xcode/>`__ or installing only the
     44 tools from the command line by running ``xcode-select --install`` and
     45 following the on screen instructions.
     46 
     47 If you are on a newer mac with an Apple Silicon M2 or M3 processor,
     48 you also need to install rosetta for backwards compatilibilty:
     49 
     50 .. code:: bash
     51 
     52   softwareupdate --install-rosetta
     53 
     54 You will need to ``bootstrap`` for GeckoView/Firefox for Android. The easiest way is to run the following command:
     55 
     56 .. code:: bash
     57 
     58   ./mach --no-interactive bootstrap --application-choice="GeckoView/Firefox for Android"
     59 
     60 .. note::
     61 
     62    - The ``--no-interactive`` argument will make ``bootstrap`` run start to finish without requiring any input from you. It will automatically accept any license agreements.
     63    - The ``--application-choice="GeckoView/Firefox for Android"`` argument is needed when using ``--no-interactive`` so that "bootstrapping" is done for the correct application (instead of the default).
     64 
     65    If you want to make all the selections yourself and/or read through the license agreements, you can simply run:
     66 
     67    .. code:: bash
     68 
     69        ./mach bootstrap
     70 
     71 You should then choose one the following options:
     72 
     73 A- You will not change or debug any C++ code:
     74 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     75 
     76 Choose: ``3. GeckoView/Firefox for Android Artifact Mode``
     77 
     78 Artifact mode downloads pre-built C++ components rather than building them locally, trading bandwidth for time.
     79 (more on Artifact mode)
     80 
     81 B- You intend to change or debug C++ code:
     82 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     83 
     84 Choose: ``4. GeckoView/Firefox for Android``
     85 
     86 This will build GeckoView from scratch, and take more time than the option above.
     87 
     88 Once ``./mach bootstrap`` is complete, it will automatically write the configuration into a new ``mozconfig`` file.
     89 If you already have a ``mozconfig``, mach will instead output a new configuration that you should append to your existing file.
     90 
     91 Build from the command line
     92 ---------------------------
     93 .. _build_from_cmd_line:
     94 
     95 In order to pick up the configuration changes we just made we need to
     96 build from the command line. This will update generated sources, compile
     97 native code, and produce GeckoView AARs and example and test APKs.
     98 
     99 .. code:: bash
    100 
    101   ./mach build
    102 
    103 Build Using Android Studio
    104 --------------------------
    105 .. _build_with_android_studio:
    106 
    107 -  Install `Android
    108   Studio <https://developer.android.com/studio/install>`_.
    109 -  If on Windows, create a JAVA_HOME environment variable
    110   and set it to the path of the Android Studio jbr. With the default installation locations, it is
    111   ``C:\Program Files\Android\Android Studio\jbr``.
    112 -  Choose File->Open from the toolbar
    113 -  Navigate to the root of your ``mozilla-central`` source directory and
    114   click “Open”
    115 -  Click yes if it asks if you want to use the gradle wrapper.
    116 
    117   -  If the gradle sync does not automatically start, select File >
    118      Sync Project with Gradle Files.
    119 
    120 -  Wait for the project to index and gradle to sync. Once synced, the
    121   workspace will reconfigure to display the different projects.
    122 
    123   -  annotations contains custom Java annotations used inside GeckoView
    124   -  app contains geckoview build settings and omnijar. omnijar contains
    125      the parts of Gecko and GeckoView that are not written in Java or Kotlin
    126   -  geckoview is the GeckoView project. Here is all the Java files
    127      related to GeckoView
    128   -  geckoview_example is an example browser built using GeckoView.
    129 
    130 Now you’re set up and ready to go.
    131 
    132 **Important: at this time, building from Android Studio or directly from
    133 Gradle does not (re-)compile native code, including C++ and Rust.** This
    134 means you will need to run ``mach build`` yourself to pick up changes to
    135 native code. `Bug
    136 1509539 <https://bugzilla.mozilla.org/show_bug.cgi?id=1509539>`_ tracks
    137 making Android Studio and Gradle do this automatically.
    138 
    139 If you want set up code formatting for Kotlin, please reference
    140 `IntelliJ IDEA configuration
    141 <https://pinterest.github.io/ktlint/rules/configuration-intellij-idea/>`_.
    142 
    143 Mobile Devices and Emulators
    144 -------------------------------------
    145 
    146 The default mozconfig file, located in the root directory of your ``mozilla-central`` contains
    147 configurations for running mobile test devices in x86, arm64, and x86_64 architectures.
    148 
    149 With the default mozconfig configurations, your machine's architecture should match the test device's
    150 architecture. On newer Macs built on Apple Silicon, the mozconfig will likely not need to be changed
    151 since it runs on arm64 and most mobile devices run on arm64.
    152 
    153 If your machine has a different architecture compared to your physical test device, you should
    154 uncomment the option matching your test device. Usually, this means uncommenting the arm64 option:
    155 
    156 .. code:: bash
    157 
    158   ac_add_options --target=aarch64
    159 
    160 **Note:** When using an emulator, the mozconfig target configuration will most likely need to match
    161 the architecture of your machine.
    162 
    163 Custom AVD
    164 ~~~~~~~~~~
    165 
    166 There are several reasons creating a custom AVD can be required, like e.g. the
    167 default emulator setup might be too old for some tasks, and it might be
    168 required to run some newer versions of the APIs or others.
    169 
    170 Assuming the following environment variables are already set (versions/OS may change):
    171 
    172 .. code:: bash
    173 
    174   JAVA_HOME=$HOME/.mozbuild/jdk/jdk-17.0.12+7
    175   ANDROID_HOME=$HOME/.mozbuild/android-sdk-linux
    176   ANDROID_AVD_HOME=$HOME/.mozbuild/android-device/avd
    177   PATH=$ANDROID_HOME/cmdline-tools/12.0/bin/:$PATH
    178 
    179 You can identify usable packages already installed on your system via
    180 
    181 .. code:: bash
    182 
    183   sdkmanager --list
    184 
    185 It will output list of available and installed packages. Packages of interest
    186 are ``system-images`` and follow the rule ``system-images;android-API;pkg;arch`` where
    187 
    188 -  ``API`` is the `Android API level <https://developer.android.com/tools/releases/platforms>`_
    189 -  ``pkg`` is the set of package installed, e.g., ``default``, ``google_apis``, ``google_apis_playstore``
    190 -  the last one being the emulator architecture and usually stick to ``x86_64``.
    191 
    192 The system image package you will use needs to be installed, so if it is not
    193 already in the list above, please use (in this example it installs the package
    194 for Android 14 (API level 34), ``default`` package and ``x86_64`` arch).
    195 
    196 .. code:: bash
    197 
    198   sdkmanager "system-images;android-34;default;x86_64"
    199 
    200 Then the AVD can be created with:
    201 
    202 .. code:: bash
    203 
    204   avdmanager create avd --name android14-x86_64 --package "system-images;android-34;default;x86_64"
    205 
    206 The name passed in argument can be whatever you want and the package is one of
    207 the installed list.  It is then required to modify entries within
    208 `android_device.py <https://searchfox.org/mozilla-central/rev/d56687458d4e6e8882c4b740e78413a0f0a69d59/testing/mozbase/mozrunner/mozrunner/devices/android_device.py#101-175>`_ to be able to make use of ``mach android-emulator``,
    209 changing the definition to match the name of the AVD created above. Example below:
    210 
    211 .. code:: diff
    212 
    213   diff --git a/testing/mozbase/mozrunner/mozrunner/devices/android_device.py b/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
    214   index 4f883261d45c1..07f91c1ab800e 100644
    215   --- a/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
    216   +++ b/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
    217   @@ -151,7 +151,7 @@ AVD_DICT = {
    218        ),
    219        "x86_64": AvdInfo(
    220            "Android x86_64",
    221   -        "mozemulator-x86_64",
    222   +        "android14-x86_64",
    223            [
    224                "-skip-adb-auth",
    225                "-verbose",
    226 
    227 Once the avd is created, it can be customized by changing the ``config.ini``
    228 file (located under ``$ANDROID_AVD_HOME/<avd-name>.avd/``, e.g.,
    229 ``$HOME/.mozbuild/android-device/avd/android14-x86_64/config.ini`` in the above
    230 example). It is recommended to enable physical keyboard by changing the value
    231 ``hw.keyboard`` to ``yes`` (otherwise only virtual keyboard input will work).
    232 
    233 Custom mozconfig with Android Studio
    234 ------------------------------------
    235 
    236 Out of the box, Android Studio will use the default mozconfig file, normally
    237 located at ``mozconfig`` in the root directory of your ``mozilla-central``
    238 checkout.
    239 
    240 To make Android Studio use a mozconfig in a custom location, you can add the
    241 following to your ``local.properties``:
    242 
    243 ::
    244 
    245   mozilla-central.mozconfig=relative/path/to/mozconfig
    246 
    247 Note that, when running mach from the command line, this value will be ignored,
    248 and the mozconfig from the mach environment will be used instead.
    249 
    250 To override the mozconfig used by mach, you can use the `MOZCONFIG` environment
    251 variable, for example:
    252 
    253 ::
    254 
    255   MOZCONFIG=debug.mozconfig ./mach build
    256 
    257 Project-Specific Instructions
    258 ------------------------------
    259 
    260 Now that you're prepared and set up, you can access specific project instructions below:
    261 
    262 - GeckoView: :ref:`Contributing to GeckoView <Contributing to GeckoView>`
    263 - Android Components: `Mozilla Android Components <https://mozac.org/>`_
    264 - Frontend: :ref:`Building Firefox for Android <Building Firefox for Android>`