2020-05-07 10:21:39 +00:00
|
|
|
# This is the Android Asset Packaging Tool(AAPT2).
|
|
|
|
# It is used by Gradle to package Android app resources.
|
|
|
|
# See: https://developer.android.com/studio/command-line/aapt2
|
|
|
|
|
2022-05-26 09:11:34 +00:00
|
|
|
{ lib, stdenv, pkgs, fetchurl }:
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
let
|
2023-06-14 01:47:41 +00:00
|
|
|
inherit (lib) getAttr;
|
2020-05-07 10:21:39 +00:00
|
|
|
inherit (stdenv) isLinux isDarwin;
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
pname = "aapt2";
|
|
|
|
# Warning: This must be the same as gradlePluginVersion android/gradle.properties
|
2024-03-22 14:21:44 +00:00
|
|
|
version = "8.1.1-10154469";
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
pkgPath = "com/android/tools/build/aapt2";
|
|
|
|
repoUrl = "https://dl.google.com/dl/android/maven2";
|
|
|
|
|
2020-05-07 10:21:39 +00:00
|
|
|
platform =
|
|
|
|
if isLinux then "linux" else
|
|
|
|
if isDarwin then "osx" else
|
|
|
|
throw "Unknown platform!";
|
|
|
|
|
2020-05-07 10:21:39 +00:00
|
|
|
filenames = {
|
2020-05-07 10:21:39 +00:00
|
|
|
jar = "${pname}-${version}-${platform}.jar";
|
2020-05-07 10:21:39 +00:00
|
|
|
pom = "${pname}-${version}.pom";
|
|
|
|
};
|
|
|
|
|
|
|
|
urls = {
|
|
|
|
jar = fetchurl {
|
|
|
|
url = "${repoUrl}/${pkgPath}/${version}/${filenames.jar}";
|
2020-05-07 10:21:39 +00:00
|
|
|
sha256 = getAttr platform {
|
2024-03-22 14:21:44 +00:00
|
|
|
linux = "sha256-p54GGvEfAo0yk8euVO7QTu/c3zuityZhyGdhFSV6w+E=";
|
|
|
|
osx = "sha256-bO4ljdUEfbuns7EyT1FKGLqNGz+0bms5XsplXvzD2T0=";
|
2020-05-07 10:21:39 +00:00
|
|
|
};
|
2020-05-07 10:21:39 +00:00
|
|
|
};
|
|
|
|
sha = fetchurl {
|
|
|
|
url = "${repoUrl}/${pkgPath}/${version}/${filenames.jar}.sha1";
|
2020-05-07 10:21:39 +00:00
|
|
|
sha256 = getAttr platform {
|
2024-03-22 14:21:44 +00:00
|
|
|
linux = "sha256-oUJOQ9j/sJ7Yt0V9WOrRmuqYI+2UWZxeefJ/WyNoWgw=";
|
|
|
|
osx = "sha256-w+q2j4MKtIOihPMaJxuIP9IwXvRIyBxgRIJLox4E7ac=";
|
2020-05-07 10:21:39 +00:00
|
|
|
};
|
2020-05-07 10:21:39 +00:00
|
|
|
};
|
|
|
|
pom = fetchurl {
|
|
|
|
url = "${repoUrl}/${pkgPath}/${version}/${filenames.pom}";
|
2024-03-22 14:21:44 +00:00
|
|
|
sha256 = "sha256-UdUGCoMmEfJxBS2demYKGdG4lzd2DqQbDUCHt/h7Ohg=";
|
2020-05-07 10:21:39 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in stdenv.mkDerivation {
|
|
|
|
inherit pname version;
|
|
|
|
|
|
|
|
srcs = with urls; [ jar sha pom ];
|
2023-06-14 01:47:41 +00:00
|
|
|
# patchelf is Linux specific and won't work on Darwin Platform
|
|
|
|
phases = if isDarwin then ["unpackPhase"] else ["unpackPhase" "patchPhase" "installPhase"];
|
2022-05-26 09:11:34 +00:00
|
|
|
buildInputs = with pkgs; [ zip unzip patchelf ];
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
unpackPhase = ''
|
|
|
|
mkdir -p $out
|
|
|
|
for src in $srcs; do
|
2020-05-07 10:21:39 +00:00
|
|
|
filename=$(stripHash $src)
|
|
|
|
cp $src $out/$filename
|
2020-05-07 10:21:39 +00:00
|
|
|
done
|
2023-06-14 01:47:41 +00:00
|
|
|
tmpDir=$(mktemp -d)
|
|
|
|
unzip $out/${filenames.jar} -d $tmpDir
|
2020-05-07 10:21:39 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
# On Linux, we need to patch the interpreter in Java packages
|
|
|
|
# that contain native executables to use Nix's interpreter instead.
|
|
|
|
patchPhase = ''
|
|
|
|
# Patch executables from maven dependency to use Nix's interpreter
|
2023-06-14 01:47:41 +00:00
|
|
|
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $tmpDir/aapt2
|
|
|
|
'';
|
2020-05-07 10:21:39 +00:00
|
|
|
|
2023-06-14 01:47:41 +00:00
|
|
|
# Rebuild the .jar file with patched binaries
|
|
|
|
installPhase = ''
|
2020-05-07 10:21:39 +00:00
|
|
|
pushd $tmpDir > /dev/null
|
|
|
|
chmod u+w $out/${filenames.jar}
|
2022-05-26 09:11:34 +00:00
|
|
|
zip -fr $out/${filenames.jar}
|
2020-05-07 10:21:39 +00:00
|
|
|
chmod $out/${filenames.jar} --reference=$out/${filenames.jar}.sha1
|
|
|
|
popd > /dev/null
|
|
|
|
'';
|
|
|
|
}
|