2 description = "Nix flake to develop for Android";
3 inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
4 inputs.flake-utils.url = "github:numtide/flake-utils";
15 inputs.flake-utils.lib.eachSystem systems (
18 pkgs = import inputs.nixpkgs {
21 android_sdk.accept_license = true;
22 allowUnfreePredicate =
24 builtins.elem (pkgs.lib.getName pkg) [
25 # ExplanationNote: android-emulate-app (see below) is unfree by transitivity
27 "android-sdk-build-tools"
28 "android-sdk-cmdline-tools"
29 "android-sdk-emulator"
31 "android-sdk-platform-tools"
32 "android-sdk-platforms"
34 "android-studio-stable"
35 "android-sdk-system-image-${androidPlatformVersion}-google_apis-x86_64"
36 "android-sdk-system-image-${androidPlatformVersion}-google_apis-arm64-v8a"
40 androidPlatformVersion = "34";
41 androidBuildToolsVersion = "34.0.0";
42 androidCmakeVersion = "3.22.1";
44 cmakeVersions = [ androidCmakeVersion ];
45 platformVersions = [ androidPlatformVersion ];
53 #"google_apis_playstore"
55 platformToolsVersion = "34.0.1";
56 ndkVersions = [ "23.1.7779620" ];
57 buildToolsVersions = [ androidBuildToolsVersion ];
60 #includeEmulator = true;
61 #includeSystemImages = true;
64 #"android-sdk-preview-license"
65 #"android-googletv-license"
66 #"android-sdk-arm-dbt-license"
68 #"intel-android-extra-license"
69 #"intel-android-sysimage-license"
70 #"mips-android-sysimage-license"
73 androidComposition = pkgs.androidenv.composeAndroidPackages androidSdkArgs;
76 pkgs.androidenv.emulateApp (
78 name = "android-emulate-app";
80 deviceName = "device";
82 # ToDo: set this when the emulator will be working
83 # for emulate-android-armeabi-v7a
84 # or emulate-android-arm64-v8a
86 #package = "chat.simplex.app";
87 #activity = "chat.simplex.app.MainActivity";
89 sdkExtraArgs = androidSdkArgs // {
90 emulatorVersion = "35.6.2";
92 platformVersion = androidPlatformVersion;
93 systemImageType = "google_apis";
95 # ExplanationNote: workaround `-gpu host` not working
96 # on my Vulkan system.
97 androidEmulatorFlags = "-gpu guest";
100 "hw.keyboard" = "yes";
101 # FixMe: Not working for me:
102 # WARNING | emuglConfig_get_vulkan_hardware_gpu: Failed to create vulkan instance error code: -9
103 # See https://issuetracker.google.com/issues/356896486
104 #"hw.gpu.enabled" = "yes";
112 default = emulate-android-x86_64;
113 emulate-android-x86_64 = androidEmulateApp { abiVersion = "x86_64"; };
114 # FixMe: PANIC: Avd's CPU Architecture 'arm64' is not supported by the QEMU2 emulator on x86_64 host.
115 emulate-android-arm64-v8a = androidEmulateApp { abiVersion = "arm64-v8a"; };
116 # FixMe: Error: Package path is not valid. Valid system image paths are:
118 # Note: why is there no valid system image for armeabi-v7a???
119 emulate-android-armeabi-v7a = androidEmulateApp { abiVersion = "armeabi-v7a"; };
124 zipAlignPath = "${androidComposition.androidsdk}/libexec/android-sdk/build-tools/${androidBuildToolsVersion}/zipalign";
128 (pkgs.android-studio.withSdk androidComposition.androidsdk)
129 (pkgs.writeShellScriptBin "zipalign" ''exec ${zipAlignPath} "$@"'')
130 androidComposition.androidsdk
131 androidComposition.platform-tools
136 # Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT.
137 export ANDROID_SDK_ROOT="${androidComposition.androidsdk}/libexec/android-sdk"
138 export ANDROID_NDK_ROOT="${androidComposition.androidsdk}/libexec/android-sdk/ndk-bundle"
139 export PATH="$(echo "$ANDROID_SDK_ROOT/cmake/${androidCmakeVersion}".*/bin):$PATH"
141 # Use the same androidBuildToolsVersion and a statically linked aapt2
142 export GRADLE_OPTS="-Dorg.gradle.project.android.aapt2FromMavenOverride=$ANDROID_SDK_ROOT/build-tools/${androidBuildToolsVersion}/aapt2";