Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

node: Add support for android #5514

Closed

Conversation

linusmartensson
Copy link

Adds an ANDROID define and resolves minor discrepancies between
android and standard POSIX systems. In addition, some configure
parameters were added, and a helper-script for android configuration.
Ideally, this script should next be merged into the standard
configure script.

Note: This depends on the respective pull-requests in uv and cares:
joyent/libuv#825
https://github.com/piscisaureus/cares/pull/2

To build for android, source the android-configure script
with an NDK path:

source ./android-configure ~/android-ndk-r8d

This will create an android standalone toolchain and export the
necessary commands.

After that, build as normal:

make -j8

After the build, you should now have android-compatible NodeJS
binaries.

@Nodejs-Jenkins
Copy link

Thank you for contributing this pull request! Here are a few pointers to make sure your submission will be considered for inclusion.

The following commiters were not found in the CLA:

  • Linus Mårtensson

Please see CONTRIBUTING.md for more information

@linusmartensson
Copy link
Author

Resolved the issue that had me closing the pull request. Sorry for the confusion.

@bnoordhuis
Copy link
Member

/cc @isaacs - apparently the CLA is in your inbox.

@linusmartensson
Copy link
Author

Will update this PR with renamed defines and a new PR dependency in libuv tomorrow. Please hold. :)
Edit: Done!

'cflags_cc': [ '-fno-rtti', '-fno-exceptions' ],
'ldflags': [ '-pthread', '-rdynamic' ],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't remove -pthread. Either special-case this or add an android-specific fix-up:

['OS=="android"', {
  'ldflags!': ['-pthread']  # remove -pthread from linker flags
}]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? It's on line 166?

Resolves minor discrepancies between android and standard
POSIX systems. In addition, some configure parameters were
added, and a helper-script for android configuration.
Ideally, this script should be merged into the standard
configure script.

To build for android, source the android-configure script
with an NDK path:

> source ./android-configure ~/android-ndk-r8d

This will create an android standalone toolchain and export the
necessary environment parameters.

After that, build as normal:

> make -j8

After the build, you should now have android-compatible NodeJS
binaries.
@bnoordhuis
Copy link
Member

Thanks Linus, landed with some nudging in 5e4e8ec.

@feichh
Copy link

feichh commented Jun 18, 2013

since this has landed, I want to raise an issue I encountered:
linusmartensson@187f303#commitcomment-3376196

@Mithgol
Copy link

Mithgol commented Jun 28, 2013

So will this merged pull request ever be some foundation of bringing Node.js to Android?

I hope someone is going to at least discuss it around Walker Creek Ranch.

@linusmartensson
Copy link
Author

Well, with this patch you should be able to build node as an android
compatible executable today. Anything specific you're after?
Den 28 jun 2013 08:38 skrev "Mithgol" notifications@github.com:

So will this merged pull request ever be some foundation of bringing
Node.js to Android?

I hope someone is going to at least discuss it around Walker Creek Ranch.


Reply to this email directly or view it on GitHubhttps://github.com//pull/5514#issuecomment-20172753
.

@Mithgol
Copy link

Mithgol commented Jun 28, 2013

Just several questions:

  • Is someone going to make and distribute regular builds of Node for Android when new minor versions of Node.js come out? (Some node.apk files?)
  • How does Node behave on Android?
    • Could we get a REPL console out of it? (Does Android even have any concept of console applications? And if it does not, could a console be GUI-imitated?)
       
    • How do I run a JavaScript in a console and view its output? (Is it possible to associate Node on Android with .js files so that their shortcuts are run from Android's desktop as console applications?)
       
    • Should an Android device be rooted to run Node?
       
    • Could a Node-running JavaScript act as a continuously running Android service? (Such as scripts running with https://github.com/coreybutler/node-windows on Windows, with https://github.com/coreybutler/node-linux on Linux, with https://github.com/coreybutler/node-mac on Mac.)

@linusmartensson
Copy link
Author

Alright, I'm no authority on this, but I'll do my best to provide some info:

  • anode is the project closest to what you're looking for. I'm not sure how
    active it is today, but this feature should make it easier for them to stay
    up to date.
  • repl works if you can copy the binary to an executable location on your
    device. Most likely somewhere in the data partition, e.g. owned by an app
    and made world readable.
  • file associations work differently on android, but I think anode does
    something similar.
  • root should never be required. Ensure you have the right permissions on
    the user account starting node, and you're good to go.
  • you could create an android service which starts node and runs a script.
    The lifetime of this script will, afaik not be coupled to the lifetime of
    the android service.
    Den 28 jun 2013 13:35 skrev "Mithgol" notifications@github.com:

Just several questionshttps://github.com/joyent/node/commit/5e4e8ec#commitcomment-3455460
:

Is someone going to make and distribute regular builds of Node
for Android when new minor versions of Node.js come out? (Some node.apkfiles?)

How does Node behave on Android?
- Could we get a REPL console out of it? (Does Android even have
any concept of console applications?)

  - How do I run a JavaScript in a console and view its output?
  (Is it possible to associate Node on Android with .js files so that
  their shortcuts are run from Android's desktop as console applications?)

  - Should an Android device be rooted to run Node?

  - Could a Node-running JavaScript act as a continuously running
  Android service? (Such as scripts running with
  https://github.com/coreybutler/node-windows on Windows, with
  https://github.com/coreybutler/node-linux on Linux, with
  https://github.com/coreybutler/node-mac on Mac.)


Reply to this email directly or view it on GitHubhttps://github.com//pull/5514#issuecomment-20183371
.

@linusmartensson
Copy link
Author

@bnoordhuis I ran a test to ensure everything builds, and noticed the cares version is not up to date. After updating cares to the latest version, the build works fine.

@Mithgol Also did some testing to determine how to best get REPL access. The easiest solution is to copy node straight to /data/local/tmp.
The following nets you a REPL command line on a device with adb debugging enabled and a host ubuntu machine with NDK_PATH configured and the SDK correctly installed:
source ./android-configure $NDK_PATH && make -j8 && adb push node /data/local/tmp && adb shell
In your new terminal, simply exec:
/data/local/tmp/node and you should have REPL.

@bnoordhuis
Copy link
Member

Upgraded in 58e4eda.

@adammw
Copy link

adammw commented Nov 21, 2013

Trying to build node.js for android on a Linux system, and I'm getting an error about arpa/nameser_compat.h missing. Output > https://gist.github.com/adammw/e01236fb0a832a845221

Any hints?

@bnoordhuis
Copy link
Member

It's picking up the linux config for c-ares, not the android one. There's a separate android-configure script in the top-level directory.

@adammw
Copy link

adammw commented Nov 21, 2013

The android-configure script doesn't pick up the --system flag that's needed to make the toolchain on my system, so I have to run the commands in it manually. I think v0.10 doesn't work, whereas v0.11 appears to.

@feichh
Copy link

feichh commented Nov 25, 2013

you can just add the --system flag yourself.
check out my fork for an unofficial backport to 0.10
https://github.com/feichh/node/tree/v0.10-android

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants