Skip to content

Commit d3f8c4d

Browse files
hadilqJohnRTitor
authored andcommitted
androidenv: upgradde to repository2-3
androidenv: apply numinit patch to have a nice error message androidenv handle unsupported systems, and make tests running by default! androidenv run nixfmt androidenv: support emulator/systemimages/NDK only for certain systems androidenv: apply nixfmt androidenv: give a warning if archive doesn't exist
1 parent 7b0b1bd commit d3f8c4d

File tree

17 files changed

+5063
-800
lines changed

17 files changed

+5063
-800
lines changed

pkgs/development/mobile/androidenv/build-tools.nix

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
{deployAndroidPackage, lib, package, os, autoPatchelfHook, makeWrapper, pkgs, pkgsi686Linux, postInstall}:
1+
{deployAndroidPackage, lib, stdenv, package, os, autoPatchelfHook, makeWrapper, pkgs, pkgsi686Linux, postInstall}:
22

33
deployAndroidPackage {
4-
inherit package os;
4+
inherit package;
55
nativeBuildInputs = [ makeWrapper ]
66
++ lib.optionals (os == "linux") [ autoPatchelfHook ];
7-
buildInputs = lib.optionals (os == "linux") [ pkgs.glibc pkgs.zlib pkgs.ncurses5 pkgsi686Linux.glibc pkgsi686Linux.zlib pkgsi686Linux.ncurses5 pkgs.libcxx ];
7+
buildInputs = lib.optionals (os == "linux") [ pkgs.glibc pkgs.zlib pkgs.ncurses5 pkgs.libcxx ]
8+
++ lib.optionals (os == "linux" && stdenv.isx86_64) (with pkgsi686Linux; [ glibc zlib ncurses5 ]);
89
patchInstructions = ''
910
${lib.optionalString (os == "linux") ''
1011
addAutoPatchelfSearchPath $packageBaseDir/lib

pkgs/development/mobile/androidenv/cmake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{deployAndroidPackage, lib, package, os, autoPatchelfHook, pkgs, stdenv}:
22

33
deployAndroidPackage {
4-
inherit package os;
4+
inherit package;
55
nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
66
buildInputs = lib.optionals (os == "linux") [ pkgs.stdenv.cc.libc pkgs.stdenv.cc.cc pkgs.ncurses5 ];
77
patchInstructions = lib.optionalString (os == "linux") ''

pkgs/development/mobile/androidenv/compose-android-packages.nix

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
, platformToolsVersion ? "35.0.2"
88
, buildToolsVersions ? [ "35.0.0" ]
99
, includeEmulator ? false
10-
, emulatorVersion ? "35.3.10"
10+
, emulatorVersion ? "35.5.2"
1111
, platformVersions ? []
1212
, includeSources ? false
1313
, includeSystemImages ? false
@@ -27,9 +27,20 @@
2727

2828
let
2929
# Determine the Android os identifier from Nix's system identifier
30-
os = if stdenv.hostPlatform.isLinux then "linux"
31-
else if stdenv.hostPlatform.isDarwin then "macosx"
32-
else throw "No Android SDK tarballs are available for system architecture: ${stdenv.system}";
30+
os = {
31+
x86_64-linux = "linux";
32+
x86_64-darwin = "macosx";
33+
aarch64-linux = "linux";
34+
aarch64-darwin = "macosx";
35+
}.${stdenv.hostPlatform.system} or "all";
36+
37+
# Determine the Android arch identifier from Nix's system identifier
38+
arch = {
39+
x86_64-linux = "x64";
40+
x86_64-darwin = "x64";
41+
aarch64-linux = "aarch64";
42+
aarch64-darwin = "aarch64";
43+
}.${stdenv.hostPlatform.system} or "all";
3344

3445
# Uses mkrepo.rb to create a repo spec.
3546
mkRepoJson = { packages ? [], images ? [], addons ? [] }: let
@@ -71,9 +82,23 @@ let
7182
lib.attrsets.mapAttrsRecursive
7283
(path: value:
7384
if (builtins.elemAt path ((builtins.length path) - 1)) == "archives" then
74-
(builtins.listToAttrs
75-
(builtins.map
76-
(archive: lib.attrsets.nameValuePair archive.os (fetchurl { inherit (archive) url sha1; })) value))
85+
let
86+
validArchives = builtins.filter (archive:
87+
let
88+
isTargetOs = if builtins.hasAttr "os" archive then
89+
archive.os == os || archive.os == "all" else true;
90+
isTargetArc = if builtins.hasAttr "arch" archive then
91+
archive.arch == arch || archive.arch == "all" else true;
92+
in
93+
isTargetOs && isTargetArc
94+
) value;
95+
in
96+
lib.warnIf (builtins.length validArchives == 0)
97+
"No valid archives for ${lib.concatMapStringsSep "." (x: ''"${x}"'') path} for os=${os}, arch=${arch}"
98+
(lib.optionals (builtins.length validArchives > 0)
99+
(lib.last (map (archive:
100+
(fetchurl { inherit (archive) url sha1; })
101+
) validArchives)))
77102
else value
78103
)
79104
attrSet;
@@ -117,12 +142,12 @@ rec {
117142
inherit stdenv lib mkLicenses;
118143
};
119144

120-
deployAndroidPackage = ({package, os ? null, buildInputs ? [], patchInstructions ? "", meta ? {}, ...}@args:
145+
deployAndroidPackage = ({package, buildInputs ? [], patchInstructions ? "", meta ? {}, ...}@args:
121146
let
122147
extraParams = removeAttrs args [ "package" "os" "buildInputs" "patchInstructions" ];
123148
in
124149
deployAndroidPackages ({
125-
inherit os buildInputs meta;
150+
inherit buildInputs;
126151
packages = [ package ];
127152
patchesInstructions = { "${package.name}" = patchInstructions; };
128153
} // extraParams
@@ -139,8 +164,7 @@ rec {
139164
'';
140165

141166
platform-tools = callPackage ./platform-tools.nix {
142-
inherit deployAndroidPackage;
143-
os = if stdenv.system == "aarch64-darwin" then "macosx" else os; # "macosx" is a universal binary here
167+
inherit deployAndroidPackage os;
144168
package = check-version packages "platform-tools" platformToolsVersion;
145169
};
146170

@@ -176,14 +200,12 @@ rec {
176200

177201
platforms = map (version:
178202
deployAndroidPackage {
179-
inherit os;
180203
package = check-version packages "platforms" version;
181204
}
182205
) platformVersions;
183206

184207
sources = map (version:
185208
deployAndroidPackage {
186-
inherit os;
187209
package = check-version packages "sources" version;
188210
}
189211
) platformVersions;
@@ -218,7 +240,6 @@ rec {
218240
in
219241
lib.optionals (availablePackages != [])
220242
(deployAndroidPackages {
221-
inherit os;
222243
packages = availablePackages;
223244
patchesInstructions = instructions;
224245
})
@@ -247,14 +268,12 @@ rec {
247268

248269
google-apis = map (version:
249270
deployAndroidPackage {
250-
inherit os;
251271
package = (check-version addons "addons" version).google_apis;
252272
}
253273
) (builtins.filter (platformVersion: platformVersion < "26") platformVersions); # API level 26 and higher include Google APIs by default
254274

255275
google-tv-addons = map (version:
256276
deployAndroidPackage {
257-
inherit os;
258277
package = (check-version addons "addons" version).google_tv_addon;
259278
}
260279
) platformVersions;

pkgs/development/mobile/androidenv/default.nix

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,15 @@ rec {
2929
"34"
3030
"35"
3131
];
32-
includeEmulator = true;
33-
includeSystemImages = true;
34-
includeNDK = true;
32+
includeEmulator =
33+
with pkgs.stdenv.hostPlatform;
34+
system == "x86_64-linux" || system == "x86_64-darwin" || system == "aarch64-darwin";
35+
includeSystemImages =
36+
with pkgs.stdenv.hostPlatform;
37+
system == "x86_64-linux" || system == "x86_64-darwin" || system == "aarch64-darwin";
38+
includeNDK =
39+
with pkgs.stdenv.hostPlatform;
40+
system == "x86_64-linux" || system == "x86_64-darwin" || system == "aarch64-darwin";
3541
};
3642

3743
test-suite = pkgs.callPackage ./test-suite.nix { };

pkgs/development/mobile/androidenv/deploy-androidpackages.nix

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{stdenv, lib, unzip, mkLicenses}:
2-
{packages, os ? null, nativeBuildInputs ? [], buildInputs ? [], patchesInstructions ? {}, meta ? {}, ...}@args:
2+
{packages, nativeBuildInputs ? [], buildInputs ? [], patchesInstructions ? {}, meta ? {}, ...}@args:
33

44
let
55
extraParams = removeAttrs args [ "packages" "os" "buildInputs" "nativeBuildInputs" "patchesInstructions" ];
@@ -62,9 +62,7 @@ stdenv.mkDerivation ({
6262
inherit buildInputs;
6363
pname = "android-sdk-${lib.concatMapStringsSep "-" (package: package.name) sortedPackages}";
6464
version = lib.concatMapStringsSep "-" (package: package.revision) sortedPackages;
65-
src = map (package:
66-
if os != null && builtins.hasAttr os package.archives then package.archives.${os} else package.archives.all
67-
) packages;
65+
src = map (package: package.archives) packages;
6866
nativeBuildInputs = [ unzip ] ++ nativeBuildInputs;
6967
preferLocalBuild = true;
7068

pkgs/development/mobile/androidenv/emulator.nix

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{ deployAndroidPackage, lib, package, os, autoPatchelfHook, makeWrapper, pkgs, pkgsi686Linux, postInstall }:
1+
{ deployAndroidPackage, lib, stdenv, package, os, autoPatchelfHook, makeWrapper, pkgs, pkgsi686Linux, postInstall }:
22

33
deployAndroidPackage {
4-
inherit package os;
4+
inherit package;
55
nativeBuildInputs = [ makeWrapper ]
66
++ lib.optionals (os == "linux") [ autoPatchelfHook ];
77
buildInputs = lib.optionals (os == "linux") (with pkgs; [
@@ -16,7 +16,6 @@ deployAndroidPackage {
1616
ncurses5
1717
libdrm
1818
stdenv.cc.cc
19-
pkgsi686Linux.glibc
2019
expat
2120
freetype
2221
nss
@@ -36,7 +35,7 @@ deployAndroidPackage {
3635
libICE
3736
libSM
3837
libxkbfile
39-
]);
38+
]) ++ lib.optional (os == "linux" && stdenv.isx86_64) pkgsi686Linux.glibc;
4039
patchInstructions = lib.optionalString (os == "linux") ''
4140
addAutoPatchelfSearchPath $packageBaseDir/lib
4241
addAutoPatchelfSearchPath $packageBaseDir/lib64

pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
},
2121

2222
config ? pkgs.config,
23+
# You probably need to set it to true to express consent.
24+
licenseAccepted ?
25+
config.android_sdk.accept_license or (builtins.getEnv "NIXPKGS_ACCEPT_ANDROID_SDK_LICENSE" == "1"),
2326
}:
2427

2528
# Copy this file to your Android project.
@@ -48,9 +51,7 @@ let
4851

4952
# Otherwise, just use the in-tree androidenv:
5053
androidEnv = pkgs.callPackage ./.. {
51-
inherit config pkgs;
52-
# You probably need to uncomment below line to express consent.
53-
# licenseAccepted = true;
54+
inherit config pkgs licenseAccepted;
5455
};
5556

5657
sdkArgs = {
@@ -97,7 +98,6 @@ pkgs.mkShell rec {
9798
platformTools
9899
androidEmulator
99100
jdk
100-
pkgs.android-studio
101101
];
102102

103103
LANG = "C.UTF-8";
@@ -196,6 +196,9 @@ pkgs.mkShell rec {
196196
];
197197
}
198198
''
199+
export ANDROID_USER_HOME=$PWD/.android
200+
mkdir -p $ANDROID_USER_HOME
201+
199202
avdmanager delete avd -n testAVD || true
200203
echo "" | avdmanager create avd --force --name testAVD --package 'system-images;android-35;google_apis;x86_64'
201204
result=$(avdmanager list avd)

pkgs/development/mobile/androidenv/examples/shell-without-emulator.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
config.allowUnfree = true;
2020
},
2121
config ? pkgs.config,
22+
# You probably need to set it to true to express consent.
23+
licenseAccepted ?
24+
config.android_sdk.accept_license or (builtins.getEnv "NIXPKGS_ACCEPT_ANDROID_SDK_LICENSE" == "1"),
2225
}:
2326

2427
# Copy this file to your Android project.
@@ -50,9 +53,7 @@ let
5053

5154
# Otherwise, just use the in-tree androidenv:
5255
androidEnv = pkgs.callPackage ./.. {
53-
inherit config pkgs;
54-
# You probably need to uncomment below line to express consent.
55-
# licenseAccepted = true;
56+
inherit config pkgs licenseAccepted;
5657
};
5758

5859
sdkArgs = {
@@ -92,7 +93,6 @@ pkgs.mkShell rec {
9293
androidSdk
9394
platformTools
9495
jdk
95-
pkgs.android-studio
9696
];
9797

9898
LANG = "C.UTF-8";

pkgs/development/mobile/androidenv/examples/shell.nix

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
config.allowUnfree = true;
1717
},
1818

19-
config ? pkgs.config
19+
config ? pkgs.config,
20+
# You probably need to set it to true to express consent.
21+
licenseAccepted ?
22+
config.android_sdk.accept_license or (builtins.getEnv "NIXPKGS_ACCEPT_ANDROID_SDK_LICENSE" == "1"),
2023
}:
2124

2225
# Copy this file to your Android project.
@@ -57,9 +60,7 @@ let
5760

5861
# Otherwise, just use the in-tree androidenv:
5962
androidEnv = pkgs.callPackage ./.. {
60-
inherit config pkgs;
61-
# You probably need to uncomment below line to express consent.
62-
# licenseAccepted = true;
63+
inherit config pkgs licenseAccepted;
6364
};
6465

6566
androidComposition = androidEnv.composeAndroidPackages {
@@ -121,7 +122,7 @@ let
121122
in
122123
pkgs.mkShell rec {
123124
name = "androidenv-demo";
124-
packages = [ androidSdk platformTools jdk pkgs.android-studio ];
125+
packages = [ androidSdk platformTools jdk ];
125126

126127
LANG = "C.UTF-8";
127128
LC_ALL = "C.UTF-8";

pkgs/development/mobile/androidenv/fetchrepo.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ pushd "$(dirname "$0")" &>/dev/null || exit 1
1616

1717
mkdir -p xml
1818

19-
fetch repository2-1.xml xml/repository2-1.xml
19+
fetch repository2-3.xml xml/repository2-3.xml
2020
for img in android android-tv android-wear android-wear-cn android-automotive google_apis google_apis_playstore
2121
do
22-
fetch sys-img/$img/sys-img2-1.xml xml/$img-sys-img2-1.xml
22+
fetch sys-img/$img/sys-img2-3.xml xml/$img-sys-img2-3.xml
2323
done
24-
fetch addon2-1.xml xml/addon2-1.xml
24+
fetch addon2-3.xml xml/addon2-3.xml
2525

2626
popd &>/dev/null

0 commit comments

Comments
 (0)