2019-06-16 21:59:06 +02:00
|
|
|
{requireFile, autoPatchelfHook, pkgs, pkgs_i686, licenseAccepted ? false}:
|
2018-11-27 20:36:27 +01:00
|
|
|
|
|
|
|
{ toolsVersion ? "25.2.5"
|
2020-03-09 04:22:02 +01:00
|
|
|
, platformToolsVersion ? "29.0.6"
|
2018-11-27 20:36:27 +01:00
|
|
|
, buildToolsVersions ? [ "28.0.3" ]
|
|
|
|
, includeEmulator ? false
|
2020-03-09 01:44:04 +01:00
|
|
|
, emulatorVersion ? "30.0.3"
|
2018-11-27 20:36:27 +01:00
|
|
|
, platformVersions ? []
|
|
|
|
, includeSources ? false
|
|
|
|
, includeDocs ? false
|
|
|
|
, includeSystemImages ? false
|
|
|
|
, systemImageTypes ? [ "default" ]
|
|
|
|
, abiVersions ? [ "armeabi-v7a" ]
|
|
|
|
, lldbVersions ? [ ]
|
|
|
|
, cmakeVersions ? [ ]
|
|
|
|
, includeNDK ? false
|
|
|
|
, ndkVersion ? "18.1.5063045"
|
|
|
|
, useGoogleAPIs ? false
|
|
|
|
, useGoogleTVAddOns ? false
|
|
|
|
, includeExtras ? []
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2019-08-17 10:48:09 +02:00
|
|
|
inherit (pkgs) stdenv lib fetchurl makeWrapper unzip;
|
2018-11-27 20:36:27 +01:00
|
|
|
|
|
|
|
# Determine the Android os identifier from Nix's system identifier
|
|
|
|
os = if stdenv.system == "x86_64-linux" then "linux"
|
|
|
|
else if stdenv.system == "x86_64-darwin" then "macosx"
|
2019-05-09 03:45:33 +02:00
|
|
|
else throw "No Android SDK tarballs are available for system architecture: ${stdenv.system}";
|
2018-11-27 20:36:27 +01:00
|
|
|
|
|
|
|
# Generated Nix packages
|
|
|
|
packages = import ./generated/packages.nix {
|
|
|
|
inherit fetchurl;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Generated system images
|
|
|
|
system-images-packages-android = import ./generated/system-images-android.nix {
|
|
|
|
inherit fetchurl;
|
|
|
|
};
|
|
|
|
|
|
|
|
system-images-packages-android-tv = import ./generated/system-images-android-tv.nix {
|
|
|
|
inherit fetchurl;
|
|
|
|
};
|
|
|
|
|
|
|
|
system-images-packages-android-wear = import ./generated/system-images-android-wear.nix {
|
|
|
|
inherit fetchurl;
|
|
|
|
};
|
|
|
|
|
|
|
|
system-images-packages-android-wear-cn = import ./generated/system-images-android-wear-cn.nix {
|
|
|
|
inherit fetchurl;
|
|
|
|
};
|
|
|
|
|
|
|
|
system-images-packages-google_apis = import ./generated/system-images-google_apis.nix {
|
|
|
|
inherit fetchurl;
|
|
|
|
};
|
|
|
|
|
|
|
|
system-images-packages-google_apis_playstore = import ./generated/system-images-google_apis_playstore.nix {
|
|
|
|
inherit fetchurl;
|
|
|
|
};
|
|
|
|
|
|
|
|
system-images-packages =
|
2019-08-17 10:48:09 +02:00
|
|
|
lib.recursiveUpdate
|
2018-11-27 20:36:27 +01:00
|
|
|
system-images-packages-android
|
2019-08-17 10:48:09 +02:00
|
|
|
(lib.recursiveUpdate system-images-packages-android-tv
|
|
|
|
(lib.recursiveUpdate system-images-packages-android-wear
|
|
|
|
(lib.recursiveUpdate system-images-packages-android-wear-cn
|
|
|
|
(lib.recursiveUpdate system-images-packages-google_apis system-images-packages-google_apis_playstore))));
|
2018-11-27 20:36:27 +01:00
|
|
|
|
|
|
|
# Generated addons
|
|
|
|
addons = import ./generated/addons.nix {
|
|
|
|
inherit fetchurl;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
rec {
|
|
|
|
deployAndroidPackage = import ./deploy-androidpackage.nix {
|
|
|
|
inherit stdenv unzip;
|
|
|
|
};
|
|
|
|
|
|
|
|
platform-tools = import ./platform-tools.nix {
|
2019-08-17 10:48:09 +02:00
|
|
|
inherit deployAndroidPackage os autoPatchelfHook pkgs lib;
|
2019-09-09 01:38:31 +02:00
|
|
|
package = packages.platform-tools.${platformToolsVersion};
|
2018-11-27 20:36:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
build-tools = map (version:
|
|
|
|
import ./build-tools.nix {
|
2019-08-17 10:48:09 +02:00
|
|
|
inherit deployAndroidPackage os autoPatchelfHook makeWrapper pkgs pkgs_i686 lib;
|
2019-09-09 01:38:31 +02:00
|
|
|
package = packages.build-tools.${version};
|
2018-11-27 20:36:27 +01:00
|
|
|
}
|
|
|
|
) buildToolsVersions;
|
|
|
|
|
|
|
|
docs = deployAndroidPackage {
|
|
|
|
inherit os;
|
|
|
|
package = packages.docs."1";
|
|
|
|
};
|
|
|
|
|
|
|
|
emulator = import ./emulator.nix {
|
2019-08-17 10:48:09 +02:00
|
|
|
inherit deployAndroidPackage os autoPatchelfHook makeWrapper pkgs pkgs_i686 lib;
|
2019-09-09 01:38:31 +02:00
|
|
|
package = packages.emulator.${emulatorVersion}.${os};
|
2018-11-27 20:36:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
platforms = map (version:
|
|
|
|
deployAndroidPackage {
|
|
|
|
inherit os;
|
2019-08-13 23:52:01 +02:00
|
|
|
package = packages.platforms.${version};
|
2018-11-27 20:36:27 +01:00
|
|
|
}
|
|
|
|
) platformVersions;
|
|
|
|
|
2018-11-27 22:31:35 +01:00
|
|
|
sources = map (version:
|
2018-11-27 20:36:27 +01:00
|
|
|
deployAndroidPackage {
|
|
|
|
inherit os;
|
2019-08-13 23:52:01 +02:00
|
|
|
package = packages.sources.${version};
|
2018-11-27 20:36:27 +01:00
|
|
|
}
|
2018-11-27 22:31:35 +01:00
|
|
|
) platformVersions;
|
2018-11-27 20:36:27 +01:00
|
|
|
|
2019-08-17 10:48:09 +02:00
|
|
|
system-images = lib.flatten (map (apiVersion:
|
2018-11-27 20:36:27 +01:00
|
|
|
map (type:
|
|
|
|
map (abiVersion:
|
|
|
|
deployAndroidPackage {
|
|
|
|
inherit os;
|
|
|
|
package = system-images-packages.${apiVersion}.${type}.${abiVersion};
|
2019-08-17 10:48:05 +02:00
|
|
|
# Patch 'google_apis' system images so they're recognized by the sdk.
|
|
|
|
# Without this, `android list targets` shows 'Tag/ABIs : no ABIs' instead
|
|
|
|
# of 'Tag/ABIs : google_apis*/*' and the emulator fails with an ABI-related error.
|
2019-08-17 10:48:09 +02:00
|
|
|
patchInstructions = lib.optionalString (lib.hasPrefix "google_apis" type) ''
|
2019-08-17 10:48:05 +02:00
|
|
|
sed -i '/^Addon.Vendor/d' source.properties
|
|
|
|
'';
|
2018-11-27 20:36:27 +01:00
|
|
|
}
|
|
|
|
) abiVersions
|
|
|
|
) systemImageTypes
|
|
|
|
) platformVersions);
|
|
|
|
|
|
|
|
lldb = map (version:
|
|
|
|
import ./lldb.nix {
|
2019-08-17 10:48:09 +02:00
|
|
|
inherit deployAndroidPackage os autoPatchelfHook pkgs lib;
|
2019-09-09 01:38:31 +02:00
|
|
|
package = packages.lldb.${version};
|
2018-11-27 20:36:27 +01:00
|
|
|
}
|
|
|
|
) lldbVersions;
|
|
|
|
|
|
|
|
cmake = map (version:
|
|
|
|
import ./cmake.nix {
|
2019-08-17 10:48:09 +02:00
|
|
|
inherit deployAndroidPackage os autoPatchelfHook pkgs lib;
|
2019-09-09 01:38:31 +02:00
|
|
|
package = packages.cmake.${version};
|
2018-11-27 20:36:27 +01:00
|
|
|
}
|
|
|
|
) cmakeVersions;
|
|
|
|
|
|
|
|
ndk-bundle = import ./ndk-bundle {
|
2019-08-17 10:48:09 +02:00
|
|
|
inherit deployAndroidPackage os autoPatchelfHook makeWrapper pkgs lib platform-tools;
|
2019-09-09 01:38:31 +02:00
|
|
|
package = packages.ndk-bundle.${ndkVersion};
|
2018-11-27 20:36:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
google-apis = map (version:
|
|
|
|
deployAndroidPackage {
|
|
|
|
inherit os;
|
2019-08-13 23:52:01 +02:00
|
|
|
package = addons.addons.${version}.google_apis;
|
2018-11-27 20:36:27 +01:00
|
|
|
}
|
|
|
|
) (builtins.filter (platformVersion: platformVersion < "26") platformVersions); # API level 26 and higher include Google APIs by default
|
|
|
|
|
|
|
|
google-tv-addons = map (version:
|
|
|
|
deployAndroidPackage {
|
|
|
|
inherit os;
|
2019-08-13 23:52:01 +02:00
|
|
|
package = addons.addons.${version}.google_tv_addon;
|
2018-11-27 20:36:27 +01:00
|
|
|
}
|
|
|
|
) platformVersions;
|
|
|
|
|
|
|
|
# Function that automatically links all plugins for which multiple versions can coexist
|
|
|
|
linkPlugins = {name, plugins}:
|
2019-08-17 10:48:09 +02:00
|
|
|
lib.optionalString (plugins != []) ''
|
2018-11-27 20:36:27 +01:00
|
|
|
mkdir -p ${name}
|
2019-08-17 10:48:09 +02:00
|
|
|
${lib.concatMapStrings (plugin: ''
|
2018-11-27 20:36:27 +01:00
|
|
|
ln -s ${plugin}/libexec/android-sdk/${name}/* ${name}
|
|
|
|
'') plugins}
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Function that automatically links a plugin for which only one version exists
|
|
|
|
linkPlugin = {name, plugin, check ? true}:
|
2019-08-17 10:48:09 +02:00
|
|
|
lib.optionalString check ''
|
2018-11-27 20:36:27 +01:00
|
|
|
ln -s ${plugin}/libexec/android-sdk/* ${name}
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Links all plugins related to a requested platform
|
|
|
|
linkPlatformPlugins = {name, plugins, check}:
|
2019-08-17 10:48:09 +02:00
|
|
|
lib.optionalString check ''
|
2018-11-27 20:36:27 +01:00
|
|
|
mkdir -p ${name}
|
2019-08-17 10:48:09 +02:00
|
|
|
${lib.concatMapStrings (plugin: ''
|
2018-11-27 20:36:27 +01:00
|
|
|
ln -s ${plugin}/libexec/android-sdk/${name}/* ${name}
|
|
|
|
'') plugins}
|
|
|
|
''; # */
|
|
|
|
|
|
|
|
# This derivation deploys the tools package and symlinks all the desired
|
|
|
|
# plugins that we want to use.
|
|
|
|
|
2019-01-30 03:13:41 +01:00
|
|
|
androidsdk = if !licenseAccepted then throw ''
|
|
|
|
You must accept the Android Software Development Kit License Agreement at
|
|
|
|
https://developer.android.com/studio/terms
|
|
|
|
by setting nixpkgs config option 'android_sdk.accept_license = true;'
|
|
|
|
'' else import ./tools.nix {
|
2019-08-17 10:48:09 +02:00
|
|
|
inherit deployAndroidPackage requireFile packages toolsVersion autoPatchelfHook makeWrapper os pkgs pkgs_i686 lib;
|
2018-11-27 20:36:27 +01:00
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
# Symlink all requested plugins
|
|
|
|
|
|
|
|
${linkPlugin { name = "platform-tools"; plugin = platform-tools; }}
|
|
|
|
${linkPlugins { name = "build-tools"; plugins = build-tools; }}
|
|
|
|
${linkPlugin { name = "emulator"; plugin = emulator; check = includeEmulator; }}
|
|
|
|
${linkPlugin { name = "docs"; plugin = docs; check = includeDocs; }}
|
|
|
|
${linkPlugins { name = "platforms"; plugins = platforms; }}
|
|
|
|
${linkPlatformPlugins { name = "sources"; plugins = sources; check = includeSources; }}
|
|
|
|
${linkPlugins { name = "lldb"; plugins = lldb; }}
|
|
|
|
${linkPlugins { name = "cmake"; plugins = cmake; }}
|
|
|
|
${linkPlugin { name = "ndk-bundle"; plugin = ndk-bundle; check = includeNDK; }}
|
|
|
|
|
2019-08-17 10:48:09 +02:00
|
|
|
${lib.optionalString includeSystemImages ''
|
2018-11-27 20:36:27 +01:00
|
|
|
mkdir -p system-images
|
2019-08-17 10:48:09 +02:00
|
|
|
${lib.concatMapStrings (system-image: ''
|
2018-11-27 20:36:27 +01:00
|
|
|
apiVersion=$(basename $(echo ${system-image}/libexec/android-sdk/system-images/*))
|
|
|
|
type=$(basename $(echo ${system-image}/libexec/android-sdk/system-images/*/*))
|
|
|
|
mkdir -p system-images/$apiVersion/$type
|
|
|
|
ln -s ${system-image}/libexec/android-sdk/system-images/$apiVersion/$type/* system-images/$apiVersion/$type
|
|
|
|
'') system-images}
|
|
|
|
''}
|
|
|
|
|
|
|
|
${linkPlatformPlugins { name = "add-ons"; plugins = google-apis; check = useGoogleAPIs; }}
|
|
|
|
${linkPlatformPlugins { name = "add-ons"; plugins = google-apis; check = useGoogleTVAddOns; }}
|
|
|
|
|
|
|
|
# Link extras
|
2019-08-17 10:48:09 +02:00
|
|
|
${lib.concatMapStrings (identifier:
|
2018-11-27 20:36:27 +01:00
|
|
|
let
|
2019-08-13 23:52:01 +02:00
|
|
|
path = addons.extras.${identifier}.path;
|
2018-11-27 20:36:27 +01:00
|
|
|
addon = deployAndroidPackage {
|
|
|
|
inherit os;
|
2019-08-13 23:52:01 +02:00
|
|
|
package = addons.extras.${identifier};
|
2018-11-27 20:36:27 +01:00
|
|
|
};
|
|
|
|
in
|
|
|
|
''
|
|
|
|
targetDir=$(dirname ${path})
|
|
|
|
mkdir -p $targetDir
|
|
|
|
ln -s ${addon}/libexec/android-sdk/${path} $targetDir
|
|
|
|
'') includeExtras}
|
|
|
|
|
|
|
|
# Expose common executables in bin/
|
|
|
|
mkdir -p $out/bin
|
|
|
|
find $PWD/tools -not -path '*/\.*' -type f -executable -mindepth 1 -maxdepth 1 | while read i
|
|
|
|
do
|
|
|
|
ln -s $i $out/bin
|
|
|
|
done
|
|
|
|
|
|
|
|
find $PWD/tools/bin -not -path '*/\.*' -type f -executable -mindepth 1 -maxdepth 1 | while read i
|
|
|
|
do
|
|
|
|
ln -s $i $out/bin
|
|
|
|
done
|
|
|
|
|
|
|
|
for i in ${platform-tools}/bin/*
|
|
|
|
do
|
|
|
|
ln -s $i $out/bin
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|