New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 738056 link

Starred by 3 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux
Pri: 2
Type: Bug

Blocking:
issue v8:5918



Sign in to add a comment

V8 Build: static library for embedding V8 in Android application

Reported by henry.p...@gmail.com, Jun 29 2017

Issue description

UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36

Steps to reproduce the problem:
Building V8(tag 5.8.283.28) on Ubuntu 14.04LTS via GN, following the instruction at https://github.com/v8/v8/wiki/Building-with-GN 

1. Settings in my .gclient:
solutions = [
  {
    "url": "https://chromium.googlesource.com/v8/v8.git",
    "managed": False,
    "name": "v8",
    "deps_file": "DEPS",
    "custom_deps": {},
  },
]
target_os = ['android']

2. Run "tools/dev/v8gen.py x64.release" to prepare build configurationfor v8 library on Android Emulator(x86_64)

3. Add several entries to out.gn/x64.release/args.gn, it has the following:
is_debug = false
target_os = "android"
target_cpu = "x64"
v8_target_cpu = "arm64"
v8_enable_inspector = true
v8_use_snapshot = false
v8_static_library = true
is_component_build = false

4. Run "ninja -C out.gn/x64.release" to build libv8*.a 

5. Use Android Studio(2.3.3) to create a simple Hello World like Android App that links V8 static library. Here is the sample project I used as template: https://codelabs.developers.google.com/codelabs/android-studio-cmake/index.html

4. Add "v8::V8::Initialize();" to xxx_1cmake_MainActivity_stringFromJNI method in native-lib.cpp, also include <v8.h> at the top, modify CmakeLists.txt to include V8 headers and libraries. The V8 libraries I linked with are from v8/out.gn/x64.release/clang_x64_v8_arm64/obj

5. Build and launch sample app in Android Emulator(Nexus_5X_API_23)

What is the expected behavior?
Application launches successfully and "Hello from c++' is shown

What went wrong?
Application fails to launch with the following error in logcat:

06-29 08:29:52.995 18475-18475/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.ping.hello.hello_cmake, PID: 18475
                                                   java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZNSs4_Rep20_S_empty_rep_storageE" referenced by "/data/app/com.ping.hello.hello_cmake-1/lib/x86_64/libnative-lib.so"...
                                                       at java.lang.Runtime.loadLibrary(Runtime.java:372)
                                                       at java.lang.System.loadLibrary(System.java:1076)
                                                       at com.ping.myhello_cmake.MainActivity.<clinit>(MainActivity.java:11)
                                                       at java.lang.Class.newInstance(Native Method)
                                                       at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                       at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                       at android.os.Looper.loop(Looper.java:148)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Did this work before? N/A 

Chrome version: 59.0.3071.109  Channel: n/a
OS Version: Ubuntu 14.04LTS
Flash Version: 

- I also tried adding "libstdc++" to target_link_libraries in app's CMakeLists.txt, but still get same error
- I also tried to build V8 with Gyp:
1. added "standalone_static_library" setting to src/v8.gyp, suggested in http://linuxplayer.org/2013/12/how-to-build-v8-static-library
2. run "make android_x64.release -j16 component=static_library V=1"
3. The build fail with "v8/out/android_x64.release/obj.host/src/libv8_libplatform.a(default-platform.o):../src/libplatform/default-platform.cc:function v8::platform::CreateDefaultPlatform(int): error: undefined reference to 'v8::base::SysInfo::NumberOfProcessors()'
"
 
Cc: verwa...@chromium.org
Components: Blink>JavaScript
Update

-DANDROID_ALLOW_UNDEFINED_SYMBOLS was set to TRUE in my Hello World app's build.gradle which suppress many link errors. After setting it FALSE, I'm getting lots link errors:

/home/ping/.torq_cache/v8/v8-5.8.283.38/android-release-all/x86_64/libv8_base.a(api.o):../../src/api.cc:function v8::debug::Script::GetPossibleBreakpoints(v8::debug::Location const&, v8::debug::Location const&, std::vector<v8::debug::Location, std::allocator<v8::debug::Location> >*) const: error: undefined reference to 'std::_Rb_tree_increment(std::_Rb_tree_node_base const*)'
/home/ping/.torq_cache/v8/v8-5.8.283.38/android-release-all/x86_64/libv8_base.a(api.o):../../src/api.cc:function v8::debug::Coverage::ScriptData::GetFunctionData(unsigned long): error: undefined reference to 'std::__throw_out_of_range(char const*)'
/home/ping/.torq_cache/v8/v8-5.8.283.38/android-release-all/x86_64/libv8_base.a(api.o):../../src/api.cc:function v8::debug::Coverage::GetScriptData(unsigned long): error: undefined reference to 'std::__throw_out_of_range(char const*)'
/home/ping/.torq_cache/v8/v8-5.8.283.38/android-release-all/x86_64/libv8_base.a(assembler.o):../../src/assembler.cc:function v8::internal::operator<<(std::ostream&, v8::internal::ExternalReference): error: undefined reference to 'std::ostream& std::ostream::_M_insert<void const*>(void const*)'
/home/ping/.torq_cache/v8/v8-5.8.283.38/android-release-all/x86_64/libv8_base.a(assembler.o):../../src/assembler.cc:function v8::internal::operator<<(std::ostream&, v8::internal::ExternalReference): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
/home/ping/.torq_cache/v8/v8-5.8.283.38/android-release-all/x86_64/libv8_base.a(assembler.o):../../src/assembler.cc:function v8::internal::operator<<(std::ostream&, v8::internal::ExternalReference): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
/home/ping/.torq_cache/v8/v8-5.8.283.38/android-release-all/x86_64/libv8_base.
a(assembler.o):../../src/assembler.cc:function v8::internal::operator<<(std::ostream&, v8::internal::ExternalReference): error: undefined reference to 'std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)'
/home/ping/.torq_cache/v8/v8-5.8.283.38/android-release-all/x86_64/libv8_base.a(assembler.o):../../src/assembler.cc:function v8::internal::operator<<(std::ostream&, v8::internal::ExternalReference): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
...

Here is the list of v8 libraries linked with:
-rw-rw-r-- 1 ping ping  5914876 Jun 30 09:10 libicui18n.a
-rw-rw-r-- 1 ping ping  3263978 Jun 30 09:10 libicuuc.a
-rw-rw-r-- 1 ping ping 33332546 Jun 30 09:10 libv8_base.a
-rw-rw-r-- 1 ping ping   198362 Jun 30 09:03 libv8_libbase.a
-rw-rw-r-- 1 ping ping   114224 Jun 30 09:07 libv8_libplatform.a
-rw-rw-r-- 1 ping ping    16638 Jun 30 09:03 libv8_libsampler.a
-rw-rw-r-- 1 ping ping   215354 Jun 30 09:10 libv8_nosnapshot.a

Labels: TE-NeedsTriageHelp
Cc: -verwa...@chromium.org yangguo@chromium.org machenb...@chromium.org
Components: -Blink>JavaScript Blink>JavaScript>API
Status: Available (was: Unconfirmed)
Blocking: v8:5918

Comment 6 by kbr@chromium.org, Jul 11 2017

Cc: seththompson@chromium.org
Quick note that this bug was brought up by Adobe during a meeting as one that was blocking some of their work. 
Cc: lafo...@chromium.org abdulsyed@chromium.org
Cc: hablich@chromium.org
+hablich@ for V8
Cc: petermarshall@chromium.org
I think Peter was the last person who did try to embed V8 on Android. Peter, any clue what's going on?
Cc: rmcilroy@chromium.org
The build configuration in #1 is a bit unusual - you have target_cpu = x64 and v8_target_cpu = arm64, so the C++ code is being compiled for x64, but the v8 jit is generating arm64 code and running it in V8's arm64 simulator. This is the way we would usually setup a simulator build on a host machine in order to test v8's arm64 codegen on an x64 host desktop machine, however if you are wanting to run in an x64 Android simulator you shouldn't need this. 

Can with cleaning the out directory then configuring gn to just have target_cpu = "x64" and drop the "v8_target_cpu"?
Cc: -seththompson@chromium.org
I didn't try this on Android unfortunately - I wonder if Henry had any luck yet?
Project Member

Comment 14 by sheriffbot@chromium.org, Sep 18

Labels: Hotlist-Recharge-Cold
Status: Untriaged (was: Available)
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue.

Sorry for the inconvenience if the bug really should have been left as Available.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Status: Available (was: Untriaged)

Sign in to add a comment