'How do I avoid an ELFCLASS64 error when building Android 8 from source?

I have an old tablet I'm toying around with for the fun of it. I'm trying to build Android 8 from source just to tinker with it and see if I can install it on the tablet. I'm using Lubuntu 20.04 LTS.

So far, all I've done is set up my environment, sync to the android-8.1.0_r81 repo, and run m, all per the instructions here: https://source.android.com/setup

My tablet uses an ARMv7 processor, so when I ran lunch I chose aosp_arm-eng, which corresponds to a generic 32-bit ARMv7 processor.

However, when I run m, it eventually fails with the following error:

[  0% 1/9730] build out/target/product/generic/obj/ETC/sepolicy_tests_intermediates/sepolicy_tests
FAILED: out/target/product/generic/obj/ETC/sepolicy_tests_intermediates/sepolicy_tests 
/bin/bash -c "(python out/host/linux-x86/bin/sepolicy_tests.py -l out/host/linux-x86/lib64 -f out/target/product/generic/obj/ETC/plat_file_contexts_intermediates/plat_file_contexts -f out/target/product/generic/obj/ETC/nonplat_file_contexts_intermediates/nonplat_file_contexts -p out/target/product/generic/obj/ETC/sepolicy_intermediates/sepolicy ) && (touch out/target/product/generic/obj/ETC/sepolicy_tests_intermediates/sepolicy_tests )"
Traceback (most recent call last):
  File "out/host/linux-x86/bin/sepolicy_tests.py", line 73, in <module>
    pol = policy.Policy(options.policy, options.file_contexts, options.libpath)
  File "/home/username/Android/Development/Oreo/out/host/linux-x86/bin/policy.py", line 255, in __init__
    self.__InitLibsepolwrap(LibPath)
  File "/home/username/Android/Development/Oreo/out/host/linux-x86/bin/policy.py", line 190, in __InitLibsepolwrap
    lib = CDLL(LibPath + "/libsepolwrap.so")
  File "/home/username/Android/Development/Oreo/prebuilts/python/linux-x86/2.7.5/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: out/host/linux-x86/lib64/libsepolwrap.so: wrong ELF class: ELFCLASS64
...

From what I understand, the out directory is the output of the make command--out isn't in the original repo. I also understand (I think) that the wrong ELF class: ELFCLASS64 error means that the libsepolwrap.so library is expecting a 32-bit OS and getting a 64-bit one. What I don't understand is why libsepolwrap.so is expecting a 32-bit OS.

According to the docs,

A 64-bit environment is required for Android 2.3.x (Gingerbread) and higher versions, including the master branch. You can compile older versions on 32-bit systems.

Given that I haven't actually modified anything yet and I'm building a pure vanilla Android 8 ROM, I'm stumped as to how to even start trying to fix this.

Side Note: I am already aware that I can find a vanilla Android 8 ROM somewhere online; I'm more interested in building it myself so I can learn the process and have something to tinker with.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source