java-native-interface

How to reduce the apk size of Android app which need openCv lib( only for Image processing)

百般思念 提交于 2020-01-19 21:52:02
问题 I'm building an Android app with min SDK 15 , which uses OpenCV library.The problem is when I build apk size of it is more than 60 MB which is not very great. I checked the app file, I could see that the size is too big due to libopencv_java3.so file in all architectures like amr64 , armeabi , mips , x86 etc. I am using opneCv only for image processing.This library has a lot of other features like video processing, 3d image, object detection and much more, which I don't need in my app like If

JNI method: formal argument lists differ in length

谁说我不能喝 提交于 2020-01-17 03:42:08
问题 I'm trying to emend a JNI function that takes a string argument from the java layer. Initially, the java code from the .java file was: callJNIMethod(); I'm trying to change it so that I can give it a string, like this: String arg = "abcd"; callJNIMethod(arg); In my JNI code, this is what the function previously looked like: JNIEXPORT jboolean JNICALL Java_com_file_app_Activity_callJNIMethod( JNIEnv *env, jclass clazz){ //use the string } This is what I changed it to (in the wrapper .cpp file

OS level event handling?

你离开我真会死。 提交于 2020-01-16 19:46:28
问题 I want to handle os level events in java. I need to do is to perform some logic on key press. I find jni is used for this purpose but don't know how. I don't need to handle event on gui. my application will run on background and perform some logic on every key press. 回答1: If you think using a GUI is overkill, I wouldn't consider using JNI which will be 10x harder. Even if you are confident in C, it can be tricky. You are better off using a library which does what you want already like http:/

the var doesn't become global but remains local

余生颓废 提交于 2020-01-16 19:39:09
问题 From the following snippet i try to test NewGlobalRef and try to make clsStr global after declaring it in the local scope of if block. jstring Java_Package_LocalAndGlobalReference_returnGlobalReference (JNIEnv *env, jobject obj) { if(1) { printf("In function make global reference\n"); jclass clsStr ; jclass cls = (*env)->FindClass(env,"java/lang/String"); if( cls == NULL) return NULL; // create a global reference of clsStr clsStr = (*env)->NewGlobalRef(env,cls); // Delete the local reference,

Native library not loaded from cordova apk

眉间皱痕 提交于 2020-01-15 10:37:09
问题 I'm making a cordova plugin that would be a simple wrapper for a .jar file and its two .so dependencies. I have tried it before in a normal android application with android studio. By copying the native libraries into the jniLibs/armeabi folder and the jar file into libs/ it worked perfectly. At the cordova plugin I've made the same folder structure and everything is on the same place. In the plugin.xml I have copying the two files into libs/armeabi which is working because if I look into the

specify .so files in build.gradle file android studio

只谈情不闲聊 提交于 2020-01-15 10:16:09
问题 This is my Directory Structure src -main -java -jniLibs -armeabi -lib1.so -lib2.so Need to understand what piece of code should be written in build gradle file for these files to be included in the build. Right now, i am getting the error of not finding the .so file. java.lang.UnsatisfiedLinkError: nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libFPEComponent.so" Following solution by H.Brooks I have got to add here My Git repository: My bUild.gradle file apply plugin:

Native crash (UnsatisfiedLinkError) when the application is updated

允我心安 提交于 2020-01-15 09:36:08
问题 I have an app that uses some native code. The applications works fine and contains all the abis but in some android devices like Galaxy Note5 with Android 7.0 and SM-G955U (Samsung Galaxy S8 plus) with Android 7.0 the application crashes with the following error: Fatal Exception: java.lang.UnsatisfiedLinkError: Native method not found These are the abis included in the APK: arm64-v8a armeabi armeabi-v7a mips mips64 x86 x86_64 Anybody knows how can I fix that? Thanks! 回答1: Looks like this is a

No JNI_OnLoad and no return value from native function?

余生长醉 提交于 2020-01-15 09:05:11
问题 i need to make linux command from native method by c++ code. this is my class Test.java public class Test { static { System.loadLibrary("NDK1"); } public native String exec(String cmd); } then i create header .h by this command : $ javah -classpath ../bin/classes com.example.new1.Test after this the header .h is created in this path com.example.new1 then i create jni file and copy .h file and create .cpp file and include .h in it. #include <string> #include <iostream> #include <stdio.h>

No JNI_OnLoad and no return value from native function?

主宰稳场 提交于 2020-01-15 09:04:50
问题 i need to make linux command from native method by c++ code. this is my class Test.java public class Test { static { System.loadLibrary("NDK1"); } public native String exec(String cmd); } then i create header .h by this command : $ javah -classpath ../bin/classes com.example.new1.Test after this the header .h is created in this path com.example.new1 then i create jni file and copy .h file and create .cpp file and include .h in it. #include <string> #include <iostream> #include <stdio.h>

MinGW's compiler option Wl,--kill-at does not work

女生的网名这么多〃 提交于 2020-01-15 08:15:12
问题 I am currently struggling to compile a Dll for JNI use, using Eclipse CDT and MinGW. Following a tutorial, i created a Java class that declares native methods, then used javah to get the relevant header file and I implemented it in a C++ class. The C++ code is very simple and compilation works, but when I load the library into the Java class, i get this error : Exception in thread "main" java.lang.UnsatisfiedLinkError: Main.integerMethod(I)I at Main.integerMethod(Native Method) at Main.main