My code
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs = with pkgs.buildPackages; [
cordova
android-tools
sdkmanager
gradle
nodejs
nix-ld
aapt
openjdk
libgcc
patchelf
openjdk17-bootstrap
maven
glibc
zlib
ncurses
stdenv.cc.cc.lib
git
gnupg
curl
unzip
zip
python3
libcxx
];
NIX_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
pkgs.stdenv.cc.cc.lib
pkgs.glibc
pkgs.zlib
pkgs.ncurses
pkgs.openssl
pkgs.libcxx
pkgs.libgcc
];
NIX_LD = "${pkgs.nix-ld}/lib/nix-ld";
shellHook = ''
# Export NIX_LD for dynamically linked binaries
export NIX_LD=${pkgs.nix-ld}/lib/nix-ld
export LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH:$LD_LIBRARY_PATH
# Set up Android SDK environment
export ANDROID_HOME=~/Android/Sdk
export PATH=$ANDROID_HOME/build-tools/34.0.0:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin:$PATH
# Patch Gradle cache and Android SDK binaries for aapt and aapt2
echo "Patching aapt and aapt2 binaries in Gradle cache and Android SDK..."
# Patch Gradle cache
find ~/.gradle/caches -name 'aapt*linux*' -type f -exec sh -c '
for binary; do
if file "$binary" | grep -q "ELF"; then
echo "Patching $binary"
patchelf --set-interpreter $(patchelf --print-interpreter $(which find)) "$binary" || true
patchelf --set-rpath "$(nix eval --raw nixpkgs#glibc.outPath)/lib:$(nix eval --raw nixpkgs#zlib.outPath)/lib:$(nix eval --raw nixpkgs#libcxx.outPath)/lib" "$binary" || true
else
echo "Skipping non-ELF file: $binary"
fi
done
' sh {} +
# Patch Android SDK
find $ANDROID_HOME/build-tools/34.0.0 -name 'aapt*' -type f -exec sh -c '
for binary; do
if file "$binary" | grep -q "ELF"; then
echo "Patching $binary"
patchelf --set-interpreter $(patchelf --print-interpreter $(which find)) "$binary" || true
patchelf --set-rpath "$(nix eval --raw nixpkgs#glibc.outPath)/lib:$(nix eval --raw nixpkgs#zlib.outPath)/lib:$(nix eval --raw nixpkgs#libcxx.outPath)/lib" "$binary" || true
else
echo "Skipping non-ELF file: $binary"
fi
done
' sh {} +
# Wrap aapt and aapt2 to use nix-ld
export AAPT_WRAPPED="$NIX_LD $ANDROID_HOME/build-tools/34.0.0/aapt"
export AAPT2_WRAPPED="$NIX_LD $ANDROID_HOME/build-tools/34.0.0/aapt2"
alias aapt="$AAPT_WRAPPED"
alias aapt2="$AAPT2_WRAPPED"
# Verify patched binaries
echo "Verifying patched binaries..."
find ~/.gradle/caches -name 'aapt*linux*' -type f -exec sh -c '
for binary; do
if file "$binary" | grep -q "ELF"; then
echo "Checking $binary"
patchelf --print-interpreter "$binary" || true
patchelf --print-rpath "$binary" || true
fi
done
' sh {} +
find $ANDROID_HOME/build-tools/34.0.0 -name 'aapt*' -type f -exec sh -c '
for binary; do
if file "$binary" | grep -q "ELF"; then
echo "Checking $binary"
patchelf --print-interpreter "$binary" || true
patchelf --print-rpath "$binary" || true
fi
done
' sh {} +
echo "Environment setup and binary patching complete."
'';
}
Error is
Configuration on demand is an incubating feature.
AAPT2 aapt2-8.3.0-10880808-linux Daemon #0: Unexpected error output: Could not start dynamically linked executable: /home/userNix/.gradle/caches/transforms-4/5da6d01e5c
c745bfda620b9d39a98894/transformed/aapt2-8.3.0-10880808-linux/aapt2
AAPT2 aapt2-8.3.0-10880808-linux Daemon #0: Unexpected error output: NixOS cannot run dynamically linked executables intended for generic
AAPT2 aapt2-8.3.0-10880808-linux Daemon #0: Unexpected error output: linux environments out of the box. For more information, see:
AAPT2 aapt2-8.3.0-10880808-linux Daemon #0: Unexpected error output: https://nix.dev/permalink/stub-ld
I am really tired so i posted this here.
I am using nixos for the past months.
Any help appreciated
The errors follows with
> Execution failed for AarResourcesCompilerTransform: /home/userNix/.gradle/caches/transforms-4/6d486f63ce68731a24449ba12b1bd56f/transformed/jetified-play-service
s-base-18.3.0.
> AAPT2 aapt2-8.3.0-10880808-linux Daemon #0: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.