Hi Guys,
Happy holidays.
I am stuck with an issue. I am working on a project that needs me to communicate with GameActivity.Java from C++. I am calling a blueprint, that calls a Java function through C++ using JNI. I am having problems even declaring JNI objects like JNIEnv and JavaVM. I am using MacOS to develop this project and I am not modifying any source code. I am developing a plugin and am putting all my code into that plugin and right now, I am writing the code for Android.
I am trying to something like this: https://answers.unrealengine.com/questions/412020/what-is-correct-and-present-method-of-packaging-a.html
I am attaching the following:
- Error Message
- My plugin’s build.cs file
- C++ Header File
- C++ source file
Thanks Again
**Here is my error message:
**
Recompiling UObjectPlugin...
Launching UnrealBuildTool... [/Users/Shared/UnrealEngine/4.13/Engine/Binaries/DotNET/UnrealBuildTool.exe MyProject -ModuleWithSuffix UObjectPlugin 1143 Mac Development -editorrecompile -canskiplink "/Users//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/MyProject.uproject" ]
CompilerResultsLog: New page: Compilation - Dec 1, 2016, 2:24:34 AM
CompilerResultsLog: Info
CompilerResultsLog: Info Running Mono...
CompilerResultsLog: Info
CompilerResultsLog: Info Setting up Mono
CompilerResultsLog: Info /Users/Shared/UnrealEngine/4.13/Engine /Users/Shared/UnrealEngine/4.13/Engine/Binaries/Mac
CompilerResultsLog: Info Compiling game modules for hot reload
CompilerResultsLog: Info Compiling with MacOSX SDK 10.12
CompilerResultsLog: Info Parsing headers for MyProjectEditor
CompilerResultsLog: Info Running UnrealHeaderTool "/Users//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/MyProject.uproject" "/Users//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Intermediate/Build/Mac/MyProjectEditor/Development/MyProjectEditor.uhtmanifest" -LogCmds="loginit warning, logexit warnin
g, logdatabase error" -Unattended -WarningsAsErrors -installed
CompilerResultsLog: Info Reflection code generated for MyProjectEditor in 6.6998022 seconds
CompilerResultsLog: Info Performing 3 actions (4 in parallel)
CompilerResultsLog: Info [1/3] Compile Module.UObjectPlugin.cpp
CompilerResultsLog: Info [2/3] Compile UObjectPlugin.generated.cpp
CompilerResultsLog: Info In file included from /Users//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Plugins/UObjectPlugin/Intermediate/Build/Mac/UE4Editor/Inc/UObjectPlugin/UObjectPlugin.generated.cpp:9:
CompilerResultsLog: Info In file included from ../../../../..//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Plugins/UObjectPlugin/Intermediate/Build/Mac/UE4Editor/Inc/UObjectPlugin/UObjectPlugin.generated.dep.h:9:
CompilerResultsLog: Info ../../../../..//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Plugins/UObjectPlugin/Source/UObjectPlugin/Classes/MyPluginObject.h:19:8: error: unknown type name 'JavaVM'
CompilerResultsLog: Info extern JavaVM *jvm;
CompilerResultsLog: Info ^
CompilerResultsLog: Info In file included from /Users//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Plugins/UObjectPlugin/Intermediate/Build/Mac/UE4Editor/Development/UObjectPlugin/Module.UObjectPlugin.cpp:2:
CompilerResultsLog: Info In file included from /Users//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Plugins/UObjectPlugin/Source/UObjectPlugin/Private/MyPluginObject.cpp:4:
CompilerResultsLog: Info ../../../../..//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Plugins/UObjectPlugin/Source/UObjectPlugin/Classes/MyPluginObject.h:19:8: error: unknown type name 'JavaVM'
CompilerResultsLog: Info extern JavaVM *jvm;
CompilerResultsLog: Info ^
CompilerResultsLog: Info ../../../../..//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Plugins/UObjectPlugin/Source/UObjectPlugin/Classes/MyPluginObject.h:20:8: error: unknown type name 'JNIEnv'
CompilerResultsLog: Info extern JNIEnv *env;
CompilerResultsLog: Info ^
CompilerResultsLog: Info ../../../../..//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Plugins/UObjectPlugin/Source/UObjectPlugin/Classes/MyPluginObject.h:20:8: error: unknown type name 'JNIEnv'
CompilerResultsLog: Info extern JNIEnv *env;
CompilerResultsLog: Info ^
CompilerResultsLog: Info In file included from /Users//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Plugins/UObjectPlugin/Intermediate/Build/Mac/UE4Editor/Development/UObjectPlugin/Module.UObjectPlugin.cpp:2:
CompilerResultsLog: Info /Users//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Plugins/UObjectPlugin/Source/UObjectPlugin/Private/MyPluginObject.cpp:32:2: error: unknown type name 'JavaVM'
CompilerResultsLog: Info JavaVM *jvm;
CompilerResultsLog: Info ^
CompilerResultsLog: Info /Users//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Plugins/UObjectPlugin/Source/UObjectPlugin/Private/MyPluginObject.cpp:33:2: error: unknown type name 'JNIEnv'
CompilerResultsLog: Info JNIEnv *env;
CompilerResultsLog: Info ^
CompilerResultsLog: Info 2 errors generated.
CompilerResultsLog: Info 4 errors generated.
CompilerResultsLog: Info ERROR: UBT ERROR: Failed to produce item: /Users//Documents/Projects/UnrealProjects/MyProject 4.13 - 6/Plugins/UObjectPlugin/Binaries/Mac/UE4Editor-UObjectPlugin-1143.dylib
CompilerResultsLog: Info Total build time: 17.02 seconds
LogMainFrame: MainFrame: Module compiling took 17.909 seconds
Warning: HotReload failed, recompile failed
Warning: RebindPackages failed because the compiler could not be started.
- Here is my projects build.cs file:
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
namespace UnrealBuildTool.Rules
{
public class UObjectPlugin : ModuleRules
{
public UObjectPlugin(TargetInfo Target)
{
PublicIncludePaths.AddRange(
new string] {
// ... add public include paths required here ...
"/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/include/",
}
);
PrivateIncludePaths.AddRange(
new string] {
"Developer/UObjectPlugin/Private",
// ... add other private include paths required here ...
"../../../../Source/Runtime/Core/Private",
"../../../../Source/Runtime/Launch/Private",
"../../../../Source/Runtime/Core/Private/Android",
"../../../../Source/Runtime/Launch/Private/Android",
"/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/include/",
}
);
PublicDependencyModuleNames.AddRange(
new string]
{
"Core",
"CoreUObject",
// ... add other public dependencies that you statically link with here ...
"Engine",
"InputCore",
"Launch",
}
);
PrivateDependencyModuleNames.AddRange(
new string]
{
// ... add private dependencies that you statically link with here ...
"Core",
"CoreUObject",
"Engine",
"InputCore",
"Launch",
}
);
DynamicallyLoadedModuleNames.AddRange(
new string]
{
// ... add any modules that your module loads dynamically here ...
}
);
}
}
}
**3) Here is my Header file
**
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#pragma once
#if PLATFORM_ANDROID
#include <jni.h>
#include "AndroidJNI.h"
#include "AndroidJava.h"
#include "AndroidApplication.h"
#include <Android/asset_manager.h>
#include <Android/asset_manager_jni.h>
#endif
#include "MyPluginObject.generated.h"
extern JavaVM *jvm;
extern JNIEnv *env;
/**
* Example UStruct declared in a plugin module
*/
USTRUCT()
struct FMyPluginStruct
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
FString TestString;
};
/**
* Example of declaring a UObject in a plugin module
*/
UCLASS()
class UMyPluginObject : public UObject
{
GENERATED_UCLASS_BODY()
public:
UFUNCTION( BlueprintCallable, Category = Karmik)
void callMapsActivity();
void AndroidThunkCpp_callMapsActivity();
private:
UPROPERTY()
FMyPluginStruct MyStruct;
};
4) Here is my Source file
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "UObjectPluginPrivatePCH.h"
#include "MyPluginObject.h"
#if PLATFORM_ANDROID
#include <jni.h>
#include "AndroidJNI.h"
#include "AndroidJava.h"
#include "AndroidApplication.h"
#include <Android/asset_manager.h>
#include <Android/asset_manager_jni.h>
#endif
UMyPluginObject::UMyPluginObject( const FObjectInitializer& ObjectInitializer )
: Super( ObjectInitializer )
{
}
void UMyPluginObject::callMapsActivity()
{
// This is going to be the BluePrint function that calls AndroidThunkCpp_callMapsActivity()
}
JavaVM *jvm;
JNIEnv *env;
void UMyPluginObject::AndroidThunkCpp_callMapsActivity()
{
// This will call the java method to invoke MapsActivity
// if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
// {
// static jmethodID callMapsActivityMethod = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_callMapsActivity", "(Z)V", false);
// FJavaWrapper::CallVoidMethod(Env, FJavaWrapper::GameActivityThis, callMapsActivityMethod, false);
// }
}