<commit_before>.. Copyright (c) 2018-2019, <NAME>
.. All rights reserved.

.. spelling::

  Gradle
  md

How to use Hunter in Android Studio?
------------------------------------

CMake can be used as a build tool for native C/C++ libraries in Android Studio.
If CMake project has third party dependencies these dependencies can be managed
by Hunter.

Example
=======

As an example let's take a look at a simple project with one tiny
:doc:`md5 package </packages/pkg/md5>` dependency. The project is a slight
modification of the
`HelloJni sample <https://github.com/googlesamples/android-ndk/tree/master/hello-jni>`__.

.. admonition:: Examples on GitHub

  * `Android Studio with Hunter <https://github.com/forexample/android-studio-with-hunter>`__

.. note::

  The code was tested with Android Studio 3.3

Check you have at least CMake 3.9.2. Such a requirement needed to work with
`Android NDK r16+ <https://gitlab.kitware.com/cmake/cmake/issues/17253>`__:

.. code-block:: none
  :emphasize-lines: 1, 3

  > cmake --version

  cmake version 3.9.2

  CMake suite maintained and supported by Kitware (kitware.com/cmake).

Check you have Ninja build tool installed:

.. code-block:: none

  > which ninja
  /usr/bin/ninja

You can use your system package manager
(e.g., on Ubuntu do ``sudo apt-get install ninja-build``)
or download it from GitHub releases, unpack and add to ``PATH``:

* https://github.com/ninja-build/ninja/releases

Get the sources:

.. code-block:: none
  :emphasize-lines: 1

  > git clone https://github.com/forexample/android-studio-with-hunter
  > cd android-studio-with-hunter
  [android-studio-with-hunter]>

Android Studio project configuration files reside in the ``android-studio``
directory but before opening it you have to create the ``local.properties`` file
and add the ``cmake.dir`` entry there.

.. seealso::

  * `Android Studio: Use CMake 3.7 or higher <https://developer.android.com/studio/projects/add-native-code#vanilla_cmake>`__

You may want to add the paths to Android NDK/SDK as well (if ``ndk.dir`` and
``sdk.dir`` not present in ``local.properties`` then they will be set by
Android Studio to default locations):

.. code-block:: none
  :emphasize-lines: 6

  [android-studio-with-hunter]> cd android-studio
  [android-studio-with-hunter/android-studio]> cat local.properties

  ndk.dir=/home/your/path/to/android-sdk/ndk-bundle
  sdk.dir=/home/your/path/to/android-sdk
  cmake.dir=/home/your/path/to/cmake

.. hint::

  Since ``local.properties`` contains information about a local machine
  you should add it to
  `.gitignore <https://github.com/forexample/android-studio-with-hunter/blob/2639b6732a0d4ffe7608839c60911cc3364b4ca0/.gitignore#L20-L21>`__.

.. warning::

  Android NDK r19+ is :ref:`not supported <android ndk r19>`.

Please check that ``cmake.dir`` has such value that ``<cmake.dir>/bin/cmake``
executable exists.

At this moment you can launch Android Studio and open your project but
note that Gradle will start configuring, it will trigger CMake configuration
which will trigger Hunter builds for 3 architectures:

.. code-block:: none
  :emphasize-lines: 11

  [android-studio-with-hunter/android-studio]> cat app/build.gradle

  android {
      ...
      defaultConfig {
          ...
          abi {
              enable true

              reset()
              include 'x86_64', 'armeabi-v7a', 'arm64-v8a'

              universalApk false
          }
      }
      ...
  }

As an alternative, you are able to build one architecture at a
time using ``-Parch=``:<commit_msg>Docs: More details about Android NDK<commit_after>.. Copyright (c) 2018-2019, <NAME>
.. All rights reserved.

.. spelling::

  Gradle
  md

How to use Hunter in Android Studio?
------------------------------------

CMake can be used as a build tool for native C/C++ libraries in Android Studio.
If CMake project has third party dependencies these dependencies can be managed
by Hunter.

Example
=======

As an example let's take a look at a simple project with one tiny
:doc:`md5 package </packages/pkg/md5>` dependency. The project is a slight
modification of the
`HelloJni sample <https://github.com/googlesamples/android-ndk/tree/master/hello-jni>`__.

.. admonition:: Examples on GitHub

  * `Android Studio with Hunter <https://github.com/forexample/android-studio-with-hunter>`__

.. note::

  The code was tested with Android Studio 3.3

Check you have at least CMake 3.9.2. Such a requirement needed to work with
`Android NDK r16+ <https://gitlab.kitware.com/cmake/cmake/issues/17253>`__:

.. code-block:: none
  :emphasize-lines: 1, 3

  > cmake --version

  cmake version 3.9.2

  CMake suite maintained and supported by Kitware (kitware.com/cmake).

Check you have Ninja build tool installed:

.. code-block:: none

  > which ninja
  /usr/bin/ninja

You can use your system package manager
(e.g., on Ubuntu do ``sudo apt-get install ninja-build``)
or download it from GitHub releases, unpack and add to ``PATH``:

* https://github.com/ninja-build/ninja/releases

Get the sources:

.. code-block:: none
  :emphasize-lines: 1

  > git clone https://github.com/forexample/android-studio-with-hunter
  > cd android-studio-with-hunter
  [android-studio-with-hunter]>

Android Studio project configuration files reside in the ``android-studio``
directory but before opening it you have to create the ``local.properties`` file
and add the ``cmake.dir`` entry there.

.. seealso::

  * `Android Studio: Use CMake 3.7 or higher <https://developer.android.com/studio/projects/add-native-code#vanilla_cmake>`__

You may want to add the paths to Android NDK/SDK as well (if ``ndk.dir`` and
``sdk.dir`` not present in ``local.properties`` then they will be set by
Android Studio to default locations):

.. code-block:: none
  :emphasize-lines: 6

  [android-studio-with-hunter]> cd android-studio
  [android-studio-with-hunter/android-studio]> cat local.properties

  ndk.dir=/home/your/path/to/android-sdk/ndk-bundle
  sdk.dir=/home/your/path/to/android-sdk
  cmake.dir=/home/your/path/to/cmake

.. hint::

  Since ``local.properties`` contains information about a local machine
  you should add it to
  `.gitignore <https://github.com/forexample/android-studio-with-hunter/blob/2639b6732a0d4ffe7608839c60911cc3364b4ca0/.gitignore#L20-L21>`__.

.. warning::

  Android NDK r19+ is :ref:`not supported <android ndk r19>`. You **have to**
  switch to a lower version explicitly, e.g. to NDK r18b.

Please check that ``cmake.dir`` has such value that ``<cmake.dir>/bin/cmake``
executable exists.

At this moment you can launch Android Studio and open your project but
note that Gradle will start configuring, it will trigger CMake configuration
which will trigger Hunter builds for 3 architectures:

.. code-block:: none
  :emphasize-lines: 11

  [android-studio-with-hunter/android-studio]> cat app/build.gradle

  android {
      ...
      defaultConfig {
          ...
          abi {
              enable true

              reset()
              include 'x86_64', 'armeabi-v7a', 'arm64-v8a'

              universalApk false
          }
      }
      ...
  }

As an alternative, you are able to build one architecture at a
time using ``-Parch=``:
{'fraction_non_alphanumeric': 0.12269000972627483, 'fraction_numerical': 0.021953591774350422, 'mean_word_length': 3.2142857142857144, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 37, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7630022', 'n_tokens_mistral': 2435, 'n_tokens_neox': 2229, 'n_words': 749}