-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build, api, docs: android support #10341
Comments
TLDR of the situation as I understand it: Android is linux but has some heavy restrictions that make it difficult to run unixy programs like node on it (Security!). You are allowed one process, basically, and it has to be java. However, you can link to a .so file linked from, say, C++. jxcore provided this, by forking node and providing a shared libary build output that could be linked into a java program. However, jxcore forked node too hard and added a bunch of things that would never have been merged into node core (for example, fibers). Earlier this year, they announced they would be halting development on jxcore https://twitter.com/nodejx/status/713443442102312960 Obviously this is a lot of work, theirfore the right way to do it is get it merged into node.js core, so that there can be an official android distribution. There is no opposition to the idea of running node on android, there is even an android-configure file in node's root directory. But there are a things to sort out to get it all into place. If want to be able to run node in an android app, then subscribe to this issue to be kept abreast of progress. |
This will necessitate figuring out how to have a proper android hardware testing story with @nodejs/build - Even if it is only one type of device. |
In terms of have node.js build as a share library there has been some work to support that but its an option to compile separately . My longer term goal is that we get to a point where the node.js distribution includes both the executable binary and the shared library along with full testing of the shared library. @sxa555 can you subscribe to this in case there are any additional requirements/considerations we should factor into the work on shared libraries that come out of the discussion for android. |
I have been working to get the shared library cross compiling an android arm shared library from a linux build host. Using Ubuntu 16.04 Xenial the and the following build steps: #!/bin/bash
# Ubuntu 16.04 Xenial
export DEBIAN_FRONTEND="noninteractive"
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install openjdk-8-jdk -y
sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 python \
lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libbz2-dev \
libgl1-mesa-dev libxml2-utils xsltproc unzip openjdk-8-jdk htop vim -y
wget "https://dl.google.com/android/repository/android-ndk-r14-beta1-linux-x86_64.zip"
unzip android-ndk-r14-beta1-linux-x86_64.zip
git clone https://github.com/nodejs/node.git
cd node
git checkout v6.9.1
make clean
export ANDROID_NDK_NAME=android-ndk-r14-beta1
export ANDROID_NDK_HOME=~/$ANDROID_NDK_NAME/
export TOOLCHAIN=$PWD/android-toolchain
rm -rf $TOOLCHAIN
~/$ANDROID_NDK_NAME/build/tools/make-standalone-toolchain.sh --toolchain=arm-linux-androideabi-4.9 --arch=arm --install-dir=$TOOLCHAIN --platform=android-21
export PATH=$TOOLCHAIN/bin:$PATH
export AR=$TOOLCHAIN/bin/arm-linux-androideabi-ar
export CC=$TOOLCHAIN/bin/arm-linux-androideabi-gcc
export CXX=$TOOLCHAIN/bin/arm-linux-androideabi-g++
export LINK=$TOOLCHAIN/bin/arm-linux-androideabi-g++
# see # see https://github.com/nodejs/node/issues/3074
sed -i 's/#define HAVE_GETSERVBYPORT_R 1/#undef HAVE_GETSERVBYPORT_R/' deps/cares/config/android/ares_config.h
GYP_DEFINES="target_arch=arm"
GYP_DEFINES+=" v8_target_arch=arm"
GYP_DEFINES+=" android_target_arch=arm"
GYP_DEFINES+=" host_os=linux OS=android"
export GYP_DEFINES
./configure \
--dest-cpu=arm \
--dest-os=android \
--without-snapshot \
--without-inspector \
--without-intl \
--without-dtrace \
--without-etw \
--without-perfctr \
--openssl-no-asm \
--shared
# Do not run `source android-configure /home/ubuntu/android-ndk-r14-beta1 arm`
time make -j4 BUILDTYPE=Release This get's to the final linking step and gacks when trying to resolve /home/ubuntu/node/android-toolchain/bin/arm-linux-androideabi-g++ -rdynamic -fPIE -pie -o /home/ubuntu/node/out/Release/cctest -Wl,--start-group /home/ubuntu/node/out/Release/obj.target/cctest/test/cctest/util.o /home/ubuntu/node/out/Release/obj.target/deps/gtest/libgtest.a /home/ubuntu/node/out/Release/obj.target/deps/v8/tools/gyp/libv8_libplatform.a /home/ubuntu/node/out/Release/obj.target/deps/v8/tools/gyp/libv8_libbase.a /home/ubuntu/node/out/Release/obj.target/deps/v8/tools/gyp/libv8_base.a /home/ubuntu/node/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a -Wl,--end-group -llog
/home/ubuntu/node/android-toolchain/bin/arm-linux-androideabi-g++ -shared -rdynamic -fPIE -pie -Wl,-soname=libnode.so.48 -o /home/ubuntu/node/out/Release/obj.target/libnode.so.48 -Wl,--whole-archive /home/ubuntu/node/out/Release/obj.target/node/src/debug-agent.o /home/ubuntu/node/out/Release/obj.target/node/src/async-wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/env.o /home/ubuntu/node/out/Release/obj.target/node/src/fs_event_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/cares_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/connection_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/connect_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/handle_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/js_stream.o /home/ubuntu/node/out/Release/obj.target/node/src/node.o /home/ubuntu/node/out/Release/obj.target/node/src/node_buffer.o /home/ubuntu/node/out/Release/obj.target/node/src/node_config.o /home/ubuntu/node/out/Release/obj.target/node/src/node_constants.o /home/ubuntu/node/out/Release/obj.target/node/src/node_contextify.o /home/ubuntu/node/out/Release/obj.target/node/src/node_file.o /home/ubuntu/node/out/Release/obj.target/node/src/node_http_parser.o /home/ubuntu/node/out/Release/obj.target/node/src/node_javascript.o /home/ubuntu/node/out/Release/obj.target/node/src/node_os.o /home/ubuntu/node/out/Release/obj.target/node/src/node_revert.o /home/ubuntu/node/out/Release/obj.target/node/src/node_util.o /home/ubuntu/node/out/Release/obj.target/node/src/node_v8.o /home/ubuntu/node/out/Release/obj.target/node/src/node_stat_watcher.o /home/ubuntu/node/out/Release/obj.target/node/src/node_watchdog.o /home/ubuntu/node/out/Release/obj.target/node/src/node_zlib.o /home/ubuntu/node/out/Release/obj.target/node/src/node_i18n.o /home/ubuntu/node/out/Release/obj.target/node/src/pipe_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/signal_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/spawn_sync.o /home/ubuntu/node/out/Release/obj.target/node/src/string_bytes.o /home/ubuntu/node/out/Release/obj.target/node/src/stream_base.o /home/ubuntu/node/out/Release/obj.target/node/src/stream_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/tcp_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/timer_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/tty_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/process_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/udp_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/uv.o /home/ubuntu/node/out/Release/obj.target/node/src/util.o /home/ubuntu/node/out/Release/obj.target/node/src/string_search.o /home/ubuntu/node/out/Release/obj.target/node/src/node_crypto.o /home/ubuntu/node/out/Release/obj.target/node/src/node_crypto_bio.o /home/ubuntu/node/out/Release/obj.target/node/src/node_crypto_clienthello.o /home/ubuntu/node/out/Release/obj.target/node/src/tls_wrap.o /home/ubuntu/node/out/Release/obj.target/node/src/backtrace_posix.o /home/ubuntu/node/out/Release/obj.target/deps/v8/tools/gyp/libv8_libplatform.a /home/ubuntu/node/out/Release/obj.target/deps/openssl/libopenssl.a /home/ubuntu/node/out/Release/obj.target/deps/zlib/libzlib.a /home/ubuntu/node/out/Release/obj.target/deps/http_parser/libhttp_parser.a /home/ubuntu/node/out/Release/obj.target/deps/cares/libcares.a /home/ubuntu/node/out/Release/obj.target/deps/uv/libuv.a /home/ubuntu/node/out/Release/obj.target/deps/v8/tools/gyp/libv8_base.a /home/ubuntu/node/out/Release/obj.target/deps/v8/tools/gyp/libv8_libbase.a /home/ubuntu/node/out/Release/obj.target/deps/v8/tools/gyp/libv8_nosnapshot.a -Wl,--no-whole-archive -lm -ldl -llog
/home/ubuntu/node/android-toolchain/bin/../sysroot/usr/lib/crtbegin_dynamic.o:crtbrand.c:function _start: error: undefined reference to 'main'
collect2: error: ld returned 1 exit status
make[1]: *** [/home/ubuntu/node/out/Release/obj.target/libnode.so.48] Error 1
make[1]: Leaving directory `/home/ubuntu/node/out'
make: *** [node] Error 2 |
It seems like this might not be the right place to report this issue. Should I open a new issue? |
Is there any active work going on with this? If not, maybe a |
Thanks for your build script. It was one of the few working ones I found. It compiled Node `7.10.1` (using ndk r15 latest) successfully. It does not compile Node as shared library unfortunately. One addition to the script that was necessary however, was undefining `HAVE_GETSERVBYPORT_R` (taken from @gartner build script in nodejs/node#10341 (comment))
This seems stalled out hard so I'm going to close, but if anyone wants to work on it or otherwise feels it should remain open, by all means re-open or comment asking that it be re-opened (if GitHub won't let you re-open it yourself). |
This is meant as tracking issue:
There have been a number of efforts made and issues opened (nodejs/build#359, #6876, #6521, nodejs/roadmap#9, #6994) to make Android support possible. Also, some efforts of
electron
code maybe be upstreamed, but likely their maintainers have not enough time to work on it, if it would make sense anyhow.I am gonna collect issues and infos centrally here, will also work on it a little and hopefully see some some support from Core once this sees some efforts.
I am starting this after having conversation on Twitter with @dominictarr @Fishrock123 https://twitter.com/dominictarr/status/810886786830467072?cn=cmVwbHk%3D
Possible Steps
main
as APIThe text was updated successfully, but these errors were encountered: