jnienv

Getting Started with JNI and C under Windows

旧巷老猫 提交于 2019-12-14 04:25:20
问题 I'm new in Java learning and first time want to get start JNI. And I am working with Cygwin and I have created a file with .java (Helloworld.java) extension as follows: class HelloWorld { private native void print(); public static void main(String[] args) { new HelloWorld().print(); } static { System.loadLibrary("HelloWorld"); } } Then I compile the file through the command line ( javac Helloworld.java ) after that create a native header file through command javah –jni Helloworld Then also

When creating New<PrimitiveType>Array from C++ code in JNI how to release the <PrimitiveType>Array's buffer?

拟墨画扇 提交于 2019-12-11 18:44:32
问题 I am currently writing a small emulator in C++ using Java as a GUI. In order to achieve this I am making JNI calls from my C++ code passing arrays of data to the GUI application. However due to the shear amount of calls I made in a test run, it has become clear that in my function to pass data a memory leak is occurring. Before my program has run: After my program has run and crashed due to lack of memory: (Please ignore the CPU usage this program currently uses, I am aware that repeated

JNI Linux segmentation fault

倾然丶 夕夏残阳落幕 提交于 2019-12-11 16:19:32
问题 My JNI library works flawlessly on Windows, however, on Linux I always get a strange segmentation fault. siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000000000000 The stack crace from the crash file is this: C [libfmodjavaL.so+0xfb8c] JNIEnv_::GetStaticObjectField(_jclass*, _jfieldID*)+0x18 C [libfmodjavaL.so+0xf72b] Logger::sendToSystemOut(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)+0x75 C [libfmodjavaL.so+0xf7c2] Logger

call nonstatic methods from java to cpp using JNI

瘦欲@ 提交于 2019-12-11 14:20:14
问题 I am trying to call non static method from java to C++ using JNI My Java Code is here: public class hellojava { public static void main(String args[]) { System.out.println("Hello World!"); System.out.println("This is the main function from the HelloWorld java class."); } public void message() { System.out.println("call from object"); } } And my C++ code is here: #include <stdio.h> #include <jni.h> JNIEnv* create_vm(JavaVM ** jvm) { JNIEnv *env; JavaVMInitArgs vm_args; JavaVMOption options;

Loading JNI Dll

ぐ巨炮叔叔 提交于 2019-12-11 04:55:13
问题 I have a file written as follows: package JNI; public class Natives { public static final int PAGE_READONLY = 0x02; public static final int PAGE_READWRITE = 0x04; public static final int PAGE_WRITECOPY = 0x08; public static final int FILE_MAP_COPY = 0x0001; public static final int FILE_MAP_WRITE = 0x0002; public static final int FILE_MAP_READ = 0x0004; public static native long createFileMapping(long hFile, int lpAttributes, int dwMaximumSizeHigh, int dwMaximumSizeLow, String lpName); public

Monodroid JNI for Java reflection to call a private method

筅森魡賤 提交于 2019-12-08 12:33:10
问题 In a Monodroid project, I need to be able to call a private method on a class. From an answer on a related question, it seems that this is possible in Java via reflection: import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import android.os.ParcelFileDescriptor; ... ParcelFileDescriptor pipe[] = null; try { Method createPipeMethod = ParcelFileDescriptor.class.getDeclaredMethod("createPipe"); pipe = (ParcelFileDescriptor[]) createPipeMethod.invoke(null); }

Call a function in java from C outside of a JNI function (Android)?

孤街醉人 提交于 2019-12-08 00:55:04
问题 I'm trying to call a Java function from my C code using the JNI in Android, but I'm in a somewhat awkward situation. My C code is being executed outside of a JNI function in a callback that is passed to a library. Here is an example of the java code package com.my.java.package; class MyClass { public function handleData(byte[] data) { doSomethingWithThisData(data); } } Here is an example of the C code void handleData(uint8_t *data, size_t len) { // I need to call handleData in my java //

Android Jni : crash in global and local ref variables

落花浮王杯 提交于 2019-12-06 04:24:34
I have jni c++ code that calls java objects methods, example : jclass JIOManager = CJavaEnv::getInstance()->env()->FindClass(ioManagerName); ..... some code CJavaEnv::getInstance()->env()->DeleteLocalRef(JIOManager); this works really fine when executes in main thread, but when I try to execute this in another thread it crash because it says that it is created in another thread :O !! but after I read in google android developer website, they say accessing Global Ref from any thread is fine, so I changed that code to be like. jclass JIOManager = (jclass)CJavaEnv::getInstance()->env()-

Unable to load .so library files when making a system application

孤街醉人 提交于 2019-12-06 03:09:11
问题 I have created an application which will be a System Application . When I install the application normally(not as system application) ".so" files are getting loaded. But when I'm making it a system application by putting the apk into /system/app/ , I'm getting the following error 01-09 00:20:26.889: E/AndroidRuntime(2101): java.lang.UnsatisfiedLinkError: Couldn't load iconv from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip

Unable to load .so library files when making a system application

↘锁芯ラ 提交于 2019-12-04 07:10:20
I have created an application which will be a System Application . When I install the application normally(not as system application) ".so" files are getting loaded. But when I'm making it a system application by putting the apk into /system/app/ , I'm getting the following error 01-09 00:20:26.889: E/AndroidRuntime(2101): java.lang.UnsatisfiedLinkError: Couldn't load iconv from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/system/app/My.apk"],nativeLibraryDirectories= [/vendor/lib, /system/lib]]]: findLibrary returned