x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do I call Java code in unreal c++ using JNI?

Hello, fellow game creators. I'm working on this VR project in which a mobile device is used as a controller. Currently I'm testing JNI to call Java code on UE4. Only to fail, though... So I referred to these two links to figure out what I messed up.

https://answers.unrealengine.com/questions/104948/platform-specific-functionality-in-ue4-game.html https://forums.unrealengine.com/showthread.php?90170-HAAALP-android-custom-java-call

But still, when I build and run it on the device, it crashes at the certain function. I can't seem to figure out what's wrong. I could really use some help.

Below is the code. (don't mind Korean letters)

  • GameActivity.java generated custom function AndroidThunkJava_Toast(String msg) alt text

  • AndroidJNI.h declare variable to save Java method ID in order to call Java function (static jmethodID AndroidThunkJava_Toast;)

  • AndroidJNI.cpp Add Java method ID alt text

  • declare function to AndroidJNI.cpp alt text

  • AndroidJNI.cpp Add AndroidThunkCpp_Toast to call cached Jave Method ID alt text

  • AndroidJNI.cpp add to JNI_OnLoad automatically called by UE4 library load

  • MyActor.h declare function (void Toast(FString msg))

  • MyActor.cpp Call java function alt text

If somebody knows something, please go ahead and leave a comment.

Stay awesome.

Product Version: UE 4.11
Tags:
1.png (41.0 kB)
3.png (94.8 kB)
4.png (61.0 kB)
6.png (68.8 kB)
8.png (37.4 kB)
more ▼

asked Jun 10 '16 at 11:50 AM in C++ Programming

avatar image

안데브
1 1 1 1

avatar image zbrtcchr Aug 11 '16 at 05:52 AM

Bumping. Also need answers for this. 안데브 have you learned how to do this?

avatar image SalihBalkan Oct 24 '16 at 01:11 PM

I need this too. Documentation would be good.

avatar image Omar Vector Nov 07 '18 at 04:59 AM

did u find what was the issue?

I believe the reason could be you didnt add "Android" module to your Build.cs , but plz confirm what was the issue

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

UE4 used code obfuscation system called ProGuard on it's java layer, because of that functions name are modified and C++ references fails due to that name change. You need to add exception to your function in ProGuard configuration, you can find engine directory \Engine\Build\Android\Java\proguard-project.txt. All other linking function that engine used are already there too which shows you a example

Also you don't need to modify engine for this, you can do this in your own module using exacly same function that AndroidJNI class does.

more ▼

answered Nov 07 '18 at 11:23 PM

avatar image

Shadowriver
37.3k 936 172 1116

avatar image Omar Vector Nov 08 '18 at 12:08 AM

Based on your experience, do you think its possible to wrapping java native call to access microphone data on android platform in real time in the same way as above example?

I'm asking bec AndroidVoiceModule has a bug I reported and epic games no clear information to fix it they always delay it

Link of the bug: https://issues.unrealengine.com/issue/UE-62389

avatar image Shadowriver Nov 08 '18 at 01:32 AM

This has capabilities of standard JNI so you should read the performance of that, like sending PCM stream using it. But why don't you check AndroidVoiceModule source yourslef and see what it's doing and try to replicate it potentially even thinking that module yourself, it might be something missing on resume. You might try stoping capture on app sleep and restart on wake up

avatar image Omar Vector Nov 08 '18 at 01:49 AM

along past month, and I'm working debugging the AndroidVoiceModule, actually its not written by epic games.

Since its developed using OpenSL ES, I read alot from documentation about it, its architecture..etc even more code samples.

When I debugged the app, when its closed, it fail to shutdown the audio driver, which always marked as used when you start the app again. also on closing, the catlog says "failed to kill 1 processes from group 1956 or some numbers"

I followed the instruction of destroying the ESEngine since at the given code its not "you have destroy recorder object and then the engine object" while the module destroy the engine Object first then the recoder, I did fix that but the problem still exist.

For VoiceCapture part , I made sure that I stop it and clear the buffer before exit, so when it shutdown no crashes or unexpected behaviuor, that make no difference.

Fun thing, is during runtime, I'm able to destroy VoiceCapture and create new one with no issue on android, but if I destory it, and then I close the app and start it agian, still the issue exit.

I dont know what else I suppose to do. than just skip it and find another way around, currently I'm investigating FMOD.

This the link for full thread just in case you want to have a look https://forums.unrealengine.com/development-discussion/audio/1507971-ue-62389-android-mic-stops-capturing-audio-after-2nd-load-of-app

Edit : I used PlatformGameinstance to handle voice capture on background and foreground to make sure everything undercontorl, but still that doesnt fix the problem.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question