Nixpkgs: Build Android 11 AOSP on nixos

Created on 13 Nov 2020  路  3Comments  路  Source: NixOS/nixpkgs

Describe the bug
Cannot build Android 11 AOSP on nixos without source modification

To Reproduce
As android is huge to download, the following could take a few hours to process, and you will need a solid machine to build android.
Steps to reproduce the behavior:

  1. Start android fhs
  2. Setup Android repository

    • mkdir AOSP_11 && cd AOSP_11

    • repo init -u https://android.googlesource.com/platform/manifest -b android-11.0.0_r17

    • repo sync :warning: This take a lot of time, you are about to download 100GB

  3. Setup build

    • source build/envsetup.sh

    • lunch aosp_taimen-userdebug

  4. Build it

    • make -j11 :warning: to complete the build this require a good CPU with 16GB Ram and some space disk

  5. After some build process if fail for linking issue to shared library.

Expected behavior
Build success

Additional context
Since I am on nix I use this fhs to build android.
But it no longer work on AOSP 11.

This is the error that happen:

prebuilts/clang/host/linux-x86/clang-3289846/bin/clang.real:
error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

This is caused by the android build system creating his own environment without LD_LIBRARY_PATH.
I didn't find any nix tips to have it working without modifying source, so I post this issue to indicate the fhs is no longer suffisant.

Here is the dirty workaround that seems to work. I do not have encounter any issues yet.
In following repo: TOP/build/soong

diff --git a/ui/build/sandbox_linux.go b/ui/build/sandbox_linux.go
index 2de772b00..85be64946 100644
--- a/ui/build/sandbox_linux.go
+++ b/ui/build/sandbox_linux.go
@@ -175,5 +175,6 @@ func (c *Cmd) wrapSandbox() {
    if _, hasUser := env.Get("USER"); hasUser {
        env.Set("USER", "nobody")
    }
+   env.Set("LD_LIBRARY_PATH", "/usr/lib:/usr/lib32")
    c.Env = []string(env)
 }

Notify maintainers
I have no idea who did the original FHS nor who trigger on this

Metadata

 - system: `"x86_64-linux"`
 - host os: `Linux 5.4.44, NixOS, 20.03.2102.e2bb73ce5f7 (Markhor)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.5`
 - channels(root): `"nixos-20.03.2102.e2bb73ce5f7, unstable-20.09pre228622.029a5de0839"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
bug

Most helpful comment

The Android build system (as of Android 11) now ignores certain environment variables by default, including LD_LIBRARY_PATH. You can run export ALLOW_NINJA_ENV=true before building to disable this behavior.

Also, in case you aren't aware of it, Robotnix can also be used to build AOSP using Nix.

All 3 comments

The Android build system (as of Android 11) now ignores certain environment variables by default, including LD_LIBRARY_PATH. You can run export ALLOW_NINJA_ENV=true before building to disable this behavior.

Also, in case you aren't aware of it, Robotnix can also be used to build AOSP using Nix.

I wasn't aware of this ninja option. Thanks ! It way cleaner than what i did.
I will put export ALLOW_NINJA_ENV=true it my android FHS, but it could be something nice to add to the example fhs on nixos Wiki. Does someone know who trigger to do so ?

I am aware of the Robotnix existence since i start searching for this issue, but i do not know how it work with local source tree, as I need to do heavy modification in multiple android repo(test it, build some debug code...).
Is there any possibility with Robotnix to do something like this nix-build ./default.nix --build_tree [PATH]?

Yeah, you're right that robotnix wouldn't help as much if you intend to do AOSP development (edit / test / debug cycles). It's most useful when you have something that works and want to allow end-users to easily build it using nix.

Was this page helpful?
0 / 5 - 0 ratings