androidenv: fix problem with avdmanager when trying to create an avd

To do so, we gathered different system images with the same
abiVersion in the same derivation.
This commit is contained in:
Hadi 2022-12-27 18:27:13 -05:00
parent 68196a61c2
commit e5fbfd894f
2 changed files with 31 additions and 15 deletions

View file

@ -185,20 +185,36 @@ rec {
system-images = lib.flatten (map (apiVersion:
map (type:
map (abiVersion:
lib.optionals (lib.hasAttrByPath [apiVersion type abiVersion] system-images-packages) (
deployAndroidPackage {
inherit os;
package = system-images-packages.${apiVersion}.${type}.${abiVersion};
# Patch 'google_apis' system images so they're recognized by the sdk.
# Without this, `android list targets` shows 'Tag/ABIs : no ABIs' instead
# of 'Tag/ABIs : google_apis*/*' and the emulator fails with an ABI-related error.
patchInstructions = lib.optionalString (lib.hasPrefix "google_apis" type) ''
# Deploy all system images with the same systemImageType in one derivation to avoid the `null` problem below
# with avdmanager when trying to create an avd!
#
# $ yes "" | avdmanager create avd --force --name testAVD --package 'system-images;android-33;google_apis;x86_64'
# Error: Package path is not valid. Valid system image paths are:
# null
let
availablePackages = map (abiVersion:
system-images-packages.${apiVersion}.${type}.${abiVersion}
) (builtins.filter (abiVersion:
lib.hasAttrByPath [apiVersion type abiVersion] system-images-packages
) abiVersions);
instructions = builtins.listToAttrs (map (package: {
name = package.name;
value = lib.optionalString (lib.hasPrefix "google_apis" type) ''
# Patch 'google_apis' system images so they're recognized by the sdk.
# Without this, `android list targets` shows 'Tag/ABIs : no ABIs' instead
# of 'Tag/ABIs : google_apis*/*' and the emulator fails with an ABI-related error.
sed -i '/^Addon.Vendor/d' source.properties
'';
}
)
) abiVersions
}) availablePackages
);
in
lib.optionals (availablePackages != [])
(deployAndroidPackages {
inherit os;
packages = availablePackages;
patchesInstructions = instructions;
})
) systemImageTypes
) platformVersions);
@ -271,8 +287,8 @@ rec {
${lib.concatMapStrings (system-image: ''
apiVersion=$(basename $(echo ${system-image}/libexec/android-sdk/system-images/*))
type=$(basename $(echo ${system-image}/libexec/android-sdk/system-images/*/*))
mkdir -p system-images/$apiVersion/$type
ln -s ${system-image}/libexec/android-sdk/system-images/$apiVersion/$type/* system-images/$apiVersion/$type
mkdir -p system-images/$apiVersion
ln -s ${system-image}/libexec/android-sdk/system-images/$apiVersion/$type system-images/$apiVersion/$type
'') images}
'';

View file

@ -163,7 +163,7 @@ pkgs.mkShell rec {
installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}')
packages=(
"build-tools;30.0.3" "ndk-bundle" "platform-tools" \
"build-tools;30.0.3" "platform-tools" \
"platforms;android-23" "platforms;android-24" "platforms;android-25" "platforms;android-26" \
"platforms;android-27" "platforms;android-28" "platforms;android-29" "platforms;android-30" \
"platforms;android-31" "platforms;android-32" "platforms;android-33" \