Skip to content

Commit ab1e8d9

Browse files
committed
nix: prepare targets with rust-overlay
pre-install the system-images add doc of using avd without android-studio
1 parent 0e0e5d0 commit ab1e8d9

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,23 @@ $ cargo apk run --release
6060

6161
## Android Emulator
6262

63+
With Android Studio:
64+
6365
- Install [Android Studio](https://developer.android.com/studio)
6466
- Open 'Device Manager' in Android Studio
6567
- Add a new device with API level `34` and ABI `arm64-v8a` (even though the app uses 30, the 30 emulator can't find the vulkan adapter, but 34 works fine)
6668
- Start up the emulator
6769

70+
Without Android Studio:
71+
72+
```sh
73+
# create emulator
74+
avdmanager create avd -k 'system-images;android-34;google_apis;arm64-v8a' -n notedeck
75+
76+
# start up the emulator
77+
env ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL=999 emulator -avd notedeck
78+
```
79+
6880
while the emulator is running, run:
6981

7082
```bash

shell.nix

+49-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,53 @@
1-
{ pkgs ? import <nixpkgs> { }
2-
, android ? "https://github.com/tadfisher/android-nixpkgs/archive/refs/tags/2024-04-02.tar.gz"
1+
{ android ? "https://github.com/tadfisher/android-nixpkgs/archive/refs/tags/2024-04-02.tar.gz"
32
, use_android ? true
43
, android_emulator ? false
54
}:
6-
with pkgs;
5+
with import <nixpkgs>
6+
{
7+
overlays = [
8+
(import (builtins.fetchTarball {
9+
url = "https://github.com/oxalica/rust-overlay/archive/master.tar.gz";
10+
}))
11+
];
12+
config = {
13+
android_sdk.accept_license = use_android;
14+
allowUnfree = use_android;
15+
};
16+
};
717

818
let
919
x11libs = lib.makeLibraryPath [ xorg.libX11 xorg.libXcursor xorg.libXrandr xorg.libXi libglvnd vulkan-loader vulkan-validation-layers libxkbcommon ];
20+
rustc = (rust-bin.fromRustupToolchainFile ./rust-toolchain).override {
21+
targets = [ ] ++
22+
(lib.optionals (stdenv.isLinux && use_android) [
23+
"aarch64-linux-android"
24+
]) ++
25+
(lib.optionals (stdenv.isLinux && stdenv.isx86_64 && use_android && android_emulator) [
26+
"x86_64-linux-android"
27+
]) ++
28+
(lib.optionals (stdenv.isLinux && stdenv.isx86_64) [
29+
"x86_64-unknown-linux-gnu"
30+
]) ++
31+
(lib.optionals (stdenv.isLinux && !stdenv.isx86_64) [
32+
"aarch64-unknown-linux-gnu"
33+
]) ++
34+
(lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [
35+
"x86_64-apple-darwin"
36+
]) ++
37+
(lib.optionals (stdenv.isDarwin && !stdenv.isx86_64) [
38+
"aarch64-apple-darwin"
39+
])
40+
;
41+
};
1042
in
1143
mkShell ({
1244
nativeBuildInputs = [
45+
rustc
1346
#cargo-udeps
1447
#cargo-edit
1548
#cargo-watch
16-
rustup
17-
rustfmt
49+
# rustup
50+
# rustfmt
1851
libiconv
1952
pkg-config
2053
#cmake
@@ -45,13 +78,17 @@ mkShell ({
4578
android-nixpkgs = callPackage (fetchTarball android) { };
4679
ndk-version = "24.0.8215888";
4780

48-
android-sdk = android-nixpkgs.sdk (sdkPkgs: with sdkPkgs; [
49-
cmdline-tools-latest
50-
build-tools-34-0-0
51-
platform-tools
52-
platforms-android-30
53-
ndk-24-0-8215888
54-
] ++ lib.optional android_emulator [ emulator ]);
81+
android-sdk = android-nixpkgs.sdk
82+
(sdkPkgs: with sdkPkgs; [
83+
cmdline-tools-latest
84+
build-tools-34-0-0
85+
platform-tools
86+
platforms-android-30
87+
ndk-24-0-8215888
88+
] ++
89+
(lib.optionals android_emulator [ emulator ]) ++
90+
(lib.optionals (android_emulator && stdenv.isx86_64) [ system-images-android-34-google-apis-x86-64 ]) ++
91+
(lib.optionals (android_emulator && !stdenv.isx86_64) [ system-images-android-34-google-apis-arm64-v8a ]));
5592

5693
android-sdk-path = "${android-sdk.out}/share/android-sdk";
5794
android-ndk-path = "${android-sdk-path}/ndk/${ndk-version}";

0 commit comments

Comments
 (0)