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

Building node as a shared library for Android #3074

Closed
vroad opened this issue Sep 26, 2015 · 13 comments
Closed

Building node as a shared library for Android #3074

vroad opened this issue Sep 26, 2015 · 13 comments
Labels
build Issues and PRs related to build files or the CI.

Comments

@vroad
Copy link

vroad commented Sep 26, 2015

I couldn't get this to work on android.
First of all, I changed platform toolchain version from 21(Android 5.0?) to 9(Android 2.3) so that it would work on older devices.
Looking at its Changelog, it was changed to 21 to avoid issues with libuv, but library built for API 21 always fails to load on devices older than Android 5.0.
After changing it, the library builds, but doesn't load at all with this error:

E/AndroidRuntime(23716): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "getservbyport_r" referenced by "libnode.so"...

@bnoordhuis bnoordhuis added the build Issues and PRs related to build files or the CI. label Sep 26, 2015
@bnoordhuis
Copy link
Member

You'll have to figure out in what shared object getservbyport_r() lives and link to that at build time. It should show up in the output of ldd libnode.so afterwards (assuming ldd is available on android.)

Cross-referencing nodejs/roadmap#9.

@vroad
Copy link
Author

vroad commented Sep 26, 2015

Thanks, but ldd says it's not a dynamic executable...

@vroad
Copy link
Author

vroad commented Sep 26, 2015

Google told me that you can find that with readelf command, and I found that libnode.so only references 4 libraries:

  • liblog.so
  • libdl.so
  • libm.so
  • libc.so

"android-ndk-r10e/platforms/android-9/arch-arm/usr/lib/libc.so" has "getservbyport" but not "getservbyport_r". Is this the cause of this problem?
Loading libc manually didn't change the result.

@bnoordhuis
Copy link
Member

It should be part of libc but it was probably added after API level 9. You could try commenting out HAVE_GETSERVBYPORT_R in deps/cares/config/android/ares_config.h and rebuilding.

@vroad
Copy link
Author

vroad commented Sep 26, 2015

I tried commenting out that and it works now, thanks.

I checked expored symbols of libc.so from "android-ndk-r10e/platforms/android-21/arch-arm/usr/lib/libc.so", but it also only has "getservbyport". Where is this implemented?

@bnoordhuis
Copy link
Member

Good question. A quick grep through the AOSP tree suggests it's been in bionic since at least 4.0.4 / API level 15. Maybe it only gets compiled in conditionally.

@vroad
Copy link
Author

vroad commented Sep 28, 2015

Does that mean getservbyport_r doesn't work on most Android devices? Then should we disable that by default?
We may also need to default API version to 9. At least, we should say that you are building for API 21.

@bnoordhuis
Copy link
Member

We (and libuv) are not really in the business of supporting older Android versions, see e.g. ecb840c.

At least, we should say that you are building for API 21.

We do, more or less. You can see in android-configure how it builds with --platform=android-21.

@vroad
Copy link
Author

vroad commented Oct 23, 2015

What about getservbyport_r? Is this supported on all devices running Android 5.0 or later?

@bnoordhuis
Copy link
Member

I'd assume it is. An android developer forum is probably a better place to ask though.

@vroad
Copy link
Author

vroad commented Oct 24, 2015

I noticed that UnsatisfiedLinkError with getservbyport_r only occurs with shared node.
Something specific to Android's linker(/system/bin/linker), maybe?

I tested shared node on emulators without disabling getservbyport_r, and got same error on all configurations I tested. Even on Android 5.1 and 6.0.

@rvagg
Copy link
Member

rvagg commented Mar 22, 2016

I'm seeking some feedback about how Node.js is used on Android if anyone watching this thread would like to tell us about it: nodejs/build#359

@bnoordhuis
Copy link
Member

Closing, I don't think there is anything left to do here.

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.
Projects
None yet
Development

No branches or pull requests

3 participants