Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Add Android support #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tomduncalf
Copy link
Contributor

This PR adds Android support, by refactoring the existing module code into a shared location and adding the necessary CMake config, JNI method and Java call to install the JSI native module on Android.

There is one issue, which I have no idea how to solve: in debug mode, there are a load of exceptions of type SIGUSR1 which happen. If you just click "continue", the app still works, but it's a bit weird - perhaps someone involved in React and JSI could take a look at this PR and give their feedback?

@ericlewis
Copy link
Owner

@tomduncalf refactor this & I’ll merge! Unless you prefer it left open.

@tomduncalf
Copy link
Contributor Author

Done! Happy to merge it, but if you know anyone at Facebook who you could point in this direction to take a look at the exception I get in debug (and more generally if this is the right approach), that would be great :)


@Override
public void onReactContextInitialized(ReactContext context) {
install(context.getJavaScriptContextHolder().get());

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 ?

Copy link
Contributor Author

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 :)

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?

extern "C"
{
JNIEXPORT void JNICALL
Java_com_testmodule_MainActivity_install(JNIEnv* env, jobject thiz, jlong runtimePtr)

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 TurboModuleManager directly?

@@ -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 */; };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also curious why the xcode project changed here ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file moved: ios/TestBinding.cpp → c++/TestBinding.cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, sorry I missed your message @axemclion!

@drafish
Copy link

drafish commented Jan 7, 2020

Build failed with an exception

/Users/drafish/workspace/react-native-hostobject-demo/c++/TestBinding.cpp:12:46: error: no member named 'react' in namespace 'facebook'
        auto test = std::make_unique<facebook::react::Test>();
                                     ~~~~~~~~~~^
  /Users/drafish/workspace/react-native-hostobject-demo/c++/TestBinding.cpp:13:53: error: no member named 'react' in namespace 'facebook'
        auto testBinding = std::make_shared<facebook::react::TestBinding>(std::move(test));
                                            ~~~~~~~~~~^

replace facebook::react with example

BUILD SUCCESSFUL

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants