Download

Add java classes or c# classes to GearVR project?

Hi,

I have gone through the tutorial to create a GearVR project. The default first person app from the tutorial works on the phone itself.

Now I want to extend it with the functionality of our other app. We have another app written in Java that broadcasts messaging over a messaging system which we have written. The client just needs to be able to compile with a java .jar file and dll or a c# dll. And then I have to implement a few classes on the client in Java or c#. The app I made in UE4 is mostly c++, I see a few c# classes. How do I go about adding my own java classes or c# classes to this UE project? In the end these java or c# classes need to create procedurally generated geometry, which I’m assuming will need to be some sort of derived Actor class.

Any guidance would be much appreciated.

Thanks.

You can write a plugin (see Gear VR plugin itself) and use JNI to call into Java. You can have your Java code copied by UPL (see GearVR_APL.xml and GearVR.Build.cs where it is registered as an example).

You will need to do your procedural geometry in C++.

When you say, “You can write a plugin” … what is the advantage of writing a plugin vs a project? Wouldn’t I want to create a UE4 project where I automatically gain GearVR support, and then modify that? Or are you saying that a plugin is the only option in this case?

You need a plugin if you want blue-print only projects to work, but if you are doing a code project you can just add the AndroidPlugin registration code to your Build.cs for the game.

So I see that there is some java code written in the GearVR_APL.xml file itself. So, this is interesting. I guess it means this code is copied somewhere else, and compiled in some other place before deploying to the phone. Where would I put my own java files? Or, not just java files, but already compiled jar files? So, can i put raw java files (non-compiled code) some where? If so, where? And where do I put compiled jar files? Thanks.

UPL allows injecting code into the GameActivity.java. This is useful when you need to be in the main activity (respond to onPause/onResume, do something during onCreate, etc). You can also copy Java code into the $S(BuildDir)/src/[package path] during resourceCopies section since it happens before ant is run to compile and package/sign the APK. You can also copy jars into $(BuldDir)/libs.