Home Explore Blog CI



nixpkgs

1st chunk of `doc/languages-frameworks/android.section.md`
4876ba3969cd5d4a6b08ebeff4d0b5e8a9f6b05e24ca48a50000000100000fba
# 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` passthru:

```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.

Title: Android Build Environment and SDK Deployment
Summary
The Android build environment offers features and supports using androidenv with Android Studio, including specifying SDK components and plugins. You can deploy a complete Android SDK installation with plugins, or subsets of an SDK, by composing Android packages with customizable options like platform versions, system image types, ABI versions, NDK inclusion, and extras. The configuration supports parameters for specifying versions of cmdline-tools, tools, platform-tools, build-tools, emulator, CMake, NDK, extras, and platform SDK versions.