📜 ⬆️ ⬇️

Build Android on Mac OS X

image

Introductory

For one of the projects, it was necessary to revise the original Android code to create the firmware for a specific piece of hardware. The version for the assembly was chosen already relatively old - AOSP 4.0.4, but it is based on a stable code branch from the manufacturer of the piece of iron, therefore the condition is necessary. In addition to developing for Android, I develop iOS applications, respectively, I work under Mac OS X and use Xcode as one of the development environments.

The main problem in my case was that the old versions of AOSP are not tracked by anyone and new edits are not made to the build system. Therefore, if the assembly of the master is not particularly difficult, then the assembly of previous versions of Android for more recent versions of MacOS requires fixing a number of problems.

In my case, the working environment looks like this:

All the highlights and difficulties of assembling AOSP are well described in the official documentation . It also indicates that MacOS 10.5 or 10.6 is required for building 4.0.x branch and Xcode 3.14 is recommended, and in the “Known issues” section it is indicated that 4.0.x branch is not compatible with MacOS 10.7.
')
I use MacOS and Xcode for development and did not want to roll back to previous versions. In addition, there was a purely sporting interest to deal with the assembly without any fundamental changes in the environment.

Decision

Directly all the initial steps for assembly are described in the documentation and were performed in accordance with it: a case-sensitive disk image was created, the necessary utilities were installed, the Android code was downloaded. Then the build with the full-eng profile was launched.

Below I give the error texts from the console and the methods of correction. Depending on the version of AOSP and your environment, they may appear all or in part. Most of the solutions can be found on the Internet, I give only a brief description of the necessary actions. In addition to AOSP 4.0.4, versions 4.0.3 and 4.1.1 were also checked. The newer the version, the fewer errors occurred, but the first 2 took place everywhere. Separately, it is worth noting that when making the described changes, the emulator is going to correctly and I have not encountered problems with running the emulator specified in the same official “Known issues”.

Running the assembly to solve problems with the compiler is done by the command below. Here the important part is CC = "gcc" CXX = "g ++" , the rest can be standard parameters in any order and combination.
make CC="gcc" CXX="g++" -j4 

In the course of the assembly, apart from the one described in the documentation, the following problems arose:

Error 1

 external/webkit/Source/WebCore/xml/XPathParser.cpp: In member function 'WebCore::XPath::Expression* WebCore::XPath::Parser::parseStatement(const WTF::String&, WTF::PassRefPtr<WebCore::XPathNSResolver>, WebCore::ExceptionCode&)': external/webkit/Source/WebCore/xml/XPathParser.cpp:480:39: error: too many arguments to function 'int WebCore::XPath::xpathyyparse()' out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/XPathGrammar.hpp:106:5: note: declared here make: *** [out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/xml/XPathParser.o] Error 1 

Correction
Apply the patch https://bugs.webkit.org/show_bug.cgi?id=92264 . The patch falls with a small error, due to the discrepancy of the context, you need to look at the rej and remove a couple of old lines that the patch could not remove. Apply patch in external / webkit / directory.

Important
During linking, at the final stage of the assembly, errors like this may appear:
 prebuilt/darwin-x86/toolchain/arm-linux-androideabi-4.4.x/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/libwebcore.a(CSSParser.o): in function WebCore::CSSParser::parseMediaQuery(WebCore::MediaList*, WTF::String const&):external/webkit/Source/WebCore/css/CSSParser.cpp:621: error: undefined reference to 'cssyyparse(WebCore::CSSParser*)' 

Depending on whether you added changes to CSSParser. A certain mystic linker appears here (for the 4.1.1 version with the build with these corrections, there are no such problems). To fix the problem, you need to make some changes in CSSParser (read by the compiler, ie, not comments). I changed the definition of this function from cssyyparse (void *) to cssyyparse (WebCore :: CSSParser *) or vice versa. Then start rebuilding - everything will run smoothly from this place.

Error 2

 host SharedLib: libSR_Recognizer (out/host/darwin-x86/obj/lib/libSR_Recognizer.dylib) Undefined symbols for architecture i386: "_canPushAudioIntoRecognizer", referenced from: _SR_RecognizerAdvanceImpl in RecognizerImpl.o _detectBeginningOfSpeech in RecognizerImpl.o ... ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status make: *** [out/host/darwin-x86/obj/lib/libSR_Recognizer.dylib] Error 1 

Correction
Transfer definition to external / srec / portable / include / PortExport.h from master branch to ours.
 #if defined(__APPLE_CC__) #if __APPLE_CC__ >= 5621 #undef PINLINE #define PINLINE #endif #endif 


Error 3

 host Executable: triangleCM (out/host/darwin-x86/obj/EXECUTABLES/ triangleCM_intermediates/triangleCM) Undefined symbols: "__dyld_func_lookup", referenced from: _promoteLocalToGlobal in libSDL.a(SDL_dlcompat.o) _dlcompat_init_func in libSDL.a(SDL_dlcompat.o) ... ld: symbol(s) not found collect2: ld returned 1 exit status make: *** [out/host/darwin-x86/obj/EXECUTABLES/ triangleCM_intermediates/triangleCM] Error 1 

Correction
Add the LOCAL_SDL_LDLIBS + = /usr/lib/dylib1.o library to / development / tools / emulator / opengl / tests / translator_tests / for GLES_V2 / Android.mk and GLES_CM / Android.mk.

Error 4
Different definition of the strnlen function in the system and in local files. Unfortunately for this error the log is not recorded, but the essence will be clear at the mention of the function strnlen.

Correction
Add a condition for the strnlen function to external / elfutils / config-compat-darwin.h:
 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1070 static inline size_t strnlen (const char *__string, size_t __maxlen) #endif 


Error 5
Select the version of the SDK version of Mac OS to build the emulator. Similar to the previous error without the log, but the mention of the emulator qemu in the log will indicate here.

Correction
Replace the condition for the Mac OS version external / qemu / Makefile.android:
 - ifeq ($(filter 10.5 10.5.%,$(DARWIN_VERSION)),) + ifneq ($(filter 10.6 10.6.%,$(DARWIN_VERSION)),) 

And add connection libraries for MacOS:
  ifeq ($(HOST_OS),darwin) QEMU_SYSTEM_LDLIBS += -Wl,-framework,Cocoa,-framework,QTKit,-framework,CoreVideo + ifneq ($(filter 10.7 10.7.%,$(DARWIN_VERSION)),) + # Lion/XCode4 needs to be explicitly told the dynamic library + # lookup symbols in the precompiled libSDL are resolved at + # runtime + QEMU_SYSTEM_LDLIBS += -undefined dynamic_lookup + endif endif 


Error 6
If your operating system is on a disk with a case-sensitive file system, then this error may occur:
 external/qemu/android/camera/camera-capture-mac.m:24:24: error: QTKit/QTkit.h: No such file or directory 

Correction
The essence of the problem is simple - there is a typo in the name of the .h file, instead of the large K a small k is printed. Usually does not appear, because MacOS is installed on a disk with a case-insensitive file system. It fixes simply by replacing in the code with the correct file name "QTKit.h".

Conclusion

The main conclusion can be made that still collect Android better on Linux systems, or in a virtual machine, if you allow the power. In this case, MacOS is only an alternative and, as the developers themselves write, when updating the build system, all versions of the OS are not checked, and often they do not even have such an opportunity.

Source: https://habr.com/ru/post/207706/


All Articles