Skip to content
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

Closed
6 tasks
eljefedelrodeodeljefe opened this issue Dec 19, 2016 · 8 comments
Closed
6 tasks

build, api, docs: android support #10341

eljefedelrodeodeljefe opened this issue Dec 19, 2016 · 8 comments
Labels
build Issues and PRs related to build files or the CI. feature request Issues that request new features to be added to Node.js. help wanted Issues that need assistance from volunteers or PRs that need help to proceed.

Comments

@eljefedelrodeodeljefe
Copy link
Contributor

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

  • validate whether building is possible
  • (officially) document how to build
  • officially support build
  • running main as API
  • consider EventEmitter API to exchange strings in both directions
  • continue with iOS (technically)
  • Version:
  • Platform:
  • Subsystem: build, api, docs
@mscdex mscdex added build Issues and PRs related to build files or the CI. feature request Issues that request new features to be added to Node.js. labels Dec 19, 2016
@dominictarr
Copy link
Contributor

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.

@Fishrock123
Copy link
Contributor

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.

@mhdawson
Copy link
Member

mhdawson commented Jan 3, 2017

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.

@gardner
Copy link

gardner commented Jan 6, 2017

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 main():

/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

@gardner
Copy link

gardner commented Jan 6, 2017

It seems like this might not be the right place to report this issue. Should I open a new issue?

@Trott
Copy link
Member

Trott commented Jul 15, 2017

Is there any active work going on with this? If not, maybe a help wanted label? Should it remain open?

@aschrijver
Copy link

A help wanted would be nice. With a 7.10.1 build I get the same results as @gardner
#14783

@Trott Trott added the help wanted Issues that need assistance from volunteers or PRs that need help to proceed. label Aug 12, 2017
aschrijver added a commit to aschrijver/dna2oslab that referenced this issue Aug 12, 2017
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))
@Trott
Copy link
Member

Trott commented Jun 15, 2018

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).

@Trott Trott closed this as completed Jun 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. feature request Issues that request new features to be added to Node.js. help wanted Issues that need assistance from volunteers or PRs that need help to proceed.
Projects
None yet
Development

No branches or pull requests

8 participants