{android-studio,androidenv}: add withSdk passthru and androidPkgs

Rename androidPkgs_9_0 to androidPkgs, and treat it more like a "full"
androidenv package.
This commit is contained in:
Morgan Jones 2024-05-27 03:15:47 -07:00
parent c375910128
commit 88ef7a8598
No known key found for this signature in database
GPG Key ID: 52BAC54ED447974E
5 changed files with 49 additions and 15 deletions

View File

@ -1,7 +1,7 @@
{ channel, pname, version, sha256Hash }:
{ alsa-lib
, bash
, runtimeShell
, buildFHSEnv
, cacert
, coreutils
@ -214,17 +214,48 @@ let
'')
];
};
in runCommand
drvName
{
startScript = ''
#!${bash}/bin/bash
${fhsEnv}/bin/${drvName}-fhs-env ${androidStudio}/bin/studio.sh "$@"
mkAndroidStudioWrapper = {androidStudio, androidSdk ? null}: runCommand drvName {
startScript = let
hasAndroidSdk = androidSdk != null;
androidSdkRoot = lib.optionalString hasAndroidSdk "${androidSdk}/libexec/android-sdk";
in ''
#!${runtimeShell}
${lib.optionalString hasAndroidSdk ''
echo "=== nixpkgs Android Studio wrapper" >&2
# Default ANDROID_SDK_ROOT to the packaged one, if not provided.
ANDROID_SDK_ROOT="''${ANDROID_SDK_ROOT-${androidSdkRoot}}"
if [ -d "$ANDROID_SDK_ROOT" ]; then
export ANDROID_SDK_ROOT
# Legacy compatibility.
export ANDROID_HOME="$ANDROID_SDK_ROOT"
echo " - ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT" >&2
# See if we can export ANDROID_NDK_ROOT too.
ANDROID_NDK_ROOT="$ANDROID_SDK_ROOT/ndk-bundle"
if [ ! -d "$ANDROID_NDK_ROOT" ]; then
ANDROID_NDK_ROOT="$(ls "$ANDROID_SDK_ROOT/ndk/"* 2>/dev/null | head -n1)"
fi
if [ -d "$ANDROID_NDK_ROOT" ]; then
export ANDROID_NDK_ROOT
echo " - ANDROID_NDK_ROOT=$ANDROID_NDK_ROOT" >&2
else
unset ANDROID_NDK_ROOT
fi
else
unset ANDROID_SDK_ROOT
unset ANDROID_HOME
fi
''}
exec ${fhsEnv}/bin/${drvName}-fhs-env ${androidStudio}/bin/studio.sh "$@"
'';
preferLocalBuild = true;
allowSubstitutes = false;
passthru = {
unwrapped = androidStudio;
withSdk = androidSdk: mkAndroidStudioWrapper { inherit androidStudio androidSdk; };
};
meta = with lib; {
description = "The Official IDE for Android (${channel} channel)";
@ -261,4 +292,5 @@ in runCommand
ln -s ${androidStudio}/bin/studio.png $out/share/pixmaps/${pname}.png
ln -s ${desktopItem}/share/applications $out/share/applications
''
'';
in mkAndroidStudioWrapper { inherit androidStudio; }

View File

@ -11,8 +11,8 @@
, platformVersions ? []
, includeSources ? false
, includeSystemImages ? false
, systemImageTypes ? [ "google_apis_playstore" ]
, abiVersions ? [ "armeabi-v7a" "arm64-v8a" ]
, systemImageTypes ? [ "google_apis" "google_apis_playstore" ]
, abiVersions ? [ "x86" "x86_64" "armeabi-v7a" "arm64-v8a" ]
, cmakeVersions ? [ ]
, includeNDK ? false
, ndkVersion ? "26.3.11579264"

View File

@ -15,9 +15,11 @@ rec {
inherit composeAndroidPackages;
};
androidPkgs_9_0 = composeAndroidPackages {
platformVersions = [ "28" ];
abiVersions = [ "x86" "x86_64"];
androidPkgs = composeAndroidPackages {
platformVersions = [ "28" "29" "30" "31" "32" "33" "34" ];
includeEmulator = true;
includeSystemImages = true;
includeNDK = true;
};
test-suite = pkgs.callPackage ./test-suite.nix {};

View File

@ -52,7 +52,7 @@ stdenv.mkDerivation rec {
cp -r * $out/lib/snapdragon-profiler
makeWrapper "${mono}/bin/mono" $out/bin/snapdragon-profiler \
--add-flags "$out/lib/snapdragon-profiler/SnapdragonProfiler.exe" \
--suffix PATH : ${lib.makeBinPath [ jre androidenv.androidPkgs_9_0.platform-tools coreutils ]} \
--suffix PATH : ${lib.makeBinPath [ jre androidenv.androidPkgs.platform-tools coreutils ]} \
--prefix MONO_GAC_PREFIX : ${gtk-sharp-2_0} \
--suffix LD_LIBRARY_PATH : $(echo $NIX_LDFLAGS | sed 's/ -L/:/g;s/ -rpath /:/g;s/-rpath //') \
--chdir "$out/lib/snapdragon-profiler" # Fixes themes not loading correctly

View File

@ -44,7 +44,7 @@ rustPlatform.buildRustPackage rec {
postInstall = ''
wrapProgram $out/bin/gnirehtet \
--set GNIREHTET_APK ${apk}/gnirehtet.apk \
--set ADB ${androidenv.androidPkgs_9_0.platform-tools}/bin/adb
--set ADB ${androidenv.androidPkgs.platform-tools}/bin/adb
'';
meta = with lib; {