Skip to content

Build Android 11 AOSP on nixos #103648

@wescande

Description

@wescande

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 ⚠️ 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 ⚠️ 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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions