-
Notifications
You must be signed in to change notification settings - Fork 15
Add Android support #4
base: master
Are you sure you want to change the base?
Changes from all commits
adbb56f
c58cc41
898df8f
5fe7048
6f16c01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,4 @@ buck-out/ | |
|
||
# Bundle artifact | ||
*.jsbundle | ||
android/app/.externalNativeBuild |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# For more information about using CMake with Android Studio, read the | ||
# documentation: https://d.android.com/studio/projects/add-native-code.html | ||
|
||
# Sets the minimum version of CMake required to build the native library. | ||
|
||
cmake_minimum_required(VERSION 3.4.1) | ||
|
||
# Creates and names a library, sets it as either STATIC | ||
# or SHARED, and provides the relative paths to its source code. | ||
# You can define multiple libraries, and CMake builds them for you. | ||
# Gradle automatically packages shared libraries with your APK. | ||
|
||
# Needed to locate double-conversion src correctly for folly includes | ||
execute_process (COMMAND ln "-s" "src" "../../node_modules/react-native/third-party/double-conversion-1.1.6/double-conversion") | ||
|
||
include_directories( | ||
../../node_modules/react-native/React | ||
../../node_modules/react-native/React/Base | ||
../../node_modules/react-native/ReactCommon | ||
../../node_modules/react-native/third-party/folly-2018.10.22.00 | ||
../../node_modules/react-native/third-party/double-conversion-1.1.6 | ||
../../node_modules/react-native/third-party/boost_1_63_0 | ||
../../node_modules/react-native/third-party/glog-0.3.5/src | ||
) | ||
|
||
add_definitions( | ||
-DFOLLY_USE_LIBCPP=1 | ||
-DFOLLY_NO_CONFIG=1 | ||
-DFOLLY_HAVE_MEMRCHR=1 | ||
) | ||
|
||
add_library( # Sets the name of the library. | ||
test_module_jni | ||
|
||
# Sets the library as a shared library. | ||
SHARED | ||
|
||
# Provides a relative path to your source file(s). | ||
../../node_modules/react-native/ReactCommon/jsi/jsi.cpp | ||
../../c++/Test.cpp | ||
../../c++/TestBinding.cpp) | ||
|
||
target_link_libraries(test_module_jni | ||
android | ||
log) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
#include "TestBinding.h" | ||
|
||
#include "Test.h" | ||
#include <jsi/JSIDynamic.h> | ||
|
||
#if ANDROID | ||
extern "C" | ||
{ | ||
JNIEXPORT void JNICALL | ||
Java_com_testmodule_MainActivity_install(JNIEnv* env, jobject thiz, jlong runtimePtr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In React native's case, you can use fbjni, which helps out with types i nJNI. Check out TurboModuleManager.cpp. This code is similar to what we do there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is where I copied it from, I think – or are you suggesting using |
||
{ | ||
auto test = std::make_unique<facebook::react::Test>(); | ||
auto testBinding = std::make_shared<facebook::react::TestBinding>(std::move(test)); | ||
jsi::Runtime* runtime = (jsi::Runtime*)runtimePtr; | ||
|
||
example::TestBinding::install(*runtime, testBinding); | ||
} | ||
} | ||
#endif | ||
|
||
namespace example { | ||
|
||
static jsi::Object getModule( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,8 +36,8 @@ | |
2D16E6881FA4F8E400B85C8A /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D16E6891FA4F8E400B85C8A /* libReact.a */; }; | ||
2DCD954D1E0B4F2C00145EB5 /* TestModuleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* TestModuleTests.m */; }; | ||
2DF0FFEE2056DD460020B375 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3EA31DF850E9000B6D8A /* libReact.a */; }; | ||
68E307DC2262762A00B130DF /* TestBinding.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 68E307DA2262762A00B130DF /* TestBinding.cpp */; }; | ||
68E3080C2262781F00B130DF /* Test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 68E3080A2262781F00B130DF /* Test.cpp */; }; | ||
736B0C4F228AB89E000DC273 /* TestBinding.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 736B0C4B228AB89D000DC273 /* TestBinding.cpp */; }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also curious why the xcode project changed here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. file moved: ios/TestBinding.cpp → c++/TestBinding.cpp There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, sorry I missed your message @axemclion! |
||
736B0C50228AB89E000DC273 /* Test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 736B0C4D228AB89D000DC273 /* Test.cpp */; }; | ||
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; | ||
ADBDB9381DFEBF1600ED6528 /* libRCTBlob.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADBDB9271DFEBF0700ED6528 /* libRCTBlob.a */; }; | ||
ED297163215061F000B7C4FE /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED297162215061F000B7C4FE /* JavaScriptCore.framework */; }; | ||
|
@@ -344,10 +344,10 @@ | |
2D02E4901E0B4A5D006451C7 /* TestModule-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "TestModule-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; | ||
2D16E6891FA4F8E400B85C8A /* libReact.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libReact.a; sourceTree = BUILT_PRODUCTS_DIR; }; | ||
5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = "<group>"; }; | ||
68E307DA2262762A00B130DF /* TestBinding.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TestBinding.cpp; sourceTree = "<group>"; }; | ||
68E307DB2262762A00B130DF /* TestBinding.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestBinding.h; sourceTree = "<group>"; }; | ||
68E3080A2262781F00B130DF /* Test.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Test.cpp; sourceTree = "<group>"; }; | ||
68E3080B2262781F00B130DF /* Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Test.h; sourceTree = "<group>"; }; | ||
736B0C4B228AB89D000DC273 /* TestBinding.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestBinding.cpp; sourceTree = "<group>"; }; | ||
736B0C4C228AB89D000DC273 /* TestBinding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestBinding.h; sourceTree = "<group>"; }; | ||
736B0C4D228AB89D000DC273 /* Test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Test.cpp; sourceTree = "<group>"; }; | ||
736B0C4E228AB89D000DC273 /* Test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Test.h; sourceTree = "<group>"; }; | ||
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; }; | ||
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; }; | ||
ADBDB91F1DFEBF0600ED6528 /* RCTBlob.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTBlob.xcodeproj; path = "../node_modules/react-native/Libraries/Blob/RCTBlob.xcodeproj"; sourceTree = "<group>"; }; | ||
|
@@ -493,17 +493,14 @@ | |
13B07FAE1A68108700A75B9A /* TestModule */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
736B0C4A228AB89D000DC273 /* c++ */, | ||
008F07F21AC5B25A0029DE68 /* main.jsbundle */, | ||
13B07FAF1A68108700A75B9A /* AppDelegate.h */, | ||
13B07FB01A68108700A75B9A /* AppDelegate.m */, | ||
13B07FB51A68108700A75B9A /* Images.xcassets */, | ||
13B07FB61A68108700A75B9A /* Info.plist */, | ||
13B07FB11A68108700A75B9A /* LaunchScreen.xib */, | ||
13B07FB71A68108700A75B9A /* main.m */, | ||
68E307DA2262762A00B130DF /* TestBinding.cpp */, | ||
68E307DB2262762A00B130DF /* TestBinding.h */, | ||
68E3080A2262781F00B130DF /* Test.cpp */, | ||
68E3080B2262781F00B130DF /* Test.h */, | ||
); | ||
name = TestModule; | ||
sourceTree = "<group>"; | ||
|
@@ -550,6 +547,18 @@ | |
name = Products; | ||
sourceTree = "<group>"; | ||
}; | ||
736B0C4A228AB89D000DC273 /* c++ */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
736B0C4B228AB89D000DC273 /* TestBinding.cpp */, | ||
736B0C4C228AB89D000DC273 /* TestBinding.h */, | ||
736B0C4D228AB89D000DC273 /* Test.cpp */, | ||
736B0C4E228AB89D000DC273 /* Test.h */, | ||
); | ||
name = "c++"; | ||
path = "../c++"; | ||
sourceTree = "<group>"; | ||
}; | ||
78C398B11ACF4ADC00677621 /* Products */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
|
@@ -709,6 +718,8 @@ | |
CreatedOnToolsVersion = 6.2; | ||
TestTargetID = 13B07F861A680F5B00A75B9A; | ||
}; | ||
13B07F861A680F5B00A75B9A = { | ||
}; | ||
2D02E47A1E0B4A5D006451C7 = { | ||
CreatedOnToolsVersion = 8.2.1; | ||
ProvisioningStyle = Automatic; | ||
|
@@ -1132,8 +1143,8 @@ | |
isa = PBXSourcesBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
68E307DC2262762A00B130DF /* TestBinding.cpp in Sources */, | ||
68E3080C2262781F00B130DF /* Test.cpp in Sources */, | ||
736B0C4F228AB89E000DC273 /* TestBinding.cpp in Sources */, | ||
736B0C50228AB89E000DC273 /* Test.cpp in Sources */, | ||
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */, | ||
13B07FC11A68108700A75B9A /* main.m in Sources */, | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internally also, this is where we install the JSI Modules.
If you are just exposing native methods, why not use React Native's TurboModuleManager - whose intenet is pretty much that ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I wasn’t sure if TurboModules were ready to use or not! If they are it would be awesome to see an example of how to use them :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@axemclion could you please provide an example on how to use turbo modules in that case?