Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autoPatchelf to postUnpack in various packages #104

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HPRIOR
Copy link

@HPRIOR HPRIOR commented Jun 16, 2024

In response to #103, I've added autoPathelf $out to various packages. I haven't tested every executable, except for cmake in pkgs/android/prebuilt.nix.

In this case, when 'bringing cmake-3-22-1 into' the flake without applying autoPatchelf $out:

flake.nix
{
  description = "My Android project";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    devshell.url = "github:numtide/devshell";
    flake-utils.url = "github:numtide/flake-utils";
    android.url = "path:/home/harryp/Code/android-nixpkgs-fork";
  };

  outputs = { self, nixpkgs, devshell, flake-utils, android }:
    {
      overlay = final: prev: {
        inherit (self.packages.${final.system}) android-sdk android-studio;
      };
    }
    //
    flake-utils.lib.eachSystem [ "aarch64-darwin" "x86_64-darwin" "x86_64-linux" ] (system:
      let
        inherit (nixpkgs) lib;
        pkgs = import nixpkgs {
          inherit system;
          config.allowUnfree = true;
          overlays = [
            devshell.overlays.default
            self.overlay
          ];
        };
        defaultBuildToolsVersion = "34.0.0";
      in
      {
        packages = {
          android-sdk = android.sdk.${system} (sdkPkgs: with sdkPkgs; [
            build-tools-34-0-0
            cmdline-tools-latest
            emulator
            platform-tools
            platforms-android-34
            cmake-3-22-1 # <------- Here ---------
            ndk-26-1-10909125
          ]
          ++ lib.optionals (system == "aarch64-darwin") [
            system-images-android-34-google-apis-arm64-v8a
          ]
          ++ lib.optionals (system == "x86_64-darwin" || system == "x86_64-linux") [
            system-images-android-34-google-apis-x86-64
          ]);
        } // lib.optionalAttrs (system == "x86_64-linux") {
          android-studio = pkgs.androidStudioPackages.stable;
        };
        devShell = import ./devshell.nix { inherit pkgs; defaultBuildToolsVersion = defaultBuildToolsVersion; };
      }
    );
}

(Still new to nix and android so not sure exactly what happens when I specify cmake-3-22-1 in the sdk.system argument)

This causes the react native expo build commands to fail:

> Task :expo-modules-core:configureCMakeDebug[arm64-v8a] FAILED
C/C++: Could not start dynamically linked executable: /nix/store/gx3vflzrb8qmbzfdfhlfbvzlqwsywq60-android-sdk-env/share/android-sdk/cmake/3.22.1/bin/cmake
C/C++: NixOS cannot run dynamically linked executables intended for generic
C/C++: linux environments out of the box. For more information, see:
C/C++: https://nix.dev/permalink/stub-ld

Full expo commands to reproduce the expo cmake error:

npx create-expo-app@latest

# Say yes to everything with default `my-app` application name.

cd my-app

npx expo install expo-dev-client

npx expo run:android

# You may also need to create an android virtual device with

avdmanager create avd -n android-avd-test -k "system-images;android-34;google_apis;x86_64"
devshell.nix
{ pkgs, defaultBuildToolsVersion }:
with pkgs; let
  # android-studio is not available in aarch64-darwin
  conditionalPackages =
    if pkgs.system != "aarch64-darwin"
    then [android-studio]
    else [];

  avdRoot = "$PWD/.android/avd";
in
  with pkgs;
    devshell.mkShell {
      name = "android-project";
      motd = ''
        Entered the Android app development environment.
      '';
      env = [
        {
          name = "ANDROID_HOME";
          value = "${android-sdk}/share/android-sdk";
        }
        {
          name = "ANDROID_SDK_ROOT";
          value = "${android-sdk}/share/android-sdk";
        }
        {
          name = "JAVA_HOME";
          value = openjdk17.home;
        }
        {
          name = "GRADLE_HOME";
          value = "${gradle}/bin";
        }
        {
          name = "GRADLE_OPTS";
          value = "-Dorg.gradle.java.home=${openjdk17.home} -Dorg.gradle.project.android.aapt2FromMavenOverride=${android-sdk}/share/android-sdk/build-tools/${defaultBuildToolsVersion}/aapt2";
        }
      ];
      packages =
        [
          android-sdk
          gradle
          openjdk17
          cmake
          # expo
          watchman
          nodejs_22
          ninja
        ]
        ++ conditionalPackages;

      devshell.startup.avdroot.text = ''
        echo "Creating android avd root as ${avdRoot}"
        mkdir -p "${avdRoot}"

        echo "Exporting ANDROID_AVD_HOME"
        export ANDROID_AVD_HOME="${avdRoot}"
      '';
    }

After running autoPatchelf $out I am able to run the expo commands and create a dev environment with an emulator

@Andreas02-dev
Copy link

@HPRIOR @tadfisher

Is anything holding this PR back from being merged? I'm facing the same issue with a clean Flutter 3.22 Android project in combination with Java 21 and Gradle 8.5.
Setting my flake input to the commit of this PR (url = "github:tadfisher/android-nixpkgs/516bd59") fixes this for me.

@HPRIOR
Copy link
Author

HPRIOR commented Jul 30, 2024

@HPRIOR @tadfisher

Is anything holding this PR back from being merged? I'm facing the same issue with a clean Flutter 3.22 Android project in combination with Java 21 and Gradle 8.5. Setting my flake input to the commit of this PR (url = "github:tadfisher/android-nixpkgs/516bd59") fixes this for me.

@tadfisher Any chance of a review?

@fdietze
Copy link

fdietze commented Nov 12, 2024

A workaround to get going on NixOS systems: https://github.com/nix-community/nix-ld

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants