Unable to build V8 library for Android in Mac - please advise

1,613 views
Skip to first unread message

Heriberto Delgado

unread,
Jul 17, 2015, 11:14:55 AM7/17/15
to v8-u...@googlegroups.com, Daniel Rojas
Environment:

- MacBook Pro (Retina, 15-inch, Mid 2014)
- OSX Yosemite (10.10.4)
- Xcode 6.4
- Android Studio 1.3 RC 1 (141.2071668)

My intent is to compile V8 as a shared library so I can include it in my new project as a standalone Javascript engine.

These are the steps I followed starting July 16, 2015 in order to accomplish that task:

1) Used SourceTree to clone depot_tools into ~/Projects/depot_tools

2) Started Terminal, then:

    export PATH=~/Projects/depot_tools:$PATH

    cd Projects

    fetch v8        (took about 15 min.)

3) As suggested in https://code.google.com/p/v8-wiki/wiki/D8OnAndroid , opened ~/Projects/.gclient and added:

    target_os = [‘android’]

    And then, on Terminal:
    
    cd v8

    gclient sync —nohooks          (15:20 hrs - very slow connection)

4) Terminal again, then:

    make android_arm -j16 library=shared

    The process aborts with the following errors:


    make[1]: *** No rule to make target ‘android_arm.optdebug’. Stop.

    /bin/sh: ~/Projects/v8/third_party/android_tools/ndk//toolchains/arm-linux-androideabi-4.9/prebuilt/mac-x86_64/bin/*-gcc: No such file or directory

    make[1]: *** [out/Makefile.android_arm.debug] Error 1

    make[1]: *** [out/Makefile.android_arm.release] Error 1


No idea what is “optdebug”, so I didn’t pursue any further. The missing folder, however, was really missing. There was no prebuilt/mac-x86_64/, just one prebuilt/linux-x86_64/. Renamed the latter to the former, and then tried again.

The new error message is:

/bin/sh: ~/Projects/v8/third_party/android_tools/ndk//toolchains/arm-linux-androideabi-4.9/prebuilt/mac-x86_64/bin/arm-linux-androideabi-gcc: cannot execute binary file

Renamed directories to what they were before (that is, prebuilt/mac-x86_64/ -> prebuilt/linux-x86_64 ).

Checked my Android Studio NDK folder in ~/Library/Android/sdk/ndk-bundle, found folder prebuilt/darwin-x86_64. Copied it to V8’s /prebuilt folder, renamed it to mac-x86-64. Tried again.

The compile step failed with these errors:


In file included from ../src/libplatform/task-queue.cc:5:
In file included from .././src/libplatform/task-queue.h:8:
In file included from ~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/queue:169:
In file included from ~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/deque:159:
In file included from ~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/__split_buffer:7:
In file included from ~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/algorithm:626:
~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/cstring:61:10: fatal error: 
      'string.h' file not found
#include <string.h>
         ^
In file included from ../src/libplatform/worker-thread.cc:5:
In file included from .././src/libplatform/worker-thread.h:8:
In file included from ~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/queue:169:
In file included from ~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/deque:159:
In file included from ~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/__split_buffer:7:
In file included from ~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/algorithm:626:
~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/cstring:61:10: fatal error: 
      'string.h' file not found
#include <string.h>
         ^
In file included from ../src/base/bits.cc:5:
In file included from .././src/base/bits.h:9:
In file included from .././src/base/macros.h:11:
~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/cstring:61:10: fatal error: 
      'string.h' file not found
#include <string.h>
         ^
../src/base/atomicops_internals_x86_gcc.cc:8:10: fatal error: 'string.h' file
      not found
#include <string.h>
         ^
1 error generated.
make[2]: *** [~/Projects/v8/out/android_arm.debug/obj.host/v8_libbase/src/base/atomicops_internals_x86_gcc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
  CXX(host) ~/Projects/v8/out/android_arm.debug/obj.host/v8_libbase/src/base/division-by-constant.o
In file included from ../src/base/cpu.cc:5:
In file included from .././src/base/cpu.h:16:
In file included from .././src/base/macros.h:11:
~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/cstring:61:10: fatal error: 
      'string.h' file not found
#include <string.h>
         ^
In file included from ../src/libplatform/default-platform.cc:5:
In file included from .././src/libplatform/default-platform.h:8:
In file included from ~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/functional:477:
In file included from ~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/memory:606:
In file included from ~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/iterator:346:
~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/iosfwd:90:10: fatal error: 
      'wchar.h' file not found
#include <wchar.h>  // for mbstate_t
         ^
In file included from ../src/base/division-by-constant.cc:9:
In file included from .././src/base/logging.h:8:
~/Projects/v8/third_party/llvm-build/Release+Asserts/bin/../include/c++/v1/cstring:61:10: fatal error: 
      'string.h' file not found
#include <string.h>
         ^
1 error generated.




At this point, I don’t know what else to do.

Can you please tell me what am I doing wrong, and how to fix it? Being able to include V8 as a standalone Javascript engine is vital for my project, so any help will be greatly appreciated. Thanks in advance!

Heriberto Delgado

unread,
Jul 23, 2015, 12:24:52 PM7/23/15
to v8-users, herib...@gmail.com
As an update to this issue, I just learned a bit more about the different ways to compile V8. Now, from Terminal, I just do:

make android_arm.debug -j16 GYPFLAGS="-Dandroid_ndk_root=/Users/heribertod/Library/Android/sdk/ndk-bundle -Dhost_os=darwin -Dlibrary=shared"


With no need to modify anything on the V8 folder.


However, I'm still getting the "<string.h>, <wchar.h> not found" messages. Does anyone have any idea why this happens, and how to fix it?

Heriberto Delgado

unread,
Jul 27, 2015, 12:48:47 PM7/27/15
to v8-users, herib...@gmail.com
A second update.

Today's build (July 27, 2015) does not show <string.h> errors anymore.

Good work, whoever did that :).

Two more to go ( <stdio.h> and <wchar.h> ).




El viernes, 17 de julio de 2015, 9:14:55 (UTC-6), Heriberto Delgado escribió:

Heriberto Delgado

unread,
Jul 31, 2015, 4:01:19 PM7/31/15
to v8-users, herib...@gmail.com
New update:

I just discovered something interesting. The project has a 'target' step, and a 'host' step; 'target' in this case is the Android ARM build, and 'host' seems to be an OS X build.

The missing <string.h>, <stdio.h> and <wchar.h> errors, actually, happen in the 'host' step. After a bit of investigation, I found out that my current Xcode setup was missing the Command Line development tools.

After installing it, the missing header errors vanished (yay!). But now, I have an entirely different set of errors; linking errors, to be precise:


  LINK(target) ~/Projects/v8/out/android_arm.release/hello-world
~/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: error: ~/Projects/v8/out/android_arm.release/obj.target/tools/gyp/libv8_libplatform.a: no archive symbol table (run ranlib)
~/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: error: ~/Projects/v8/out/android_arm.release/obj.target/third_party/icu/libicui18n.a: no archive symbol table (run ranlib)
~/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: error: ~/Projects/v8/out/android_arm.release/obj.target/third_party/icu/libicuuc.a: no archive symbol table (run ranlib)
~/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: error: ~/Projects/v8/out/android_arm.release/obj.target/tools/gyp/libv8_base.a: no archive symbol table (run ranlib)
~/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: error: ~/Projects/v8/out/android_arm.release/obj.target/tools/gyp/libv8_libbase.a: no archive symbol table (run ranlib)
~/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: error: ~/Projects/v8/out/android_arm.release/obj.target/third_party/icu/libicudata.a: no archive symbol table (run ranlib)
~/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: error: ~/Projects/v8/out/android_arm.release/obj.target/tools/gyp/libv8_snapshot.a: no archive symbol table (run ranlib)
~/Projects/v8/out/android_arm.release/obj.target/hello-world/samples/hello-world.o:hello-world.cc:function main: error: undefined reference to 'v8::V8::InitializeICU(char const*)'
~/Projects/v8/out/android_arm.release/obj.target/hello-world/samples/hello-world.o:hello-world.cc:function main: error: undefined reference to 'v8::platform::CreateDefaultPlatform(int)'
~/Projects/v8/out/android_arm.release/obj.target/hello-world/samples/hello-world.o:hello-world.cc:function main: error: undefined reference to 'v8::V8::InitializePlatform(v8::Platform*)'

....

~/Projects/v8/out/android_arm.release/obj.target/shell/samples/shell.o:shell.cc:function main: error: undefined reference to 'v8::V8::ShutdownPlatform()'
~/Projects/v8/out/android_arm.release/obj.target/shell/samples/shell.o:shell.cc:function main: error: undefined reference to 'v8::Isolate::Exit()'
collect2: error: ld returned 1 exit status
make[2]: *** [~/Projects/v8/out/android_arm.release/shell] Error 1
cc1plus: warning: unrecognized command line option "-Wno-format-pedantic"
cc1plus: warning: unrecognized command line option "-Wno-format-pedantic"
cc1plus: warning: unrecognized command line option "-Wno-format-pedantic"
make[1]: *** [android_arm.release] Error 2
make: *** [android_arm.release] Error 2


El viernes, 17 de julio de 2015, 9:14:55 (UTC-6), Heriberto Delgado escribió:

Heriberto Delgado

unread,
Aug 4, 2015, 4:24:47 PM8/4/15
to v8-users
Another update.

First of all, let me tell you: I am a bit disappointed for the poor (actually, for the non-existent) support in this group for this issue. Is it really that atypical that someone attempts to build an Android version of V8 using a recent Mac model with the latest tools available? Makes you wonder if Google is really *that* commited to open-source software development, in spirit - as opposed to in letter, as Google clearly is...

Oh well.

I finally got version 4.3.60 to compile and produce valid (full, instead of thin) libraries for arm-eabi, arm64, x86, x64 and mips (but no mips64). A modification was needed in \tools\gyp\v8.gyp to do that. Attached is the modified v8.gyp with the modifications.

I chose 4.3.60 since it was the last version I could compile by using the steps below. Any versions after this one use the new compilation method (that is, the one where you do not need to specify an ANDROID_NDK_ROOT environment variable) and, it seems, are no longer able to produce fat v8 libraries.

A few points of interest if you want to do the same:

- This applies for version 4.3.60 only - check your local git copy for a "4.3.60" tag.
- You will need *both* Xcode and the Command Line Development tools installed in your machine.
- Overwrite the current /tools/gyp/v8.gyp file with the attached one, in order to produce fat (instead of thin) libraries.
- This version uses the old compilation method, so be sure to " export ANDROID_NDK_ROOT=~/Path/To/Your/Android/NDK/Folder/ ".
- If you attempt to include internationalization support, the system will generate a few ICU library files, but they are all "thin" and cannot be used in your project. I still haven't found a way to make them "fat".
- By all means, do include -j16 in your build command (or a similar number); it will speed up the compilation considerably.
- VERY IMPORTANT: The debugging agent that was present in version 3.14 is *gone* now, for good. See https://groups.google.com/forum/#!msg/v8-users/pS5tgGXzzHY/qG2txmrfqcAJ . The debugging protocol and related functions, however, are still there; the only thing you need to implement externally is the thread code that creates a socket that sends and receive debugging commands outside the app.

Now, to create the Android builds on a (recent model) Mac:

- Open Terminal, then run the following commands:
   fetch v8
   cd v8
- Using your favorite git client, "checkout 4.3.60" in the v8 folder.
- In Terminal, run:
  gclient sync
- Copy the attached file to the /tools/gyp folder, overwriting the existing one.
- In Terminal, run:
   export ANDROID_NDK_ROOT=/The/Full/Path/To/Your/Android/NDK/Folder/

With this, you're ready to build the make commands for the various v8 libraries. In Terminal, run:

   make android_arm.release -j16 i18nsupport=off
   make android_arm64.release -j16 i18nsupport=off
   make android_ia32.release -j16 i18nsupport=off
   make android_x64.release -j16 i18nsupport=off
   make android_mipsel.release -j16 i18nsupport=off

The new library files are stored in folders called:

   /out/android_arm.release
   /out/android_arm64.release
   /out/android_ia32.release
   /out/android_x64.release
   /out/android_mipsel.release
 
Containing these files at each one of these folders:

  libv8_base.a
  libv8_libbase.a
  libv8_libplatform.a
  libv8_nosnapshot.a
  libv8_snapshot.a

These are the files you want; just remember to choose one of libv8_snapshot.a or libv8_nosnapshot.a depending on your project's needs.

Hope this helps for anyone else that might have these issues.



El viernes, 17 de julio de 2015, 9:14:55 (UTC-6), Heriberto Delgado escribió:
v8.gyp

Michael Hablich

unread,
Aug 5, 2015, 3:38:07 AM8/5/15
to v8-users
Hi Heriberto,

few answers inline.

On Tuesday, August 4, 2015 at 10:24:47 PM UTC+2, Heriberto Delgado wrote:
Another update.

First of all, let me tell you: I am a bit disappointed for the poor (actually, for the non-existent) support in this group for this issue. Is it really that atypical that someone attempts to build an Android version of V8 using a recent Mac model with the latest tools available?

It seems so, else you would have gotten any response. There are similar threads for other OS were people got feedback because other developers have the same/similar build configuration.
 
Makes you wonder if Google is really *that* commited to open-source software development, in spirit - as opposed to in letter, as Google clearly is...

Oh well.

I finally got version 4.3.60 to compile and produce valid (full, instead of thin) libraries for arm-eabi, arm64, x86, x64 and mips (but no mips64). A modification was needed in \tools\gyp\v8.gyp to do that. Attached is the modified v8.gyp with the modifications.

I chose 4.3.60 since it was the last version I could compile by using the steps below. Any versions after this one use the new compilation method (that is, the one where you do not need to specify an ANDROID_NDK_ROOT environment variable) and, it seems, are no longer able to produce fat v8 libraries.

A few points of interest if you want to do the same:

- This applies for version 4.3.60 only - check your local git copy for a "4.3.60" tag.
- You will need *both* Xcode and the Command Line Development tools installed in your machine.
- Overwrite the current /tools/gyp/v8.gyp file with the attached one, in order to produce fat (instead of thin) libraries.
- This version uses the old compilation method, so be sure to " export ANDROID_NDK_ROOT=~/Path/To/Your/Android/NDK/Folder/ ".
- If you attempt to include internationalization support, the system will generate a few ICU library files, but they are all "thin" and cannot be used in your project. I still haven't found a way to make them "fat".
- By all means, do include -j16 in your build command (or a similar number); it will speed up the compilation considerably.

Yes, be aware that this depends on the cores you are having on your machine.

Moritz Möller

unread,
Nov 16, 2015, 7:16:36 AM11/16/15
to v8-users
Just a short me too - I'm getting exactly the same error, so it has nothing to do with your build configuration.

Ended up using a linux vm to build the arm libraries and using ar rvs to make the static libraries fat.


On Tuesday, August 4, 2015 at 10:24:47 PM UTC+2, Heriberto Delgado wrote:
Reply all
Reply to author
Forward
0 new messages