Add nix-shell for macos android development
Co-authored-by: William Casarin <jb55@jb55.com> Link: 20240404185039.3738-1-kernelkind@gmail.com Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
116ba27f3f
commit
272da6cced
3
.envrc
3
.envrc
@@ -1,7 +1,4 @@
|
|||||||
|
|
||||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
||||||
use nix
|
use nix
|
||||||
fi
|
|
||||||
|
|
||||||
export PATH=$PATH:$HOME/.cargo/bin
|
export PATH=$PATH:$HOME/.cargo/bin
|
||||||
export JB55=32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245
|
export JB55=32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245
|
||||||
|
|||||||
39
README.md
39
README.md
@@ -10,29 +10,54 @@ Look it actually runs on android!
|
|||||||
|
|
||||||
<img src="https://cdn.jb55.com/s/bebeeadf7001fae1.png" height="500px" />
|
<img src="https://cdn.jb55.com/s/bebeeadf7001fae1.png" height="500px" />
|
||||||
|
|
||||||
## Compiling
|
# Developer Setup
|
||||||
|
|
||||||
|
## Linux/MacOS
|
||||||
|
|
||||||
|
First, install [nix][nix] if you don't have it.
|
||||||
|
|
||||||
The `shell.nix` provides a reproducible build environment for android and rust. I recommend using [direnv][direnv] to load this environment when you `cd` into the directory.
|
The `shell.nix` provides a reproducible build environment for android and rust. I recommend using [direnv][direnv] to load this environment when you `cd` into the directory.
|
||||||
|
|
||||||
|
If you don't have [direnv][direnv], enter the dev shell via:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nix-shell
|
||||||
|
```
|
||||||
|
|
||||||
Once you have your dev shell setup, you can build with this command:
|
Once you have your dev shell setup, you can build with this command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo apk run --release
|
$ cargo run --release
|
||||||
```
|
```
|
||||||
|
|
||||||
This will build and run the app on your android device. If you don't have the `aarch64-linux-android` rust target yet, you can install it with:
|
## Android
|
||||||
|
|
||||||
|
The dev shell should also have all of the android-sdk dependencies needed for development, but you still need the `aarch64-linux-android` rustup target installed:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ rustup target add aarch64-linux-android
|
$ rustup target add aarch64-linux-android
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also just type
|
To run on a real device, just type:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run --release
|
$ cargo apk run --release
|
||||||
```
|
```
|
||||||
|
|
||||||
To run the multiplatform desktop version of the app called NoteDeck.
|
## Android Emulator
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
while the emulator is running, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo apk run --release
|
||||||
|
```
|
||||||
|
|
||||||
|
The app should appear on the emulator
|
||||||
|
|
||||||
[direnv]: https://direnv.net/
|
[direnv]: https://direnv.net/
|
||||||
|
[nix]: https://nixos.org/download/
|
||||||
|
|||||||
73
shell.nix
73
shell.nix
@@ -1,34 +1,57 @@
|
|||||||
{ pkgs ? import <nixpkgs> {}, use_android ? true }:
|
{ pkgs ? import <nixpkgs> { }
|
||||||
|
, android ? fetchTarball "https://github.com/tadfisher/android-nixpkgs/archive/refs/tags/2024-04-02.tar.gz"
|
||||||
|
, use_android ? true }:
|
||||||
with pkgs;
|
with pkgs;
|
||||||
|
|
||||||
let
|
let
|
||||||
x11libs = lib.makeLibraryPath [ xorg.libX11 xorg.libXcursor xorg.libXrandr xorg.libXi libglvnd vulkan-loader vulkan-validation-layers libxkbcommon ];
|
x11libs = lib.makeLibraryPath [ xorg.libX11 xorg.libXcursor xorg.libXrandr xorg.libXi libglvnd vulkan-loader vulkan-validation-layers libxkbcommon ];
|
||||||
|
android-nixpkgs = callPackage android { };
|
||||||
ndk-version = "24.0.8215888";
|
ndk-version = "24.0.8215888";
|
||||||
androidComposition = androidenv.composeAndroidPackages {
|
|
||||||
includeNDK = true;
|
android-sdk = android-nixpkgs.sdk (sdkPkgs: with sdkPkgs; [
|
||||||
ndkVersions = [ ndk-version ];
|
cmdline-tools-latest
|
||||||
platformVersions = [ "28" "29" "30" ];
|
build-tools-34-0-0
|
||||||
useGoogleAPIs = false;
|
platform-tools
|
||||||
#useGoogleTVAddOns = false;
|
platforms-android-30
|
||||||
#includeExtras = [
|
emulator
|
||||||
# "extras;google;gcm"
|
ndk-24-0-8215888
|
||||||
#];
|
]);
|
||||||
};
|
|
||||||
androidsdk = androidComposition.androidsdk;
|
android-sdk-path = "${android-sdk.out}/share/android-sdk";
|
||||||
android-home = "${androidsdk}/libexec/android-sdk";
|
android-ndk-path = "${android-sdk-path}/ndk/${ndk-version}";
|
||||||
ndk-home = "${android-home}/ndk/${ndk-version}";
|
|
||||||
in
|
in
|
||||||
|
|
||||||
mkShell ({
|
mkShell ({
|
||||||
|
buildInputs = [] ++ pkgs.lib.optional use_android [
|
||||||
|
android-sdk
|
||||||
|
];
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
cargo-udeps cargo-edit cargo-watch rustup rustfmt libiconv pkg-config cmake fontconfig
|
#cargo-udeps
|
||||||
brotli wabt gdb heaptrack
|
#cargo-edit
|
||||||
|
#cargo-watch
|
||||||
heaptrack
|
#rustup
|
||||||
|
#rustfmt
|
||||||
] ++ pkgs.lib.optional use_android [ jre openssl libiconv androidsdk cargo-apk ] ;
|
libiconv
|
||||||
|
pkg-config
|
||||||
|
#cmake
|
||||||
|
fontconfig
|
||||||
|
#brotli
|
||||||
|
#wabt
|
||||||
|
#gdb
|
||||||
|
#heaptrack
|
||||||
|
] ++ lib.optional use_android [
|
||||||
|
jre
|
||||||
|
openssl
|
||||||
|
libiconv
|
||||||
|
cargo-apk
|
||||||
|
] ++ lib.optional stdenv.isDarwin [
|
||||||
|
darwin.apple_sdk.frameworks.Security
|
||||||
|
darwin.apple_sdk.frameworks.OpenGL
|
||||||
|
darwin.apple_sdk.frameworks.CoreServices
|
||||||
|
darwin.apple_sdk.frameworks.AppKit
|
||||||
|
];
|
||||||
|
|
||||||
|
ANDROID_NDK_ROOT = android-ndk-path;
|
||||||
|
} // (if !stdenv.isDarwin then {
|
||||||
LD_LIBRARY_PATH="${x11libs}";
|
LD_LIBRARY_PATH="${x11libs}";
|
||||||
} // (if !use_android then {} else {
|
} else {}))
|
||||||
ANDROID_HOME = android-home;
|
|
||||||
NDK_HOME = ndk-home;
|
|
||||||
}))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user