Created
June 12, 2018 08:44
-
-
Save adisbladis/684b23f6beb2e7dae619ccc5fa172575 to your computer and use it in GitHub Desktop.
Build android applications from nix-shell without FHS env
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with (import <nixpkgs> {}); | |
let | |
# Extract license from a Linux box | |
# It's in ~/Android/Sdk/licenses/android-sdk-license | |
sdkLicense = "d56f5187479451eabf01fb78af6dfcb131a6481e"; | |
in pkgs.mkShell { | |
buildInputs = with pkgs; [ | |
git | |
gitRepo | |
gnupg | |
python2 | |
curl | |
procps | |
openssl | |
gnumake | |
nettools | |
jdk | |
jre | |
schedtool | |
utillinux | |
m4 | |
gperf | |
perl | |
libxml2 | |
zip | |
unzip | |
bison | |
flex | |
lzop | |
# Android | |
gradle | |
androidenv.platformTools | |
]; | |
shellHook = let | |
# Android build tools have a lot of native links | |
# If we are gonna pull them down with gradle we need to | |
# Add extra paths so the dynamic linking works | |
extraRpaths = pkgs.lib.makeLibraryPath (with pkgs; [ | |
libcxx.out | |
zlib.out | |
ncurses5 | |
]); | |
in '' | |
if test -z "$ANDROID_HOME"; then | |
export ANDROID_HOME=$(mktemp -d) | |
fi | |
export USE_CCACHE=1 | |
export ANDROID_JAVA_HOME=${pkgs.jdk.home} | |
# Disable daemon, it's pointless in CI | |
export GRADLE_OPTS="--no-daemon" | |
mkdir -p $ANDROID_HOME/licenses | |
echo ${sdkLicense} > $ANDROID_HOME/licenses/android-sdk-license | |
# List all tasks, this is just to trigger SDK downloading | |
# so we can patchelf right after that | |
gradle --no-daemon tasks > /dev/null | |
# Patch ELF interpreters from hard-coded FHS-paths to hard-coded nix paths | |
find $ANDROID_HOME -executable -type f -not -name '*.*' | while read filename; do | |
p=$(patchelf --print-rpath ''${filename}) | |
${pkgs.patchelf}/bin/patchelf \ | |
--set-interpreter ${pkgs.glibc}/lib/ld-linux-x86-64.so.2 \ | |
--set-rpath "$p:${extraRpaths}" \ | |
''${filename} | |
done | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment