Skip to content

Commit

Permalink
nix: prepare targets with rust-overlay
Browse files Browse the repository at this point in the history
pre-install the system-images
add doc of using avd without android-studio
  • Loading branch information
hellodword committed May 16, 2024
1 parent 0e0e5d0 commit 0fad0cb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,23 @@ $ cargo apk run --release

## Android Emulator

With Android Studio:

- Install [Android Studio](https://developer.android.com/studio)
- Open 'Device Manager' in Android Studio
- 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)
- Start up the emulator

Without Android Studio:

```sh
# create emulator
avdmanager create avd -k 'system-images;android-34;google_apis;arm64-v8a' -n notedeck

# start up the emulator
env ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL=999 emulator -avd notedeck
```

while the emulator is running, run:

```bash
Expand Down
54 changes: 42 additions & 12 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
{ pkgs ? import <nixpkgs> { }
, android ? "https://github.com/tadfisher/android-nixpkgs/archive/refs/tags/2024-04-02.tar.gz"
{ android ? "https://github.com/tadfisher/android-nixpkgs/archive/refs/tags/2024-04-02.tar.gz"
, use_android ? true
, android_emulator ? false
}:
with pkgs;
with import <nixpkgs>
{
overlays = [
(import (builtins.fetchTarball {
url = "https://github.com/oxalica/rust-overlay/archive/master.tar.gz";
}))
];
config = {
android_sdk.accept_license = use_android;
allowUnfree = use_android;
};
};

let
x11libs = lib.makeLibraryPath [ xorg.libX11 xorg.libXcursor xorg.libXrandr xorg.libXi libglvnd vulkan-loader vulkan-validation-layers libxkbcommon ];
rustc = (rust-bin.fromRustupToolchainFile ./rust-toolchain).override {
targets = [ ] ++
(lib.optionals (stdenv.isLinux && use_android) [
"aarch64-linux-android"
]) ++
(lib.optionals (stdenv.isLinux && stdenv.isx86_64 && use_android && android_emulator) [
"x86_64-linux-android"
]) ++
(lib.optionals (stdenv.isLinux && stdenv.isx86_64) [
"x86_64-unknown-linux-gnu"
]) ++
(lib.optionals stdenv.isDarwin [
# TODO
]);
};
in
mkShell ({
nativeBuildInputs = [
rustc
#cargo-udeps
#cargo-edit
#cargo-watch
rustup
rustfmt
# rustup
# rustfmt
libiconv
pkg-config
#cmake
Expand Down Expand Up @@ -45,13 +71,17 @@ mkShell ({
android-nixpkgs = callPackage (fetchTarball android) { };
ndk-version = "24.0.8215888";

android-sdk = android-nixpkgs.sdk (sdkPkgs: with sdkPkgs; [
cmdline-tools-latest
build-tools-34-0-0
platform-tools
platforms-android-30
ndk-24-0-8215888
] ++ lib.optional android_emulator [ emulator ]);
android-sdk = android-nixpkgs.sdk
(sdkPkgs: with sdkPkgs; [
cmdline-tools-latest
build-tools-34-0-0
platform-tools
platforms-android-30
ndk-24-0-8215888
] ++
(lib.optionals android_emulator [ emulator ]) ++
(lib.optionals (android_emulator && stdenv.isx86_64) [ system-images-android-34-google-apis-x86-64 ]) ++
(lib.optionals (android_emulator && !stdenv.isx86_64) [ system-images-android-34-google-apis-arm64-v8a ]));

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

0 comments on commit 0fad0cb

Please sign in to comment.