UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AndroidJava.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6
7#if USE_ANDROID_JNI
9#include <jni.h>
10
11/*
12Wrappers for Java classes.
13TODO: make function look up static? It doesn't matter for our case here (we only create one instance of the class ever)
14*/
16{
17 FName Name;
18 FName Signature;
19 jmethodID Method;
20};
21
23{
24public:
26
27 // !! All Java objects returned by JNI functions are local references.
28 FJavaClassObject(FName ClassName, const char* CtorSig, ...);
30 FJavaClassObject(const FJavaClassObject&) = delete;
32
33 FJavaClassObject& operator=(const FJavaClassObject&) = delete;
34
35 FJavaClassMethod GetClassMethod(const char* MethodName, const char* FuncSig);
36
37 // TODO: Define this for extra cases
38 template<typename ReturnType>
39 ReturnType CallMethod(FJavaClassMethod Method, ...);
40
42 {
43 return Object;
44 }
45
46 static FScopedJavaObject<jstring> GetJString(const FString& String);
47
48 static void VerifyException();
49
50protected:
51
54};
55
56template<>
57void FJavaClassObject::CallMethod<void>(FJavaClassMethod Method, ...);
58
59template<>
60bool FJavaClassObject::CallMethod<bool>(FJavaClassMethod Method, ...);
61
62template<>
63int FJavaClassObject::CallMethod<int>(FJavaClassMethod Method, ...);
64
65template<>
66jobject FJavaClassObject::CallMethod<jobject>(FJavaClassMethod Method, ...);
67
68template<>
69jobjectArray FJavaClassObject::CallMethod<jobjectArray>(FJavaClassMethod Method, ...);
70
71template<>
72int64 FJavaClassObject::CallMethod<int64>(FJavaClassMethod Method, ...);
73
74template<>
75FString FJavaClassObject::CallMethod<FString>(FJavaClassMethod Method, ...);
76
77template<>
78float FJavaClassObject::CallMethod<float>(FJavaClassMethod Method, ...);
79
80namespace UE::Jni
81{
82 template <typename T>
84 {
85 template <typename... TArgs>
86 TClassObject(const TArgs&... args)
87 : FJavaClassObject{Jni::Class<T>, *[this, &args...]
88 {
89 auto LocalObject = T::New(Jni::Class<T>, args...);
91 return LocalObject;
92 }()}
93 {
94 }
95 };
96}
97#endif
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition NameTypes.h:617
args
Definition TestServer.py:519