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"
37 "android-sdk-system-image-${androidPlatformVersion}-google_apis-armeabi-v7a"
41 androidPlatformVersion = "34";
42 androidBuildToolsVersion = "34.0.0";
43 androidCmakeVersion = "3.22.1";
45 cmakeVersions = [ androidCmakeVersion ];
46 platformVersions = [ androidPlatformVersion ];
54 #"google_apis_playstore"
56 platformToolsVersion = "34.0.1";
57 ndkVersions = [ "23.1.7779620" ];
58 buildToolsVersions = [ androidBuildToolsVersion ];
61 #includeEmulator = true;
62 #includeSystemImages = true;
65 #"android-sdk-preview-license"
66 #"android-googletv-license"
67 #"android-sdk-arm-dbt-license"
69 #"intel-android-extra-license"
70 #"intel-android-sysimage-license"
71 #"mips-android-sysimage-license"
74 androidComposition = pkgs.androidenv.composeAndroidPackages androidSdkArgs;
77 pkgs.androidenv.emulateApp (
79 name = "android-emulate-app";
81 deviceName = "device";
83 # ToDo: set this when the emulator will be working
84 # for emulate-android-armeabi-v7a
85 # or emulate-android-arm64-v8a
87 #package = "chat.simplex.app";
88 #activity = "chat.simplex.app.MainActivity";
90 sdkExtraArgs = androidSdkArgs // {
91 emulatorVersion = "35.6.2";
93 platformVersion = androidPlatformVersion;
94 systemImageType = "google_apis";
96 # ExplanationNote: workaround `-gpu host` not working
97 # on my Vulkan system.
98 androidEmulatorFlags = "-gpu guest";
101 "hw.keyboard" = "yes";
102 # FixMe: Not working for me:
103 # WARNING | emuglConfig_get_vulkan_hardware_gpu: Failed to create vulkan instance error code: -9
104 # See https://issuetracker.google.com/issues/356896486
105 #"hw.gpu.enabled" = "yes";
113 default = emulate-android-x86_64;
114 emulate-android-x86_64 = androidEmulateApp { abiVersion = "x86_64"; };
115 # FixMe: PANIC: Avd's CPU Architecture 'arm64' is not supported by the QEMU2 emulator on x86_64 host.
116 emulate-android-arm64-v8a = androidEmulateApp { abiVersion = "arm64-v8a"; };
117 # FixMe: PANIC: CPU Architecture 'arm' is not supported by the QEMU2 emulator, (the classic engine is deprecated!)
118 # Note: only androidPlatformVersion <= 25 still provide images for this ABI
119 # See nixpkgs/pkgs/development/mobile/androidenv/repo.json
120 emulate-android-armeabi-v7a = androidEmulateApp { abiVersion = "armeabi-v7a"; };
125 zipAlignPath = "${androidComposition.androidsdk}/libexec/android-sdk/build-tools/${androidBuildToolsVersion}/zipalign";
129 (pkgs.android-studio.withSdk androidComposition.androidsdk)
130 (pkgs.writeShellScriptBin "zipalign" ''exec ${zipAlignPath} "$@"'')
131 androidComposition.androidsdk
132 androidComposition.platform-tools
137 # Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT.
138 export ANDROID_SDK_ROOT="${androidComposition.androidsdk}/libexec/android-sdk"
139 export ANDROID_NDK_ROOT="${androidComposition.androidsdk}/libexec/android-sdk/ndk-bundle"
140 export PATH="$(echo "$ANDROID_SDK_ROOT/cmake/${androidCmakeVersion}".*/bin):$PATH"
142 # Use the same androidBuildToolsVersion and a statically linked aapt2
143 export GRADLE_OPTS="-Dorg.gradle.project.android.aapt2FromMavenOverride=$ANDROID_SDK_ROOT/build-tools/${androidBuildToolsVersion}/aapt2";