lol
1{
2 # To test your changes in androidEnv run `nix-shell android-sdk-with-emulator-shell.nix`
3
4 # If you copy this example out of nixpkgs, use these lines instead of the next.
5 # This example pins nixpkgs: https://nix.dev/tutorials/towards-reproducibility-pinning-nixpkgs.html
6 /*nixpkgsSource ? (builtins.fetchTarball {
7 name = "nixpkgs-20.09";
8 url = "https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz";
9 sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy";
10 }),
11 pkgs ? import nixpkgsSource {
12 config.allowUnfree = true;
13 },
14 */
15
16 # If you want to use the in-tree version of nixpkgs:
17 pkgs ? import ../../../../.. {
18 config.allowUnfree = true;
19 }
20, config ? pkgs.config
21}:
22
23# Copy this file to your Android project.
24let
25 # Declaration of versions for everything. This is useful since these
26 # versions may be used in multiple places in this Nix expression.
27 android = {
28 versions = {
29 cmdLineToolsVersion = "11.0";
30 platformTools = "34.0.5";
31 buildTools = "34.0.0";
32 };
33 platforms = [ "34" ];
34 };
35
36 # If you copy this example out of nixpkgs, something like this will work:
37 /*androidEnvNixpkgs = fetchTarball {
38 name = "androidenv";
39 url = "https://github.com/NixOS/nixpkgs/archive/<fill me in from Git>.tar.gz";
40 sha256 = "<fill me in with nix-prefetch-url --unpack>";
41 };
42
43 androidEnv = pkgs.callPackage "${androidEnvNixpkgs}/pkgs/development/mobile/androidenv" {
44 inherit config pkgs;
45 licenseAccepted = true;
46 };*/
47
48 # Otherwise, just use the in-tree androidenv:
49 androidEnv = pkgs.callPackage ./.. {
50 inherit config pkgs;
51 # You probably need to uncomment below line to express consent.
52 # licenseAccepted = true;
53 };
54
55 sdkArgs = {
56 cmdLineToolsVersion = android.versions.cmdLineToolsVersion;
57 platformToolsVersion = android.versions.platformTools;
58 buildToolsVersions = [ android.versions.buildTools ];
59 platformVersions = android.platforms;
60 includeNDK = false;
61 includeSystemImages = false;
62 includeEmulator = false;
63
64 # Accepting more licenses declaratively:
65 extraLicenses = [
66 # Already accepted for you with the global accept_license = true or
67 # licenseAccepted = true on androidenv.
68 # "android-sdk-license"
69
70 # These aren't, but are useful for more uncommon setups.
71 "android-sdk-preview-license"
72 "android-googletv-license"
73 "android-sdk-arm-dbt-license"
74 "google-gdk-license"
75 "intel-android-extra-license"
76 "intel-android-sysimage-license"
77 "mips-android-sysimage-license"
78 ];
79 };
80
81 androidComposition = androidEnv.composeAndroidPackages sdkArgs;
82 androidSdk = androidComposition.androidsdk;
83 platformTools = androidComposition.platform-tools;
84 jdk = pkgs.jdk;
85in
86pkgs.mkShell rec {
87 name = "androidenv-example-without-emulator-demo";
88 packages = [ androidSdk platformTools jdk pkgs.android-studio ];
89
90 LANG = "C.UTF-8";
91 LC_ALL = "C.UTF-8";
92 JAVA_HOME = jdk.home;
93
94 # Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT.
95 ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
96
97 shellHook = ''
98 # Write out local.properties for Android Studio.
99 cat <<EOF > local.properties
100 # This file was automatically generated by nix-shell.
101 sdk.dir=$ANDROID_SDK_ROOT
102 EOF
103 '';
104
105 passthru.tests = {
106
107 shell-without-emulator-sdkmanager-packages-test = pkgs.runCommand "shell-without-emulator-sdkmanager-packages-test"
108 {
109 nativeBuildInputs = [ androidSdk jdk ];
110 } ''
111 output="$(sdkmanager --list)"
112 installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}')
113 echo "installed_packages_section: ''${installed_packages_section}"
114
115 packages=(
116 "build-tools;34.0.0" "cmdline-tools;11.0" \
117 "patcher;v4" "platform-tools" "platforms;android-34"
118 )
119
120 for package in "''${packages[@]}"; do
121 if [[ ! $installed_packages_section =~ "$package" ]]; then
122 echo "$package package was not installed."
123 exit 1
124 fi
125 done
126
127 touch "$out"
128 '';
129
130 shell-without-emulator-sdkmanager-excluded-packages-test = pkgs.runCommand "shell-without-emulator-sdkmanager-excluded-packages-test"
131 {
132 nativeBuildInputs = [ androidSdk jdk ];
133 } ''
134 output="$(sdkmanager --list)"
135 installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}')
136
137 excluded_packages=(
138 "emulator" "ndk"
139 )
140
141 for package in "''${excluded_packages[@]}"; do
142 if [[ $installed_packages_section =~ "$package" ]]; then
143 echo "$package package was installed, while it was excluded!"
144 exit 1
145 fi
146 done
147
148 touch "$out"
149 '';
150 };
151}
152