init
authorJulien Moutinho <julm+android@sourcephile.fr>
Tue, 8 Apr 2025 09:50:06 +0000 (11:50 +0200)
committerJulien Moutinho <julm+android@sourcephile.fr>
Tue, 8 Apr 2025 10:14:01 +0000 (12:14 +0200)
.envrc [new file with mode: 0644]
.gitignore [new file with mode: 0644]
flake.lock [new file with mode: 0644]
flake.nix [new file with mode: 0644]

diff --git a/.envrc b/.envrc
new file mode 100644 (file)
index 0000000..3550a30
--- /dev/null
+++ b/.envrc
@@ -0,0 +1 @@
+use flake
diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..ee1fb53
--- /dev/null
@@ -0,0 +1,2 @@
+core
+result
diff --git a/flake.lock b/flake.lock
new file mode 100644 (file)
index 0000000..b424b9c
--- /dev/null
@@ -0,0 +1,61 @@
+{
+  "nodes": {
+    "flake-utils": {
+      "inputs": {
+        "systems": "systems"
+      },
+      "locked": {
+        "lastModified": 1731533236,
+        "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "type": "github"
+      }
+    },
+    "nixpkgs": {
+      "locked": {
+        "lastModified": 1743938762,
+        "narHash": "sha256-UgFYn8sGv9B8PoFpUfCa43CjMZBl1x/ShQhRDHBFQdI=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "74a40410369a1c35ee09b8a1abee6f4acbedc059",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixpkgs-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "root": {
+      "inputs": {
+        "flake-utils": "flake-utils",
+        "nixpkgs": "nixpkgs"
+      }
+    },
+    "systems": {
+      "locked": {
+        "lastModified": 1681028828,
+        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+        "owner": "nix-systems",
+        "repo": "default",
+        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-systems",
+        "repo": "default",
+        "type": "github"
+      }
+    }
+  },
+  "root": "root",
+  "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644 (file)
index 0000000..f7355c5
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,147 @@
+{
+  description = "Nix flake to develop for Android";
+  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+  inputs.flake-utils.url = "github:numtide/flake-utils";
+  outputs =
+    inputs:
+    let
+      systems = [
+        "x86_64-linux"
+        "x86_64-darwin"
+        "aarch64-linux"
+        "aarch64-darwin"
+      ];
+    in
+    inputs.flake-utils.lib.eachSystem systems (
+      system:
+      let
+        pkgs = import inputs.nixpkgs {
+          inherit system;
+          config = {
+            android_sdk.accept_license = true;
+            allowUnfreePredicate =
+              pkg:
+              builtins.elem (pkgs.lib.getName pkg) [
+                # ExplanationNote: android-emulate-app (see below) is unfree by transitivity
+                "android-emulate-app"
+                "android-sdk-build-tools"
+                "android-sdk-cmdline-tools"
+                "android-sdk-emulator"
+                "android-sdk-ndk"
+                "android-sdk-platform-tools"
+                "android-sdk-platforms"
+                "android-sdk-tools"
+                "android-studio-stable"
+                "android-sdk-system-image-${androidPlatformVersion}-google_apis-x86_64"
+                "android-sdk-system-image-${androidPlatformVersion}-google_apis-arm64-v8a"
+              ];
+          };
+        };
+        androidPlatformVersion = "34";
+        androidBuildToolsVersion = "34.0.0";
+        androidCmakeVersion = "3.22.1";
+        androidSdkArgs = {
+          cmakeVersions = [ androidCmakeVersion ];
+          platformVersions = [ androidPlatformVersion ];
+          abiVersions = [
+            "arm64-v8a"
+            "armeabi-v7a"
+            "x86_64"
+          ];
+          systemImageTypes = [
+            "google_apis"
+            #"google_apis_playstore"
+          ];
+          platformToolsVersion = "34.0.1";
+          ndkVersions = [ "23.1.7779620" ];
+          buildToolsVersions = [ androidBuildToolsVersion ];
+
+          includeNDK = true;
+          #includeEmulator = true;
+          #includeSystemImages = true;
+          extraLicenses = [
+            "android-sdk-license"
+            #"android-sdk-preview-license"
+            #"android-googletv-license"
+            #"android-sdk-arm-dbt-license"
+            #"google-gdk-license"
+            #"intel-android-extra-license"
+            #"intel-android-sysimage-license"
+            #"mips-android-sysimage-license"
+          ];
+        };
+        androidComposition = pkgs.androidenv.composeAndroidPackages androidSdkArgs;
+        androidEmulateApp =
+          args:
+          pkgs.androidenv.emulateApp (
+            {
+              name = "android-emulate-app";
+              app = null;
+              deviceName = "device";
+              package = "";
+              # ToDo: set this when the emulator will be working
+              # for emulate-android-armeabi-v7a
+              # or emulate-android-arm64-v8a
+              #app = ".";
+              #package = "chat.simplex.app";
+              #activity = "chat.simplex.app.MainActivity";
+
+              sdkExtraArgs = androidSdkArgs // {
+                emulatorVersion = "35.6.2";
+              };
+              platformVersion = androidPlatformVersion;
+              systemImageType = "google_apis";
+
+              # ExplanationNote: workaround `-gpu host` not working
+              # on my Vulkan system.
+              androidEmulatorFlags = "-gpu guest";
+
+              configOptions = {
+                "hw.keyboard" = "yes";
+                # FixMe: Not working for me:
+                # WARNING | emuglConfig_get_vulkan_hardware_gpu: Failed to create vulkan instance error code: -9
+                # See https://issuetracker.google.com/issues/356896486
+                #"hw.gpu.enabled" = "yes";
+              };
+            }
+            // args
+          );
+      in
+      {
+        packages = rec {
+          default = emulate-android-x86_64;
+          emulate-android-x86_64 = androidEmulateApp { abiVersion = "x86_64"; };
+          # FixMe: PANIC: Avd's CPU Architecture 'arm64' is not supported by the QEMU2 emulator on x86_64 host.
+          emulate-android-arm64-v8a = androidEmulateApp { abiVersion = "arm64-v8a"; };
+          # FixMe: Error: Package path is not valid. Valid system image paths are:
+          # null
+          # Note: why is there no valid system image for armeabi-v7a???
+          emulate-android-armeabi-v7a = androidEmulateApp { abiVersion = "armeabi-v7a"; };
+        };
+
+        devShell =
+          let
+            zipAlignPath = "${androidComposition.androidsdk}/libexec/android-sdk/build-tools/${androidBuildToolsVersion}/zipalign";
+          in
+          pkgs.mkShell {
+            buildInputs = [
+              (pkgs.android-studio.withSdk androidComposition.androidsdk)
+              (pkgs.writeShellScriptBin "zipalign" ''exec ${zipAlignPath} "$@"'')
+              androidComposition.androidsdk
+              androidComposition.platform-tools
+              pkgs.gradle
+              pkgs.gradle.jdk
+            ];
+            shellHook = ''
+              # Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT.
+              export ANDROID_SDK_ROOT="${androidComposition.androidsdk}/libexec/android-sdk"
+              export ANDROID_NDK_ROOT="${androidComposition.androidsdk}/libexec/android-sdk/ndk-bundle"
+              export PATH="$(echo "$ANDROID_SDK_ROOT/cmake/${androidCmakeVersion}".*/bin):$PATH"
+
+              # Use the same androidBuildToolsVersion and a statically linked aapt2
+              export GRADLE_OPTS="-Dorg.gradle.project.android.aapt2FromMavenOverride=$ANDROID_SDK_ROOT/build-tools/${androidBuildToolsVersion}/aapt2";
+            '';
+          };
+      }
+    );
+}