Skip to content

Commit 930f074

Browse files
committed
Add a bit of logging
1 parent 1ec9d9c commit 930f074

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

android/src/main/cpp/cpp-adapter.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct MultithreadingModule : jni::JavaClass<MultithreadingModule> {
2020
public:
2121
__unused static constexpr auto kJavaDescriptor = "Lcom/reactnativemultithreading/MultithreadingModule;";
2222

23+
static constexpr auto TAG = "RNMultithreading";
2324

2425
static void registerNatives() {
2526
javaClassStatic()->registerNatives({
@@ -32,10 +33,11 @@ struct MultithreadingModule : jni::JavaClass<MultithreadingModule> {
3233
static std::shared_ptr<react::JSExecutorFactory> makeJSExecutorFactory() {
3334
ThreadScope scope; // JNI needs to attach this thread because this function is being called from a different Thread
3435

35-
__android_log_write(ANDROID_LOG_DEBUG, "RNMultithreading", "Calling Java method MultithreadingModule.makeJSExecutor()...");
36+
__android_log_write(ANDROID_LOG_INFO, TAG, "Calling Java method MultithreadingModule.makeJSExecutor()...");
3637
static const auto cls = javaClassStatic();
3738
static const auto method = cls->getStaticMethod<react::JavaScriptExecutorHolder()>("makeJSExecutor");
3839
auto result = method(cls);
40+
__android_log_write(ANDROID_LOG_INFO, TAG, "JavaScriptExecutor created! Getting factory...");
3941
return result->cthis()->getExecutorFactory();
4042
}
4143

@@ -57,16 +59,22 @@ struct MultithreadingModule : jni::JavaClass<MultithreadingModule> {
5759
return std::make_shared<reanimated::AndroidErrorHandler>(scheduler_);
5860
};
5961
auto makeJsExecutor = []() -> std::unique_ptr<jsi::Runtime> {
60-
__android_log_write(ANDROID_LOG_DEBUG, "RNMultithreading", "Creating JSExecutor..");
61-
std::shared_ptr<react::ExecutorDelegate> delegate = std::shared_ptr<react::ExecutorDelegate>();
62-
std::shared_ptr<react::MessageQueueThread> jsQueue = std::shared_ptr<react::MessageQueueThread>();
63-
auto jsExecutorFactory = makeJSExecutorFactory();
64-
auto executor = jsExecutorFactory->createJSExecutor(delegate, jsQueue);
65-
auto runtimePointer = static_cast<jsi::Runtime*>(executor->getJavaScriptContext());
66-
__android_log_write(ANDROID_LOG_DEBUG, "RNMultithreading", "JSExecutor created!");
67-
std::unique_ptr<jsi::Runtime> runtime;
68-
runtime.reset(runtimePointer);
69-
return runtime;
62+
__android_log_write(ANDROID_LOG_DEBUG, TAG, "Creating JSExecutorFactory..");
63+
try {
64+
std::shared_ptr<react::ExecutorDelegate> delegate = std::shared_ptr<react::ExecutorDelegate>();
65+
std::shared_ptr<react::MessageQueueThread> jsQueue = std::shared_ptr<react::MessageQueueThread>();
66+
auto jsExecutorFactory = makeJSExecutorFactory();
67+
__android_log_write(ANDROID_LOG_DEBUG, TAG, "Creating JSExecutor..");
68+
auto executor = jsExecutorFactory->createJSExecutor(delegate,
69+
jsQueue);
70+
auto runtimePointer = static_cast<jsi::Runtime *>(executor->getJavaScriptContext());
71+
__android_log_write(ANDROID_LOG_DEBUG, TAG, "JSExecutor created!");
72+
return std::unique_ptr<jsi::Runtime>(runtimePointer);
73+
} catch (std::exception& exc) {
74+
__android_log_write(ANDROID_LOG_ERROR, TAG, "Failed to create JSExecutor!");
75+
__android_log_write(ANDROID_LOG_ERROR, TAG, exc.what());
76+
return std::unique_ptr<jsi::Runtime>(); // TODO: Remove this and let the caller handle the exception.
77+
}
7078
};
7179
mrousavy::multithreading::install(*runtime, makeJsExecutor, makeScheduler, makeErrorHandler);
7280

android/src/main/java/com/reactnativemultithreading/MultithreadingModule.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.reactnativemultithreading;
22

3+
import android.util.Log;
4+
35
import androidx.annotation.Keep;
46
import androidx.annotation.NonNull;
57

@@ -24,6 +26,8 @@ public class MultithreadingModule extends ReactContextBaseJavaModule {
2426
System.loadLibrary("rnmultithreading");
2527
}
2628

29+
static String TAG = "RNMultithreading";
30+
2731
// Dummy so react native adds it to the Gradle Module System
2832
public MultithreadingModule(ReactApplicationContext context) {
2933
super(context);
@@ -32,7 +36,7 @@ public MultithreadingModule(ReactApplicationContext context) {
3236
@NonNull
3337
@Override
3438
public String getName() {
35-
return "RNMultithreading";
39+
return TAG;
3640
}
3741

3842
private static native void installNative(long jsiRuntimePointer,
@@ -49,10 +53,13 @@ public static void install(ReactApplicationContext context, JavaScriptContextHol
4953
// Called from the C++ code
5054
@SuppressWarnings({"unused", "RedundantSuppression"})
5155
public static JavaScriptExecutor makeJSExecutor() {
56+
Log.i(TAG, "Creating JavaScriptExecutorFactory...");
5257
JavaScriptExecutorFactory factory = makeJSExecutorFactory();
5358
try {
59+
Log.i(TAG, "Factory created! Creating JavaScriptExecutor...");
5460
return factory.create();
5561
} catch (Exception e) {
62+
Log.e(TAG, "Failed to create JavaScriptExecutor!");
5663
e.printStackTrace();
5764
return null;
5865
}
@@ -61,6 +68,7 @@ public static JavaScriptExecutor makeJSExecutor() {
6168
// method from React native
6269
public static JavaScriptExecutorFactory makeJSExecutorFactory() {
6370
try {
71+
Log.i(TAG, "Trying to create JSC Factory...");
6472
SoLoader.loadLibrary("jscexecutor");
6573
return new JSCExecutorFactory("Multithreading", "Multithreading");
6674
} catch (UnsatisfiedLinkError jscE) {
@@ -79,6 +87,7 @@ public static JavaScriptExecutorFactory makeJSExecutorFactory() {
7987

8088
// Otherwise use Hermes
8189
try {
90+
Log.i(TAG, "Trying to create Hermes Factory...");
8291
return new HermesExecutorFactory();
8392
} catch (UnsatisfiedLinkError hermesE) {
8493
// If we get here, either this is a JSC build, and of course

0 commit comments

Comments
 (0)