Skip to content

Commit

Permalink
plugin: remove native modules detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimecbernardo committed Mar 5, 2018
1 parent 99f3400 commit 7780f20
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 50 deletions.
18 changes: 0 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,6 @@ To expedite the process of extracting the assets files, instead of parsing the a

Node modules can be added to the project using `npm install` inside `nodejs-assets/nodejs-project/`, as long as there's a `package.json` already present.

#### Native Modules

On Linux and macOS, there is experimental support for building modules that contain native code.

The plugin automatically detects native modules inside your `nodejs-project` folder by searching for `.gyp` files. It's recommended to have the build prerequisites mentioned in `nodejs-mobile` for [Android](https://github.com/janeasystems/nodejs-mobile#prerequisites-to-build-the-android-library-on-linux-ubuntudebian) and [iOS](https://github.com/janeasystems/nodejs-mobile#prerequisites-to-build-the-ios-framework-library-on-macos). For Android it's also recommended that you set the `ANDROID_NDK_HOME` environment variable in your system.

Building native modules for Android can take a long time, since it depends on building a standalone NDK toolchain for each required architecture. The resulting `.node` binaries are then included in the final application in a separate asset path for each architecture and the correct one will be chosen at runtime.

While the plugin tries to detect automatically the presence of native modules, there's a way to override this detection and turn the native modules build process on or off, by creating the `nodejs-assets/BUILD_NATIVE_MODULES.txt` and setting its contents to `1` or `0`, respectively. This can be used to start your application like this:
```sh
echo "1" > nodejs-assets/BUILD_NATIVE_MODULES.txt
react-native run-android
```
```sh
echo "1" > nodejs-assets/BUILD_NATIVE_MODULES.txt
react-native run-ios
```

### `React-Native` application

To communicate with Node.js from your `react-native` application, first import `nodejs-mobile-react-native`.
Expand Down
16 changes: 0 additions & 16 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,6 @@ if (shouldRebuildNativeModules==null) {
}
}

if (shouldRebuildNativeModules==null) {
// If build native modules preference is not set, try to find .gyp files to turn it on.
shouldRebuildNativeModules="0";
def gyp_files_tree = fileTree(
dir: "${rootProject.projectDir}/../nodejs-assets/nodejs-project",
include: "**/*.gyp"
);
gyp_files_tree.visit { gypFile ->
if (!gypFile.isDirectory()) {
// It's a .gyp file.
shouldRebuildNativeModules="1";
gypFile.stopVisiting();
}
}
}

if ("1".equals(shouldRebuildNativeModules)) {

String npmCommandName = 'npm';
Expand Down
16 changes: 0 additions & 16 deletions scripts/module-postlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,6 @@ NODEJS_ASSETS_DIR="$( cd "$PROJECT_DIR" && cd ../nodejs-assets/ && pwd )"
PREFERENCE_FILE_PATH="$NODEJS_ASSETS_DIR/BUILD_NATIVE_MODULES.txt"
if [ -f "$PREFERENCE_FILE_PATH" ]; then
NODEJS_MOBILE_BUILD_NATIVE_MODULES="$(cat $PREFERENCE_FILE_PATH | xargs)"
fi
fi
if [ -z "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then
# If build native modules preference is not set, try to find .gyp files
#to turn it on.
gypfiles=($(find "$CODESIGNING_FOLDER_PATH/nodejs-project/" -type f -name "*.gyp"))
if [ \${#gypfiles[@]} -gt 0 ]; then
NODEJS_MOBILE_BUILD_NATIVE_MODULES=1
else
NODEJS_MOBILE_BUILD_NATIVE_MODULES=0
fi
Expand Down Expand Up @@ -207,14 +199,6 @@ NODEJS_ASSETS_DIR="$( cd "$PROJECT_DIR" && cd ../nodejs-assets/ && pwd )"
PREFERENCE_FILE_PATH="$NODEJS_ASSETS_DIR/BUILD_NATIVE_MODULES.txt"
if [ -f "$PREFERENCE_FILE_PATH" ]; then
NODEJS_MOBILE_BUILD_NATIVE_MODULES="$(cat $PREFERENCE_FILE_PATH | xargs)"
fi
fi
if [ -z "$NODEJS_MOBILE_BUILD_NATIVE_MODULES" ]; then
# If build native modules preference is not set, try to find .gyp files
#to turn it on.
gypfiles=($(find "$CODESIGNING_FOLDER_PATH/nodejs-project/" -type f -name "*.gyp"))
if [ \${#gypfiles[@]} -gt 0 ]; then
NODEJS_MOBILE_BUILD_NATIVE_MODULES=1
else
NODEJS_MOBILE_BUILD_NATIVE_MODULES=0
fi
Expand Down

0 comments on commit 7780f20

Please sign in to comment.