Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add android support #1231

Merged
merged 17 commits into from
Jun 20, 2024
108 changes: 108 additions & 0 deletions docs/integrations/android.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Android

Getting a full working android development environment with devenv is as simple as:

```nix title="devenv.nix"
{ pkgs, ... }:

{
android.enable = true;
}
```

For a more tailored development environment you can specify specific options:

```nix title="devenv.nix"
{ pkgs, ... }:

{
android = {
enable = true;
platforms.version = [ "32" "34" ];
systemImageTypes = [ "google_apis_playstore" ];
abis = [ "arm64-v8a" "x86_64" ];
cmakeVersions = [ "3.22.1" ];
cmdLineTools.version = "11.0";
tools.version = "26.1.1";
platformTools.version = "34.0.5";
buildTools.version = [ "30.0.3" ];
emulator = {
enable = true;
version = "34.1.9";
};
sources.enable = false;
systemImages.enable = true;
ndk.enable = true;
googleAPIs.enable = true;
googleTVAddOns.enable = true;
extras = [ "extras;google;gcm" ];
extraLicenses = [
"android-sdk-preview-license"
"android-googletv-license"
"android-sdk-arm-dbt-license"
"google-gdk-license"
"intel-android-extra-license"
"intel-android-sysimage-license"
"mips-android-sysimage-license"
];
android-studio = pkgs.android-studio;
};
}
```

Since Android contains many unfree packages, you need to set allowUnfree: true in devenv.yaml:

```nix title="devenv.yaml"
# other inputs
allowUnfree: true
```

## Emulators
Creating emulators via the android-studio GUI may not work as expected due to conflicts between the immutable Nix store paths and Android Studio requiring a mutable path. Therefore, it's recommended to create an emulator via the CLI:

### Creating an emulator
```nix title="bash"
avdmanager create avd --force --name my-android-emulator-name --package 'system-images;android-32;google_apis_playstore;x86_64'
```

After creating the emulator, you can use any text editor to develop for Android. During testing, we successfully ran a React Native project inside Android Studio by first creating the Android emulator externally as described above and then running:

## React Native
The following config works with react native starter project.
```nix title="devenv.nix"
{ ... }:

{
android = {
enable = true;
reactNative.enable = true;
};
}
```

```nix title="devenv.yaml"
inputs:
nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling
allowUnfree: true
```
## Flutter
The following config works with the flutter starter project.

```nix title="devenv.nix"
k3yss marked this conversation as resolved.
Show resolved Hide resolved
{pkgs, ... }:

{
android = {
enable = true;
flutter.enable = true;
};
}
```

```nix title="devenv.yaml"
inputs:
nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling
allowUnfree: true
```
5 changes: 5 additions & 0 deletions examples/android/devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ pkgs, ... }:

{
android.enable = true;
}
1 change: 1 addition & 0 deletions examples/android/devenv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allowUnfree: true
1 change: 1 addition & 0 deletions examples/supported-languages/.setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ echo " languages.unison.enable = lib.mkForce (!(pkgs.stdenv.isLinux && pkgs.std
echo " languages.standardml.enable = lib.mkForce (!pkgs.stdenv.isAarch64);" >> devenv.local.nix
# https://github.com/NixOS/nixpkgs/issues/297019
echo " languages.purescript.enable = lib.mkForce (!pkgs.stdenv.isAarch64);" >> devenv.local.nix
echo " android.enable = lib.mkForce (pkgs.stdenv.isLinux);" >> devenv.local.nix
echo "}" >> devenv.local.nix
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ nav:
- GitHub Actions: integrations/github-actions.md
- Codespaces / devcontainer: integrations/codespaces-devcontainer.md
- Difftastic: integrations/difftastic.md
- Android: integrations/android.md
- Examples: examples.md
- Editor Support:
- VSCode: editor-support/vscode.md
Expand Down
Loading
Loading