# Building an Android app

**URL:** https://discourse.nixos.org/t/building-an-android-app/5043
**Category:** Uncategorized
**Created:** [December 6, 2019, 5:06pm UTC](https://discourse.nixos.org/t/building-an-android-app/5043 "2019-12-06T17:06:42Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![raboof](https://discourse.nixos.org/user_avatar/discourse.nixos.org/raboof/32/1681_2.png) [@raboof](https://discourse.nixos.org/u/raboof)
#### Post date: [December 6, 2019, 5:06pm UTC](https://discourse.nixos.org/t/building-an-android-app/5043/1 "2019-12-06T17:06:42Z")

</div>

I’d like to build the Android app ‘Alarmio’.

Following [Nixpkgs 23.11 manual | Nix & NixOS](https://nixos.org/nixpkgs/manual/#building-an-android-application), I created a `shell.nix`:

```auto
{ pkgs ? import <nixpkgs> {} }:

pkgs.androidenv..buildApp {
  name = "Alarmio";
  platformVersions = ["28"];
}

```

This gave me a

```auto
$ nix-shell
error: You must accept the Android Software Development Kit License Agreement at
https://developer.android.com/studio/terms
by setting nixpkgs config option 'android_sdk.accept_license = true;'

(use '--show-trace' to show detailed location information)

```

even though I do have `nixpkgs.config.android_sdk.accept_license = true` in my `/etc/nixos/configuration.nix`. I guess `licenseAccepted` isn’t passed on correctly somewhere? Anyway I ‘hacked around’ it like:

```auto
{ pkgs ? import <nixpkgs> {} }:

(pkgs.androidenv.override {
  licenseAccepted = true;
})
.buildApp {
  name = "Alarmio";
  platformVersions = ["28"];
}

```

This allows me to enter the nix-shell, but then when I try to `./gradlew install` I get:

```auto
FAILURE: Build completed with 4 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:mergeOssDebugResources'.
> Multiple task action failures occurred:
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
      > AAPT2 aapt2-3.5.0-5435860-linux Daemon #20: Daemon startup failed
        This should not happen under normal circumstances, please file an issue if it does.
   > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade

```

Adding `--stacktrace` reveals `/home/aengelen/.gradle/caches/transforms-2/files-2.1/8848e96d59858a36a941eba86940e0ae/aapt2-3.5.0-5435860-linux/aapt2` cannot be executed. Indeed, running that executable directly, it doesn’t have the interpreter set. I can `patchelf` the correct interpreter, but it seems gradle overwrites it every time.

Any ideas on how to get over this hurdle?

---

<div class="post-metadata">

### Author: ![raboof](https://discourse.nixos.org/user_avatar/discourse.nixos.org/raboof/32/1681_2.png) [@raboof](https://discourse.nixos.org/u/raboof)
#### Post date: [December 6, 2019, 5:09pm UTC](https://discourse.nixos.org/t/building-an-android-app/5043/2 "2019-12-06T17:09:05Z")

</div>

I guess `buildFHSUserEnv` could work to sidestep the problem of `aapt2` not finding its interpreter, but I’m not sure if you can somehow combine `buildFHSUserEnv` and the `buildApp` for android?

---

<div class="post-metadata">

### Author: ![SRGOM](https://discourse.nixos.org/user_avatar/discourse.nixos.org/srgom/32/1688_2.png) [@SRGOM](https://discourse.nixos.org/u/SRGOM)
#### Post date: [December 6, 2019, 6:08pm UTC](https://discourse.nixos.org/t/building-an-android-app/5043/3 "2019-12-06T18:08:14Z")

</div>

I think I did manage a successful dummy Android app a while back. I will try to find instructions if you can remind me in 4 days (hopefully you won’t need to … But do remind if you do)

---

<div class="post-metadata">

### Author: ![raboof](https://discourse.nixos.org/user_avatar/discourse.nixos.org/raboof/32/1681_2.png) [@raboof](https://discourse.nixos.org/u/raboof)
#### Post date: [December 28, 2019, 12:54pm UTC](https://discourse.nixos.org/t/building-an-android-app/5043/4 "2019-12-28T12:54:16Z")

</div>

(I cheated by creating a `/lib64/ld-linux-x86-64.so.2`… but that’s dirty so I’d still be interested in a proper solution)

---

<div class="post-metadata">

### Author: ![ihebchagra](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ihebchagra/32/1967_2.png) [@ihebchagra](https://discourse.nixos.org/u/ihebchagra)
#### Post date: [December 28, 2019, 1:05pm UTC](https://discourse.nixos.org/t/building-an-android-app/5043/5 "2019-12-28T13:05:27Z")

</div>

ummm maybe I’m not very knowledgeable but aren’t you supposed to put `android_sdk.accept_license = true;` in ~/.config/nixpkgs/config.nix  
That seemed to work for me

This is my ~/.config/nixpkgs/config.nix:

```auto
{
  allowUnfree = true;
  android_sdk.accept_license = true;
}

```

nix-shell has nothing to do with NixOS, it’s part of Nix rather so it doesn’t need configuration.nix I think

---

<div class="post-metadata">

### Author: ![raboof](https://discourse.nixos.org/user_avatar/discourse.nixos.org/raboof/32/1681_2.png) [@raboof](https://discourse.nixos.org/u/raboof)
#### Post date: [December 28, 2019, 3:36pm UTC](https://discourse.nixos.org/t/building-an-android-app/5043/6 "2019-12-28T15:36:20Z")

</div>

> [@ihebchagra](#):
>
> nix-shell has nothing to do with NixOS, it’s part of Nix rather so it doesn’t need configuration.nix I think

Aah, somehow I assumed settings in `/etc/nixos/configuration.nix` would be ‘inherited’ by the local/nix-shell config - indeed it looks like those are separate, got it.

I like to accept the license explicitly on a per-project basis, and my nix-fu is slowly improving, so I now got:

```auto
{ pkgs ? import <nixpkgs> { config.android_sdk.accept_license = true; } }:

pkgs.androidenv.buildApp {
  name = "Alarmio";
  platformVersions = ["28"];
}

```

No (good) solution for the `aapt2` interpreter, though.
