Add jni target to ReactCxxPlatform (#51898)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51898

changelog: [internal]

Reviewed By: andrewdacenko

Differential Revision: D76240376

fbshipit-source-id: bbae620dde69261e6d26d088471601e7d7e9a074
This commit is contained in:
Christoph Purrer
2025-06-09 19:15:47 -07:00
committed by Facebook GitHub Bot
parent 89cb7ea600
commit 43ba9df55f
2 changed files with 47 additions and 0 deletions
@@ -0,0 +1,28 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <fbjni/Context.h>
#include <fbjni/fbjni.h>
namespace facebook::react {
jobject getApplication(JNIEnv* env) {
auto activityThreadClass = env->FindClass("android/app/ActivityThread");
auto currentApplicationMethodID = env->GetStaticMethodID(
activityThreadClass, "currentApplication", "()Landroid/app/Application;");
return env->CallStaticObjectMethod(
activityThreadClass, currentApplicationMethodID);
}
jni::alias_ref<jni::AContext> getContext() {
auto env = facebook::jni::Environment::ensureCurrentThreadIsAttached();
auto application = getApplication(env);
return facebook::jni::wrap_alias(
static_cast<facebook::jni::AContext::javaobject>(application));
}
} // namespace facebook::react
@@ -0,0 +1,19 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <fbjni/Context.h>
#include <fbjni/fbjni.h>
namespace facebook::react {
jobject getApplication(JNIEnv* env);
jni::alias_ref<jni::AContext> getContext();
} // namespace facebook::react