androidenv: support 5 years of Android APIs with images; test 10 without

Cut down on the number of system images that need to be fetched by just
supporting packages from the last 5 years. Still test the last 10 years
of APIs without images.
This commit is contained in:
Morgan Jones 2025-03-29 01:19:05 -07:00 committed by Masum Reza
parent c75818be07
commit 81ac8a7666
4 changed files with 19 additions and 12 deletions

View File

@ -88,6 +88,9 @@ The following parameters are supported:
have an aarch64-linux compile).
* `platformVersions` specifies which platform SDK versions should be included.
It defaults to including only the latest API level, though you can add more.
* `numLatestPlatformVersions` specifies how many of the latest API levels to include,
if you are using the default for `platformVersions`. It defaults to 1, though you can
increase this to, for example, 5 to get the last 5 years of Android API packages.
* `minPlatformVersion` and `maxPlatformVersion` take priority over `platformVersions`
if both are provided. Note that `maxPlatformVersion` always defaults to the latest
Android SDK platform version, allowing you to specify `minPlatformVersion` to describe

View File

@ -82,6 +82,7 @@ in
emulatorVersion ? repo.latest.emulator,
minPlatformVersion ? null,
maxPlatformVersion ? coerceInt repo.latest.platforms,
numLatestPlatformVersions ? 1,
platformVersions ?
if minPlatformVersion != null && maxPlatformVersion != null then
let
@ -92,7 +93,14 @@ in
lib.max minPlatformVersionInt maxPlatformVersionInt
)
else
map coerceInt [ repo.latest.platforms ],
let
minPlatformVersionInt = if minPlatformVersion == null then 1 else coerceInt minPlatformVersion;
latestPlatformVersionInt = lib.max minPlatformVersionInt (coerceInt repo.latest.platforms);
firstPlatformVersionInt = lib.max minPlatformVersionInt (
latestPlatformVersionInt - (lib.max 1 numLatestPlatformVersions) + 1
);
in
lib.range firstPlatformVersionInt latestPlatformVersionInt,
includeSources ? false,
includeSystemImages ? false,
systemImageTypes ? [

View File

@ -18,7 +18,8 @@ lib.recurseIntoAttrs rec {
};
androidPkgs = composeAndroidPackages {
minPlatformVersion = 28;
# Support roughly the last 5 years of Android packages and system images by default in nixpkgs.
numLatestPlatformVersions = 5;
includeEmulator = "if-supported";
includeSystemImages = "if-supported";
includeNDK = "if-supported";

View File

@ -47,12 +47,13 @@ let
androidComposition = androidEnv.composeAndroidPackages {
includeSources = true;
includeSystemImages = true;
includeSystemImages = false;
includeEmulator = "if-supported";
includeNDK = "if-supported";
useGoogleAPIs = true;
minPlatformVersion = 23;
# Make sure everything from the last decade works since we are not using system images.
numLatestPlatformVersions = 10;
# If you want to use a custom repo JSON:
# repoJson = ../repo.json;
@ -100,6 +101,7 @@ let
androidSdk = androidComposition.androidsdk;
platformTools = androidComposition.platform-tools;
firstSdk = pkgs.lib.foldl' pkgs.lib.min 100 androidComposition.platformVersions;
latestSdk = pkgs.lib.foldl' pkgs.lib.max 0 androidComposition.platformVersions;
jdk = pkgs.jdk;
in
@ -171,19 +173,12 @@ pkgs.mkShell rec {
"extras;google;gcm"
)
for x in $(seq 23 ${toString latestSdk}); do
for x in $(seq ${toString firstSdk} ${toString latestSdk}); do
if [ $x -ne 34 ]; then
# FIXME couldn't find platforms;android-34, even though it's in the correct directory!! sdkmanager's bug?!
packages+=("platforms;android-$x")
fi
packages+=("sources;android-$x")
if [ $x -ge 28 ]; then
if [ $x -lt 34 ]; then
packages+=("system-images;android-$x;google_apis_playstore;x86_64")
else
packages+=("system-images;android-$x;google_apis;x86_64")
fi
fi
done
${pkgs.lib.optionalString includeAuto ''packages+=("extras;google;auto")''}