How to register C++ React Native module in Android
up vote
21
down vote
favorite
I have a C++ React Native module derived from facebook::xplat::module::CxxModule. It is working ok with iOS project but now I'm trying to figure out how to use it from Java. The only documentation I found is the comment in React Native codebase stating that:
NativeModules whose implementation is written in C++ must
not provide any Java code (so they can be reused on other platforms),
and instead should register themselves using
CxxModuleWrapper
My question is how to register C++ module in Java using CxxModuleWrapper
java
add a comment |
up vote
21
down vote
favorite
I have a C++ React Native module derived from facebook::xplat::module::CxxModule. It is working ok with iOS project but now I'm trying to figure out how to use it from Java. The only documentation I found is the comment in React Native codebase stating that:
NativeModules whose implementation is written in C++ must
not provide any Java code (so they can be reused on other platforms),
and instead should register themselves using
CxxModuleWrapper
My question is how to register C++ module in Java using CxxModuleWrapper
java
2
"Your question really is how to call C++ from javascript without calling java I suspect (if possible)?" - No, I can just use JNI and call any C++ library easily, the problem here is that I will need to do all data conversion and will have to implement all the callbacks and promises to communicate with JS side. This could be avoided using C++ module inherited fromfacebook::xplat::module::CxxModule. I have such a module and I can use it from Objective C but not from Java
– bjornd
Jun 15 at 16:38
Can you use some tool to generate bindings, like this
– Raviprakash
Jun 18 at 17:47
add a comment |
up vote
21
down vote
favorite
up vote
21
down vote
favorite
I have a C++ React Native module derived from facebook::xplat::module::CxxModule. It is working ok with iOS project but now I'm trying to figure out how to use it from Java. The only documentation I found is the comment in React Native codebase stating that:
NativeModules whose implementation is written in C++ must
not provide any Java code (so they can be reused on other platforms),
and instead should register themselves using
CxxModuleWrapper
My question is how to register C++ module in Java using CxxModuleWrapper
java
I have a C++ React Native module derived from facebook::xplat::module::CxxModule. It is working ok with iOS project but now I'm trying to figure out how to use it from Java. The only documentation I found is the comment in React Native codebase stating that:
NativeModules whose implementation is written in C++ must
not provide any Java code (so they can be reused on other platforms),
and instead should register themselves using
CxxModuleWrapper
My question is how to register C++ module in Java using CxxModuleWrapper
java
java
asked Jun 10 at 7:44
bjornd
17.3k44365
17.3k44365
2
"Your question really is how to call C++ from javascript without calling java I suspect (if possible)?" - No, I can just use JNI and call any C++ library easily, the problem here is that I will need to do all data conversion and will have to implement all the callbacks and promises to communicate with JS side. This could be avoided using C++ module inherited fromfacebook::xplat::module::CxxModule. I have such a module and I can use it from Objective C but not from Java
– bjornd
Jun 15 at 16:38
Can you use some tool to generate bindings, like this
– Raviprakash
Jun 18 at 17:47
add a comment |
2
"Your question really is how to call C++ from javascript without calling java I suspect (if possible)?" - No, I can just use JNI and call any C++ library easily, the problem here is that I will need to do all data conversion and will have to implement all the callbacks and promises to communicate with JS side. This could be avoided using C++ module inherited fromfacebook::xplat::module::CxxModule. I have such a module and I can use it from Objective C but not from Java
– bjornd
Jun 15 at 16:38
Can you use some tool to generate bindings, like this
– Raviprakash
Jun 18 at 17:47
2
2
"Your question really is how to call C++ from javascript without calling java I suspect (if possible)?" - No, I can just use JNI and call any C++ library easily, the problem here is that I will need to do all data conversion and will have to implement all the callbacks and promises to communicate with JS side. This could be avoided using C++ module inherited from
facebook::xplat::module::CxxModule. I have such a module and I can use it from Objective C but not from Java– bjornd
Jun 15 at 16:38
"Your question really is how to call C++ from javascript without calling java I suspect (if possible)?" - No, I can just use JNI and call any C++ library easily, the problem here is that I will need to do all data conversion and will have to implement all the callbacks and promises to communicate with JS side. This could be avoided using C++ module inherited from
facebook::xplat::module::CxxModule. I have such a module and I can use it from Objective C but not from Java– bjornd
Jun 15 at 16:38
Can you use some tool to generate bindings, like this
– Raviprakash
Jun 18 at 17:47
Can you use some tool to generate bindings, like this
– Raviprakash
Jun 18 at 17:47
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Please check this blog for detail: https://medium.com/@kudochien/how-to-write-a-react-native-cxxmodule-59073259f15d.
Snippet from the blog:
Export it from native
extern "C" HelloCxxModule* createHelloCxxModule() {
return new HelloCxxModule();
}
Register it in java
public final class HelloCxxPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(
// I have librnpackage-hellocxx.so the exported createHelloCxxModule() above.
CxxModuleWrapper.makeDso("rnpackage-hellocxx", "createHelloCxxModule")
);
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Please check this blog for detail: https://medium.com/@kudochien/how-to-write-a-react-native-cxxmodule-59073259f15d.
Snippet from the blog:
Export it from native
extern "C" HelloCxxModule* createHelloCxxModule() {
return new HelloCxxModule();
}
Register it in java
public final class HelloCxxPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(
// I have librnpackage-hellocxx.so the exported createHelloCxxModule() above.
CxxModuleWrapper.makeDso("rnpackage-hellocxx", "createHelloCxxModule")
);
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
add a comment |
up vote
0
down vote
Please check this blog for detail: https://medium.com/@kudochien/how-to-write-a-react-native-cxxmodule-59073259f15d.
Snippet from the blog:
Export it from native
extern "C" HelloCxxModule* createHelloCxxModule() {
return new HelloCxxModule();
}
Register it in java
public final class HelloCxxPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(
// I have librnpackage-hellocxx.so the exported createHelloCxxModule() above.
CxxModuleWrapper.makeDso("rnpackage-hellocxx", "createHelloCxxModule")
);
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
add a comment |
up vote
0
down vote
up vote
0
down vote
Please check this blog for detail: https://medium.com/@kudochien/how-to-write-a-react-native-cxxmodule-59073259f15d.
Snippet from the blog:
Export it from native
extern "C" HelloCxxModule* createHelloCxxModule() {
return new HelloCxxModule();
}
Register it in java
public final class HelloCxxPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(
// I have librnpackage-hellocxx.so the exported createHelloCxxModule() above.
CxxModuleWrapper.makeDso("rnpackage-hellocxx", "createHelloCxxModule")
);
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
Please check this blog for detail: https://medium.com/@kudochien/how-to-write-a-react-native-cxxmodule-59073259f15d.
Snippet from the blog:
Export it from native
extern "C" HelloCxxModule* createHelloCxxModule() {
return new HelloCxxModule();
}
Register it in java
public final class HelloCxxPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(
// I have librnpackage-hellocxx.so the exported createHelloCxxModule() above.
CxxModuleWrapper.makeDso("rnpackage-hellocxx", "createHelloCxxModule")
);
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
edited Nov 21 at 3:53
answered Nov 21 at 2:44
Geng Jiawen
4,0072526
4,0072526
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50781569%2fhow-to-register-c-react-native-module-in-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
"Your question really is how to call C++ from javascript without calling java I suspect (if possible)?" - No, I can just use JNI and call any C++ library easily, the problem here is that I will need to do all data conversion and will have to implement all the callbacks and promises to communicate with JS side. This could be avoided using C++ module inherited from
facebook::xplat::module::CxxModule. I have such a module and I can use it from Objective C but not from Java– bjornd
Jun 15 at 16:38
Can you use some tool to generate bindings, like this
– Raviprakash
Jun 18 at 17:47