How to register C++ React Native module in Android
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 android c++ react-native
add a comment |
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 android c++ react-native
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 |
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 android c++ react-native
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 android c++ react-native
java android c++ react-native
asked Jun 10 at 7:44
bjornd
17.5k44365
17.5k44365
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
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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,1552527
4,1552527
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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