Access FJavaWrapper in Android Runtime Plugin

Hi all,

I’m working on a plugin for android and want to access the FJavaWrapper class from my code.

So I inlcude

#include "Android/AndroidJNI.h"

to my cpp file. In the normal compile setting “Development Editor/Win64” all is fine couse the plugin is whitelisted for Android.

But if I try to launch on Android, my plugin is compiled for android again and I got a

fatal error: 'Android/AndroidJNI.h' file not found

And it drives me crazy. I saw the GearVR PlugIn uses the file too, and it looks like that it works. I take a look in there plugin build settings and saw nothing which points to the AndroidJNI.h, or added it to the include dependencies.

What should I do to use the AndroidJNI in specially the FJavaWrapper in my Plugin?

regards

Okay I found the issue.

Should add the Privateinclude:

/Source/Runtime/Launch/Private"

Hi Hessling,

I’m having the same issue right now. Can you be more specific about your fix?

What did you add exactly to make it work?

A code sample would be great!

Thanks
Robel

Hi Robel,

I had to add “/Source/Runtime/Launch/Private” in the private include section of my plugin c# config file. Each source project/plugin has one. But I worked on a plugin which worked on the engine source base and not a precompiled engine from the Epic Game Laucher.

Regard,
Ingo Hessling

  1. in the XXX.uplugin file add WhitelistPlatforms": [ “Android”, “Win64” ] to Modules
  2. in the cpp file, add following including files.
    #if PLATFORM_ANDROID
    #include “AndroidPlatform.h”
    #include “Android/AndroidApplication.h”
    #include “Android/AndroidJNI.h”
    #include “Android/AndroidJava.h”
    #endif
  3. in the c++ code, use PLATFORM_ANDROID MACRO to distinguish the java code and C++ platform code

Hello. I have the same issue and i didn’t understand your solution. Can you share exactly the include field. I tried include “Android/AndroidJNI.h/Source/Runtime/Launch/Private” but it was wrong

Hey, probably the problem is that your code does not see the “Launch” module, which contains the code for calling JNI. You can do it this way:

if (Target.Platform == UnrealTargetPlatform.Android)
{
	PrivateDependencyModuleNames.Add("Launch");
}

You can look at my plugin to see how I did it: Android Native