Skip to content

Commit

Permalink
android: update native-gradle to mobile v0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimecbernardo committed Oct 31, 2017
1 parent 113959e commit 74c28a6
Show file tree
Hide file tree
Showing 139 changed files with 66,404 additions and 25 deletions.
23 changes: 10 additions & 13 deletions android/native-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The sample app runs the node.js engine in a background thread to start an HTTP s

## How to run
- Clone this project.
- Download the Node.js on Mobile shared library from [here](https://github.com/janeasystems/nodejs-mobile/releases/download/nodejs-mobile-v0.1.2/nodejs-mobile-v0.1.2-android.zip).
- Download the Node.js on Mobile shared library from [here](https://github.com/janeasystems/nodejs-mobile/releases/download/nodejs-mobile-v0.1.3/nodejs-mobile-v0.1.3-android.zip).
- Copy the `bin/` folder from inside the downloaded zip file to `app/libnode/bin` (There are `copy-libnode.so-here` files in each architecture's path for convenience). If it's been done correctly you'll end with the following paths for the binaries:
- `app/libnode/bin/arm64-v8a/libnode.so`
- `app/libnode/bin/armeabi-v7a/libnode.so`
Expand Down Expand Up @@ -34,20 +34,17 @@ Using the Android Studio's New Project wizard, create a new Project with the fol
- `Runtime TYpe Information Support (-frtti)` checked off
1. Finish

### Create node.h
### Copy libnode's header files

To access libnode's `Start()` entrypoint, a header file is required.
Create a `node.h` file in the `cpp` folder (`app/src/main/cpp/`) with the following content:
To access libnode's `Start()` entrypoint, the libnode's header files are required.

```h
#ifndef SRC_NODE_H_
#define SRC_NODE_H_
Create the `libnode/` folder inside the project's `app/` folder. Copy the `include/` folder from inside the [downloaded zip file](https://github.com/janeasystems/nodejs-mobile/releases/download/nodejs-mobile-v0.1.3/nodejs-mobile-v0.1.3-android.zip) to `app/libnode/include`. If it's been done correctly you'll end with the following path for the `node.h` header file:
- `app/libnode/include/node/node.h`

namespace node {
int Start(int argc, char *argv[]);
}
#endif // SRC_NODE_H_
```
In `app/CMakeLists.txt` add the following line to add libnode's header files to the CMake include paths:
```CMake
include_directories(libnode/include/node/)
```

### Add native JNI function to start node.js

Expand Down Expand Up @@ -240,7 +237,7 @@ Since the app runs an HTTP server, it requires the right permissions in `app/src

#### Copy the `libnode.so` binaries to the project structure:

Create the `libnode/` folder inside the project's `app/` folder. Copy the `bin/` folder from inside the [downloaded zip file](https://github.com/janeasystems/nodejs-mobile/releases/download/nodejs-mobile-v0.1.2/nodejs-mobile-v0.1.2-android.zip) to `app/libnode/bin`. If it's been done correctly you'll end with the following paths for the binaries:
Copy the `bin/` folder from inside the [downloaded zip file](https://github.com/janeasystems/nodejs-mobile/releases/download/nodejs-mobile-v0.1.3/nodejs-mobile-v0.1.3-android.zip) to `app/libnode/bin`. If it's been done correctly you'll end with the following paths for the binaries:
- `app/libnode/bin/arm64-v8a/libnode.so`
- `app/libnode/bin/armeabi-v7a/libnode.so`
- `app/libnode/bin/x86/libnode.so`
Expand Down
4 changes: 3 additions & 1 deletion android/native-gradle/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ add_library( # Sets the name of the library.
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )


#Includes node's header files.
include_directories(libnode/include/node/)

add_library( libnode
SHARED
IMPORTED )
Expand Down
54 changes: 54 additions & 0 deletions android/native-gradle/app/libnode/include/node/android-ifaddrs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 1995, 1999
* Berkeley Software Design, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp
*/

#ifndef _IFADDRS_H_
#define _IFADDRS_H_

struct ifaddrs {
struct ifaddrs *ifa_next;
char *ifa_name;
unsigned int ifa_flags;
struct sockaddr *ifa_addr;
struct sockaddr *ifa_netmask;
struct sockaddr *ifa_dstaddr;
void *ifa_data;
};

/*
* This may have been defined in <net/if.h>. Note that if <net/if.h> is
* to be included it must be included before this header file.
*/
#ifndef ifa_broadaddr
#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
#endif

#include <sys/cdefs.h>

__BEGIN_DECLS
extern int getifaddrs(struct ifaddrs **ifap);
extern void freeifaddrs(struct ifaddrs *ifa);
__END_DECLS

#endif
Loading

0 comments on commit 74c28a6

Please sign in to comment.