How to call java function from c++?

I want to call a function from c++ by using jni.
Here is some code I found from the Internet:

#include <jni.h>
#include “platform/android/jni/JniHelper.h”

But it show that VS2010 cannot find jni.h.
Please tell me why and how to solve this problem.


未命名.jpg (40.9 KB)

Chris Du wrote:

I want to call a function from c++ by using jni.
Here is some code I found from the Internet:
>
#include <jni.h>
#include “platform/android/jni/JniHelper.h”
>
But it show that VS2010 cannot find jni.h.
Please tell me why and how to solve this problem.

These might help— I really wrestled with this just today, to open a url from within cocos2dx.

First I followed this: http://digitalsynapsesblog.blogspot.com/2011/09/cocos2d-x-launching-url-on-android.html

…followed by this: http://cocos2d-x.org/boards/6/topics/3769?r=10556#message-10556

Combined they got me up and running. You’ll find that past a certain point the first link is out of date with the current file structure. That’s about where the second link picks up.

Hope that helps!

Thanks.
I have found jni.h and Jnihelper.h.
But there is a new problem.

“android/log.h”: No such file or directory

And I can’t find it in my computer.
Would you help me with this?

Chris Du wrote:

Thanks.
I have found jni.h and Jnihelper.h.
But there is a new problem.
>
“android/log.h”: No such file or directory
>
And I can’t find it in my computer.
Would you help me with this?

Hi Chris, not sure what’s causing that. I’ll have to leave it one of the kind individuals here who is more knowledgable. I’ve got it in multiple places on my computer and it’s part of the NDK. I’m at a loss to explain why it would complain about it only now.

@Chris Du: How did you find jni.h and Jnihelper.h. I am having same issue?

It’s in the folder of COCOS2DX_ROOT/cocos2dx/platform/android/jni.

Thanks for the quick reply. Agree that JniHelper.h and .cpp is there. I have also written below includes,
*
#include “jni/JniHelper.h”
#include “jni/SystemInfoJni.h”
#include <jni.h>
#include
#include “platform/CCPlatformMacros.h”
#include
#include “platform/CCCommon.h”
#include “platform/CCApplicationProtocol.h”*

But when I write
JniMethodInfo t;

I am getting
Type ‘JniMethodInfo’ could not be resolved.

I have spent hours on it but can not figure out what is the problem!

Do I need to change anything in the library??

You can try this:
#include “…/platform/android/jni/JniHelper.h”

Same problem here. Anyone solved it?

Use VS2013 express.
It’s free.