So the title explains everything you need to know... I tried googling for 2 hours but I just cant find a page where it shows you how to do like example I have a code that calculates the screen size in cpp and I want to call it in java to use it(obviously) EDIT: I just have to put the cpp file name or register it in the Android.mk file... My bad still learning CPP android apps
Asked
Active
Viewed 980 times
-4
-
export your c++ function in a dll see http://stackoverflow.com/questions/9485896/calling-c-dll-from-java – user Feb 26 '17 at 14:57
-
Google the JNI (Java native interface) – Ben Wainwright Feb 26 '17 at 14:59
-
Possible duplicate of [Calling C++ dll from Java](http://stackoverflow.com/questions/9485896/calling-c-dll-from-java) – user Feb 26 '17 at 15:00
-
Please remove the downvotes :( – Pixeldroid Modding Feb 26 '17 at 15:52
1 Answers
1
I just had to place the cpp file name in the Android.mk file... This is my first time so sorry... Fixed code: C++
#include <string.h>
#include <jni.h>
extern "C"
{
JNIEXPORT jint JNICALL Java_net_pixeldroidof_addonedit_MainActivity_getScreenY(JNIEnv* env, jobject thiz)
{
int number = 30;
return number;
}
}
Java
public native static int getScreenY();
//And you can start calling it(example: getScreenY() will now return the value from the cpp)

Pixeldroid Modding
- 35
- 6