Home Explore Blog Models CI



nixpkgs

1st chunk of `doc/languages-frameworks/android.section.md`
82b66f518577b04903b59d23c9a4813cc372b41c63cb71a50000000100000fec
# Android {#android}

The Android build environment provides three major features and a number of
supporting features.

## Using androidenv with Android Studio {#using-androidenv-with-android-studio}

Use the `android-studio-full` attribute for a very complete Android SDK, including system images:

```nix
{ buildInputs = [ android-studio-full ]; }
```

This is identical to:

```nix
{ buildInputs = [ androidStudioPackages.stable.full ]; }
```

Alternatively, you can pass composeAndroidPackages to the `withSdk` passthrough:

```nix
{
  buildInputs = [
    (android-studio.withSdk (androidenv.composeAndroidPackages { includeNDK = true; }).androidsdk)
  ];
}
```

These will export `ANDROID_SDK_ROOT` and `ANDROID_NDK_ROOT` to the SDK and NDK directories
in the specified Android build environment.

## Deploying an Android SDK installation with plugins {#deploying-an-android-sdk-installation-with-plugins}

Alternatively, you can deploy the SDK separately with a desired set of plugins, or subsets of an SDK.

```nix
with import <nixpkgs> { };

let
  androidComposition = androidenv.composeAndroidPackages {
    platformVersions = [
      "34"
      "35"
      "latest"
    ];
    systemImageTypes = [ "google_apis_playstore" ];
    abiVersions = [
      "armeabi-v7a"
      "arm64-v8a"
    ];
    includeNDK = true;
    includeExtras = [ "extras;google;auto" ];
  };
in
androidComposition.androidsdk
```

The above function invocation states that we want an Android SDK with the above
specified plugin versions. By default, most plugins are disabled. Notable
exceptions are the tools, platform-tools and build-tools sub packages.

The following parameters are supported:

* `cmdLineToolsVersion` specifies the version of the `cmdline-tools` package to use.
  It defaults to the latest.
* `toolsVersion`, specifies the version of the `tools` package. Notice `tools` is
  obsolete, and currently only `26.1.1` is available, so there's not a lot of
  options here, however, you can set it as `null` if you don't want it. It defaults
  to the latest.
* `platformToolsVersion` specifies the version of the `platform-tools` plugin.
  It defaults to the latest.
* `buildToolsVersions` specifies the versions of the `build-tools` plugins to
  use. It defaults to the latest.
* `includeEmulator` specifies whether to deploy the emulator package (`false`
  by default). When enabled, the version of the emulator to deploy can be
  specified by setting the `emulatorVersion` parameter. If set to
  `"if-supported"`, it will deploy the emulator if it's supported by the system.
* `includeCmake` specifies whether CMake should be included. It defaults to true
  on x86-64 and Darwin platforms, and also supports `"if-supported"`.
* `cmakeVersions` specifies which CMake versions should be deployed.
  It defaults to the latest.
* `includeNDK` specifies that the Android NDK bundle should be included.
  Defaults to `false` though can be set to `true` or `"if-supported"`.
* `ndkVersions` specifies the NDK versions that we want to use. These are linked
  under the `ndk` directory of the SDK root, and the first is linked under the
  `ndk-bundle` directory. It defaults to the latest.
* `ndkVersion` is equivalent to specifying one entry in `ndkVersions`, and
  `ndkVersions` overrides this parameter if provided.
* `includeExtras` is an array of identifier strings referring to arbitrary
  add-on packages that should be installed. Note that extras may not be compatible
  with all platforms (for example, the Google TV head unit, which does not
  have an aarch64-linux compile).
* `platformVersions` specifies which platform SDK versions should be included.
  It defaults to including only the latest API level, though you can add more.
* `numLatestPlatformVersions` specifies how many of the latest API levels to include,
  if you are using the default for `platformVersions`. It defaults to 1, though you can
  increase this to, for example, 5 to get the last 5 years of Android API packages.
* `minPlatformVersion` and `maxPlatformVersion` take priority over `platformVersions`

Title: Configuring Android SDK and Android Studio with Nix
Summary
This document outlines how to set up the Android build environment using Nix, specifically focusing on `androidenv` and Android Studio. It demonstrates how to achieve a complete Android SDK integration using `android-studio-full` or more customized setups via `android-studio.withSdk` and `androidenv.composeAndroidPackages`, ensuring `ANDROID_SDK_ROOT` and `ANDROID_NDK_ROOT` are correctly exported. The text also details how to deploy a custom Android SDK installation with specific plugins and versions by utilizing `androidenv.composeAndroidPackages`, providing a comprehensive list of parameters for fine-grained control over components like platform versions, system images, ABI versions, NDK, build tools, emulators, and CMake.