Category : java-native-interface

I use C++ with NDK/JNI/CMake in my Android project. I have a struct like this: struct AppSettings { std::string scenedir; std::string outmesh; std::string dmname = "depth-L0"; std::string image = "undistorted"; std::string mask; std::string aabb; } Now, I want to use my struct and change the value of the string ‘dmname’ like this: AppSettings conf; // ..

Read more

I’m trying to run a native method that I created but when I try and run my main method I get this error and I’ve got no clue how to fix it, I 100% know my shared library is being loaded. Exception in thread "main" java.lang.UnsatisfiedLinkError: Main.C.C.change(II)J at Main.C.C.change(Native Method) at Main.C.C.main(C.java:16) Here are all ..

Read more

I’m trying to load a library called "change.dll" which sits in the same directory as my file "C.java" here’s the code of that file. package Main.C; import java.io.File; public class C { public static native long change(int width, int height); private static final String absolute = new File("resolution/C/change").getAbsolutePath(); static { System.load(absolute); } public static void ..

Read more

I have a jar file acting as a launcher (launcher.jar), it has these two classes, they describe how the application starts. And the jar file of the application itself (applet.jar) package mylauncher; public class MyClassLoader { private static ClassLoader classLoader; public MyClassLoader() { … } public Applet createApplet() throws ClassNotFoundException, InstantiationException, IllegalAccessException { Class localClass ..

Read more

So I have this c++ code I wish to implement into my java project. Function: change resolution DEVMODE devmode; devmode.dmSize = sizeof(DEVMODE); devmode.dmPelsWidth = desiredWidth; devmode.dmPelsHeight = desiredHeight; long result = ChangeDisplaySettings(&devmode, DM_PELSWIDTH || DM_PELSHEIGHT); I want to implement this into this header file I generated and into its respected function so I can use ..

Read more

I am calling a java method from C++ in android app. Works fine in debug but GetMethodID fails in release build. // Java public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { //… showKeyboard(); } public void showKeyboard() { Log.i("my_app", "MainActivity::showKeyboard"); //… } } // C++ JavaVM* gJvm; // Saved in JNI_OnLoad() ..

Read more

I have a Android/NDK/JNI/Java/C++ project. I have a Gradle file that looks like this: …. cmake { cppFlags "-std=c++11 -fexceptions" arguments "-DANDROID_STL=c++_static" } …. My question is: how to check that these flags and arguments are well taken into account when my Android project is compiled ? Thanks Source: Windows Que..

Read more

I see here a typical example of Gradle file for a NDK project. Nevertheless, I wonder what are the rules to know where to put the different flags: // Passes optional arguments to CMake. arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_TOOLCHAIN=clang" // Sets a flag to enable format macro constants for the C compiler. cFlags "-D__STDC_FORMAT_MACROS" // Sets optional ..

Read more

public class some_class { public static void som_func() { var some_object = new SomeObject(); var ret = 0; do { ret = some_object.DoSomething(); } while(ret != 1); System.out.printf("Return value: %d", ret); } } Now in C++ if I call like this way: auto some_cls = g_env->FindClass("some_class"); auto some_func = g_env->GetStaticMethodID(some_cls, "som_func", "()V"); g_env->CallStaticVoidMethod(some_cls, some_func); Is ..

Read more