UE4.19 Call to Java method crashes GearVR app no error on log
Using unreal 4.19.1, I am trying to implement a Java method to launch a different app from mine. I have a java class with the method in [project]/Build/Android/src/com/[company]/[project] The same method works perfectly well when called from a native Android app built in Android Studio. I had to adapt it a little for Unreal, but the call remains almost the same.
I call it in game from a function that I coded in c++ and exposed to blueprint so that I can easily call it from a widget. I know it gets to the method call because I have added debug logs in between every step until the java class call, and they all print as expected.
[2018.04.20-08.07.51:499]LogTemp: Display: Getting Env
[2018.04.20-08.07.51:500]LogTemp: Display: Getting Activity
[2018.04.20-08.07.51:500]LogTemp: Display: Getting Class
[2018.04.20-08.07.51:501]LogTemp: Display: Getting Method
[2018.04.20-08.07.51:501]LogTemp: Display: Getting Intent
Those are the last lines of the log, there is no error, no crash, nothing, it simply stops. I know it isn't the code for the method, because commenting the code out and leaving the method empty inside still has the same behavior. This is the line where it stops in c++:
I know the class and the method get found because I check if the previous step succeeded before going to the next step, and those errors generate a Critical Error on the log - I fixed those already. I use TCHAR_TO_ANSI(*pkgName) to pass an FString from the blueprint function to the Method. I want to add some sort of log to the java class, but haven't figured out a way to do it yet.
Any thoughts on what could be causing the crash? Or maybe a better way to launch a different Android app? Or a better way to call a Java method from c++?
For anyone having the same issue, I managed to find out what was wrong. When calling the Java method I had not instantiated an object of the class before doing so. This caused it to crash - the lack of an error is what really made it difficult to find. This is how I fixed it:
First line finds the no arguments constructor method for the class, and second line instantiates the object. Before this you do have to have found the class, activity and Env. After getting the object you can call methods from the class. No need to change anything in Unreal source code.
Follow this question
Once you sign in you will be able to subscribe for any updates here