java程序通过JNI调用第三方so文件,运行出现crash,导致程序退出 80C

在spring boot中使用JNI集成第三方so文件,通过
java -XX:+UnlockDiagnosticVMOptions -XX:+VerifyBeforeGC -XX:+VerifyAfterGC -jar xxxxx.jar运行,在调用第三方so文件时出现crash,导致程序退出
图片说明
下面是crash产生的日志文件hs_err_pid17314.log

 #
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (instanceKlass.cpp:3358), pid=17314, tid=0x00007ff1fe6e6700
#  guarantee(false) failed: boom
#
# JRE version: Java(TM) SE Runtime Environment (8.0_111-b14) (build 1.8.0_111-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.111-b14 compiled mode linux-amd64 compressed oops)
# Core dump written. Default location: /data/html/agora/core or core.17314
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#

---------------  T H R E A D  ---------------

Current thread (0x00007ff22c1c6000):  VMThread [stack: 0x00007ff1fe5e6000,0x00007ff1fe6e7000] [id=17324]

Stack: [0x00007ff1fe5e6000,0x00007ff1fe6e7000],  sp=0x00007ff1fe6e5200,  free space=1020k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0xac5c2a]  VMError::report_and_die()+0x2ba
V  [libjvm.so+0x4fbc92]  report_vm_error(char const*, int, char const*, char const*)+0x62
V  [libjvm.so+0x655582]  VerifyFieldClosure::do_oop(unsigned int*)+0x102
V  [libjvm.so+0x64b651]  InstanceKlass::oop_oop_iterate_nv(oopDesc*, NoHeaderExtendedOopClosure*)+0x91
V  [libjvm.so+0x63ea8f]  InstanceKlass::oop_verify_on(oopDesc*, outputStream*)+0x5f
V  [libjvm.so+0x8dd059]  MutableSpace::verify()+0x69
V  [libjvm.so+0x992486]  PSYoungGen::verify()+0x16
V  [libjvm.so+0xa8cf6c]  Universe::verify(VerifyOption, char const*, bool)+0xcc
V  [libjvm.so+0x98e6f0]  PSScavenge::invoke_no_policy()+0x330
V  [libjvm.so+0x98fa81]  PSScavenge::invoke()+0x41
V  [libjvm.so+0x9467d0]  ParallelScavengeHeap::failed_mem_allocate(unsigned long)+0x70
V  [libjvm.so+0xac7647]  VM_ParallelGCFailedAllocation::doit()+0x97
V  [libjvm.so+0xacf125]  VM_Operation::evaluate()+0x55
V  [libjvm.so+0xacd4fa]  VMThread::evaluate_operation(VM_Operation*)+0xba
V  [libjvm.so+0xacd87e]  VMThread::loop()+0x1ce
V  [libjvm.so+0xacdcf0]  VMThread::run()+0x70
V  [libjvm.so+0x924ea8]  java_start(Thread*)+0x108

VM_Operation (0x00007ff1753d7780): ParallelGCFailedAllocation, mode: safepoint, requested by thread 0x00007ff128001000

8个回答

 ---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x00007ff1300d7800 JavaThread "I/O dispatcher 32" [_thread_in_native, id=17603, stack(0x00007ff0ffbfc000,0x00007ff0ffcfd000)]
  0x00007ff1300d5800 JavaThread "I/O dispatcher 31" [_thread_in_native, id=17602, stack(0x00007ff0ffcfd000,0x00007ff0ffdfe000)]
  0x00007ff1300d3800 JavaThread "I/O dispatcher 30" [_thread_in_native, id=17601, stack(0x00007ff0ffdfe000,0x00007ff0ffeff000)]
  0x00007ff1300d1800 JavaThread "I/O dispatcher 29" [_thread_in_native, id=17600, stack(0x00007ff0ffeff000,0x00007ff100000000)]
  0x00007ff1300cf800 JavaThread "I/O dispatcher 28" [_thread_in_native, id=17599, stack(0x00007ff1740d4000,0x00007ff1741d5000)]
  0x00007ff1300ce000 JavaThread "I/O dispatcher 27" [_thread_in_native, id=17598, stack(0x00007ff1741d5000,0x00007ff1742d6000)]
  0x00007ff1300cc000 JavaThread "I/O dispatcher 26" [_thread_in_native, id=17597, stack(0x00007ff1742d6000,0x00007ff1743d7000)]
  0x00007ff1300ca800 JavaThread "I/O dispatcher 25" [_thread_in_native, id=17596, stack(0x00007ff1743d7000,0x00007ff1744d8000)]
  0x00007ff1282f0000 JavaThread "Thread-12" daemon [_thread_blocked, id=17595, stack(0x00007ff1744d8000,0x00007ff1745d9000)]
  0x00007ff1282ef800 JavaThread "pool-8-thread-1" [_thread_in_native, id=17594, stack(0x00007ff1745d9000,0x00007ff1746da000)]
  0x00007ff128004000 JavaThread "process reaper" daemon [_thread_blocked, id=17500, stack(0x00007ff21c02b000,0x00007ff21c064000)]
  0x00007ff128001000 JavaThread "Thread-11" [_thread_blocked, id=17489, stack(0x00007ff1749db000,0x00007ff1753dc000)]
  0x00007ff158004800 JavaThread "pool-2-thread-2" [_thread_in_native, id=17467, stack(0x00007ff1746da000,0x00007ff1747db000)]
  0x00007ff164a34000 JavaThread "pool-2-thread-1" [_thread_blocked, id=17411, stack(0x00007ff1753dc000,0x00007ff1754dd000)]
  0x00007ff10c0d5800 JavaThread "I/O dispatcher 24" [_thread_in_native, id=17410, stack(0x00007ff1754dd000,0x00007ff1755de000)]
  0x00007ff10c0d4000 JavaThread "I/O dispatcher 23" [_thread_in_native, id=17409, stack(0x00007ff1755de000,0x00007ff1756df000)]
  0x00007ff10c0d2000 JavaThread "I/O dispatcher 22" [_thread_in_native, id=17408, stack(0x00007ff1756df000,0x00007ff1757e0000)]
  0x00007ff10c0d0000 JavaThread "I/O dispatcher 21" [_thread_in_native, id=17407, stack(0x00007ff1757e0000,0x00007ff1758e1000)]
  0x00007ff10c0ce800 JavaThread "I/O dispatcher 20" [_thread_in_native, id=17406, stack(0x00007ff1758e1000,0x00007ff1759e2000)]
  0x00007ff10c0cc800 JavaThread "I/O dispatcher 19" [_thread_in_native, id=17405, stack(0x00007ff1759e2000,0x00007ff175ae3000)]
  0x00007ff10c0cb000 JavaThread "I/O dispatcher 18" [_thread_in_native, id=17404, stack(0x00007ff175ae3000,0x00007ff175be4000)]
  0x00007ff10c0c9000 JavaThread "I/O dispatcher 17" [_thread_in_native, id=17403, stack(0x00007ff175be4000,0x00007ff175ce5000)]
  0x00007ff164975000 JavaThread "Thread-9" daemon [_thread_blocked, id=17402, stack(0x00007ff175ce5000,0x00007ff175de6000)]
  0x00007ff164974000 JavaThread "pool-7-thread-1" [_thread_in_native, id=17401, stack(0x00007ff175de6000,0x00007ff175ee7000)]
  0x00007ff22c008800 JavaThread "DestroyJavaVM" [_thread_blocked, id=17315, stack(0x00007ff235bea000,0x00007ff235ceb000)]
  0x00007ff22d723800 JavaThread "Thread-8" [_thread_blocked, id=17387, stack(0x00007ff1760e7000,0x00007ff1761e8000)]
  0x00007ff22ce20000 JavaThread "grpc-default-boss-ELG-1-1" daemon [_thread_in_native, id=17386, stack(0x00007ff1761e8000,0x00007ff1762e9000)]
  0x00007ff13c0d7000 JavaThread "I/O dispatcher 16" [_thread_in_native, id=17385, stack(0x00007ff1766e9000,0x00007ff1767ea000)]
  0x00007ff13c0d5000 JavaThread "I/O dispatcher 15" [_thread_in_native, id=17384, stack(0x00007ff1767ea000,0x00007ff1768eb000)]
  0x00007ff13c0d3800 JavaThread "I/O dispatcher 14" [_thread_in_native, id=17383, stack(0x00007ff1768eb000,0x00007ff1769ec000)]
  0x00007ff13c0d1800 JavaThread "I/O dispatcher 13" [_thread_in_native, id=17382, stack(0x00007ff1769ec000,0x00007ff176aed000)]
  0x00007ff13c0d0000 JavaThread "I/O dispatcher 12" [_thread_in_native, id=17381, stack(0x00007ff176aed000,0x00007ff176bee000)]
  0x00007ff13c0ce000 JavaThread "I/O dispatcher 11" [_thread_in_native, id=17380, stack(0x00007ff176bee000,0x00007ff176cef000)]
  0x00007ff13c0cc000 JavaThread "I/O dispatcher 10" [_thread_in_native, id=17379, stack(0x00007ff176cef000,0x00007ff176df0000)]
  0x00007ff13c001800 JavaThread "I/O dispatcher 9" [_thread_in_native, id=17378, stack(0x00007ff176df0000,0x00007ff176ef1000)]
  0x00007ff18c32a000 JavaThread "Thread-7" daemon [_thread_blocked, id=17377, stack(0x00007ff176ef1000,0x00007ff176ff2000)]
  0x00007ff18c359800 JavaThread "pool-4-thread-1" [_thread_in_native, id=17376, stack(0x00007ff176ff2000,0x00007ff1770f3000)]
  0x00007ff22ca79800 JavaThread "http-nio-50000-AsyncTimeout" daemon [_thread_blocked, id=17375, stack(0x00007ff1770f3000,0x00007ff1771f4000)]
  0x00007ff22ca78000 JavaThread "http-nio-50000-Acceptor-0" daemon [_thread_in_native, id=17374, stack(0x00007ff1771f4000,0x00007ff1772f5000)]
  0x00007ff22de8a800 JavaThread "http-nio-50000-ClientPoller-1" daemon [_thread_in_native, id=17373, stack(0x00007ff1772f5000,0x00007ff1773f6000)]
  0x00007ff22c2b7000 JavaThread "http-nio-50000-ClientPoller-0" daemon [_thread_in_native, id=17372, stack(0x00007ff1773f6000,0x00007ff1774f7000)]
  0x00007ff22e2f8800 JavaThread "http-nio-50000-exec-10" daemon [_thread_blocked, id=17371, stack(0x00007ff1774f7000,0x00007ff1775f8000)]
  0x00007ff22e2f7000 JavaThread "http-nio-50000-exec-9" daemon [_thread_blocked, id=17370, stack(0x00007ff1775f8000,0x00007ff1776f9000)]
  0x00007ff22da0e800 JavaThread "http-nio-50000-exec-8" daemon [_thread_blocked, id=17369, stack(0x00007ff1776f9000,0x00007ff1777fa000)]
  0x00007ff22ce58000 JavaThread "http-nio-50000-exec-7" daemon [_thread_blocked, id=17368, stack(0x00007ff1777fa000,0x00007ff1778fb000)]
  0x00007ff22ccb7000 JavaThread "http-nio-50000-exec-6" daemon [_thread_blocked, id=17367, stack(0x00007ff1778fb000,0x00007ff1779fc000)]
  0x00007ff22d4b9000 JavaThread "http-nio-50000-exec-5" daemon [_thread_blocked, id=17366, stack(0x00007ff1779fc000,0x00007ff177afd000)]
  0x00007ff22e91d000 JavaThread "http-nio-50000-exec-4" daemon [_thread_blocked, id=17365, stack(0x00007ff177afd000,0x00007ff177bfe000)]
  0x00007ff22c9e2000 JavaThread "http-nio-50000-exec-3" daemon [_thread_blocked, id=17364, stack(0x00007ff177bfe000,0x00007ff177cff000)]
  0x00007ff22cc0f800 JavaThread "http-nio-50000-exec-2" daemon [_thread_blocked, id=17363, stack(0x00007ff177cff000,0x00007ff177e00000)]
  0x00007ff22e077000 JavaThread "http-nio-50000-exec-1" daemon [_thread_blocked, id=17362, stack(0x00007ff1b4033000,0x00007ff1b4134000)]
  0x00007ff22cf0e000 JavaThread "NioBlockingSelector.BlockPoller-1" daemon [_thread_in_native, id=17361, stack(0x00007ff1b4a37000,0x00007ff1b4b38000)]
  0x00007ff22d0de800 JavaThread "pool-3-thread-1" [_thread_blocked, id=17360, stack(0x00007ff1b4b38000,0x00007ff1b4c39000)]
  0x00007ff22e750800 JavaThread "commons-pool-EvictionTimer" daemon [_thread_blocked, id=17355, stack(0x00007ff1b4534000,0x00007ff1b4635000)]
  0x00007ff22d70c000 JavaThread "container-0" [_thread_blocked, id=17353, stack(0x00007ff1b4635000,0x00007ff1b4736000)]
  0x00007ff22cf8f000 JavaThread "ContainerBackgroundProcessor[StandardEngine[Tomcat]]" daemon [_thread_blocked, id=17352, stack(0x00007ff1b4736000,0x00007ff1b4837000)]
  0x00007ff1b0c44000 JavaThread "I/O dispatcher 8" [_thread_in_native, id=17349, stack(0x00007ff1d4672000,0x00007ff1d4773000)]
  0x00007ff1b0bd2000 JavaThread "I/O dispatcher 7" [_thread_in_native, id=17348, stack(0x00007ff1d4773000,0x00007ff1d4874000)]
  0x00007ff1b035f000 JavaThread "I/O dispatcher 6" [_thread_in_native, id=17347, stack(0x00007ff1d4874000,0x00007ff1d4975000)]
  0x00007ff1b007c000 JavaThread "I/O dispatcher 5" [_thread_in_native, id=17346, stack(0x00007ff1d4975000,0x00007ff1d4a76000)]
  0x00007ff1b0309800 JavaThread "I/O dispatcher 4" [_thread_in_native, id=17345, stack(0x00007ff1d4a76000,0x00007ff1d4b77000)]
  0x00007ff1b076e000 JavaThread "I/O dispatcher 3" [_thread_in_native, id=17344, stack(0x00007ff1d4b77000,0x00007ff1d4c78000)]
  0x00007ff1b01cc800 JavaThread "I/O dispatcher 2" [_thread_in_native, id=17343, stack(0x00007ff1d4c78000,0x00007ff1d4d79000)]
  0x00007ff1b0d72000 JavaThread "I/O dispatcher 1" [_thread_in_native, id=17342, stack(0x00007ff1d4d79000,0x00007ff1d4e7a000)]
  0x00007ff22e79b000 JavaThread "Thread-2" daemon [_thread_blocked, id=17341, stack(0x00007ff1fc08a000,0x00007ff1fc18b000)]
  0x00007ff22e73a000 JavaThread "pool-1-thread-1" [_thread_in_native, id=17340, stack(0x00007ff1fcd9c000,0x00007ff1fce9d000)]
  0x00007ff22c218000 JavaThread "Service Thread" daemon [_thread_blocked, id=17332, stack(0x00007ff1fddde000,0x00007ff1fdedf000)]
  0x00007ff22c20e000 JavaThread "C1 CompilerThread3" daemon [_thread_blocked, id=17331, stack(0x00007ff1fdedf000,0x00007ff1fdfe0000)]
  0x00007ff22c20c000 JavaThread "C2 CompilerThread2" daemon [_thread_blocked, id=17330, stack(0x00007ff1fdfe0000,0x00007ff1fe0e1000)]
  0x00007ff22c20a000 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=17329, stack(0x00007ff1fe0e1000,0x00007ff1fe1e2000)]
  0x00007ff22c207000 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=17328, stack(0x00007ff1fe1e2000,0x00007ff1fe2e3000)]
  0x00007ff22c205800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=17327, stack(0x00007ff1fe2e3000,0x00007ff1fe3e4000)]
  0x00007ff22c1d2800 JavaThread "Finalizer" daemon [_thread_blocked, id=17326, stack(0x00007ff1fe3e4000,0x00007ff1fe4e5000)]
  0x00007ff22c1ce000 JavaThread "Reference Handler" daemon [_thread_blocked, id=17325, stack(0x00007ff1fe4e5000,0x00007ff1fe5e6000)]

Other Threads:
=>0x00007ff22c1c6000 VMThread [stack: 0x00007ff1fe5e6000,0x00007ff1fe6e7000] [id=17324]
  0x00007ff22c213800 WatcherThread [stack: 0x00007ff1fdcdd000,0x00007ff1fddde000] [id=17333]

VM state:at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread:  ([mutex/lock_event])
[0x00007ff22c005e50] Threads_lock - owner thread: 0x00007ff22c1c6000
[0x00007ff22c006350] Heap_lock - owner thread: 0x00007ff128001000

Heap:
 PSYoungGen      total 466944K, used 454656K [0x0000000719800000, 0x0000000736d00000, 0x00000007c0000000)
  eden space 454656K, 100% used [0x0000000719800000,0x0000000735400000,0x0000000735400000)
  from space 12288K, 0% used [0x0000000736080000,0x0000000736080000,0x0000000736c80000)
  to   space 12800K, 0% used [0x0000000735400000,0x0000000735400000,0x0000000736080000)
 ParOldGen       total 225280K, used 34933K [0x00000005cc800000, 0x00000005da400000, 0x0000000719800000)
  object space 225280K, 15% used [0x00000005cc800000,0x00000005cea1d580,0x00000005da400000)
 Metaspace       used 66039K, capacity 67058K, committed 67456K, reserved 1110016K
  class space    used 6509K, capacity 6683K, committed 6784K, reserved 1048576K

Card table byte_map: [0x00007ff232022000,0x00007ff232fbf000] byte_map_base: 0x00007ff22f1be000

failed_mem_allocate 看上去是so中分配内存等失败了,so的接口代码中增加一些输出,进一步定位

F7ANTY
f7anty so文件是第三方的,不能增加输出
一年多之前 回复

太多了,难道不能捡重要的错误吗

F7ANTY
f7anty 显示的错误是 Internal Error (instanceKlass.cpp:3358), pid=17314, tid=0x00007ff1fe6e6700,导致出错的线程类型是VMThread(jvm的内部线程)
一年多之前 回复

上图中在crash的时候有输出 Failed: 0x0000000724e62b08 -> 0x0000000324c18200,通过hsdb分析附近的栈信息,如下

图片说明

图片说明

上图中标识的红框是不是表明yuv: ** BAD OOP 是一个坏的指针

先根据接口文档检查数据类型,如果没错的话可能是so问题,让其他人给个测试的函数再试试吧。

先根据接口文档检查数据类型,如果没错的话可能是so问题

你java类名要和so名称一致

第一步 建立一个监听类

建立监听类的作用是在应用中间件启动时自动执行加载程序。

1)创建一个类实现ServletContextListener 接口

2)实现contextInitialized方法

3)在项目的web.xml 文件中配置此监听类
第二步 添加动态库到系统变量

将dll/so文件所在的路径添加到系统环境java.library.path 中

添加过程需要使用到反射机制来进行,不能使用System.setProperty()进行设置,设置了也无效。直接看代码:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

private void addDirToPath(String s){
try {
//获取系统path变量对象
Field field=ClassLoader.class.getDeclaredField("sys_paths");
//设置此变量对象可访问
field.setAccessible(true);
//获取此变量对象的值
String[] path=(String[])field.get(null);
//创建字符串数组,在原来的数组长度上增加一个,用于存放增加的目录
String[] tem=new String[path.length+1];
//将原来的path变量复制到tem中
System.arraycopy(path,0,tem,0,path.length);
//将增加的目录存入新的变量数组中
tem[path.length]=s;
//将增加目录后的数组赋给path变量对象
field.set(null,tem);
} catch (Exception e) {
e.printStackTrace();
}
}
第三步 加载动态库文件

接下来就可以写上下文初始化的方法了:
?
1
2
3
4
5
6
7
8

public void contextInitialized(ServletContextEvent arg0) {
//获取存放dll文件的绝对路径(假设将dll文件放在系统根目录下的WEB-INF文件夹中)
String path=arg0.getServletContext().getRealPath("WEB-INF");
//将此目录添加到系统环境变量中
addDirToPath(path);
//加载相应的dll/so文件,注意要将'\'替换为'/'
System.load(path.replaceAll("\\","/")+"/XXXX.dll");
}
第四步 重启启动应用中间件(Tomcat|Weblogic)

至此就可以在你的java程序中使用dll/so文件的方法了。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
通过JNI调用第三方动态库(生成两个.so文件)
参考网上一些资料,实现了通过JNI调用第三方动态库.so,个人觉得重点在Make文件改写,例外注意确保程序完全正确,我开始就是程序中个字母写错而浪费了好多时间。
jni调用so文件问题
[code=Java] public class CplusGraphics rn staticrn System.out.println("方法被调用之前--------------");rn System.loadLibrary("ShapeRead");rn System.out.println("方法被调用--------------");rn rn public static native int GetShpType(); rn [/code]rnrn[code=C/C++] /* DO NOT EDIT THIS FILE - it is machine generated */rn #include rn /* Header for class com_graphics_base_CplusGraphics */rnrn #ifndef _Included_com_graphics_base_CplusGraphicsrn #define _Included_com_graphics_base_CplusGraphicsrn #ifdef __cplusplusrn extern "C" rn #endifrn /*rn * Class: com_graphics_base_CplusGraphicsrn * Method: GetShpTypern * Signature: ()Irn */rn JNIEXPORT jint JNICALL Java_com_graphics_base_CplusGraphics_GetShpTypern (JNIEnv *, jobject);rnrn #ifdef __cplusplusrn rn #endifrn #endif[/code]rn[code=C/C++] #include "com_graphics_base_CplusGraphics.h"rn #include rnrn #ifndef _Included_com_fileText_fileReadrn #define _Included_com_fileText_fileReadrn #ifdef __cplusplusrnrn extern "C" rn #endifrn //jobject arraylist;rnrn JNIEXPORT jint JNICALL Java_com_graphics_base_CplusGraphics_GetShpTypern (JNIEnv *env, jobject obj)rnrn /*rn * Class: CplusGraphicsrn * Method: SetShpTypern * Signature: (I)Vrn */rn rn int i = 100;rn jint type = i;rn return type;rn rnrn #ifdef __cplusplusrn rn #endifrn #endifrn[/code]rnrnrn //其他类里面调用rn System.out.println(CplusGraphics.GetShpType());rnrnrn然后编译没问题,android模拟器里面运行程序,屏幕会卡住。rn而rnSystem.out.println("方法被调用之前--------------");rn System.loadLibrary("ShapeRead");rn System.out.println("方法被调用--------------");rn中只有第一句输出了。就卡在第二句java语句上了。 求各位大大帮忙看看哪里错了。rnrn[img=http://www.eoeandroid.com/data/attachment/forum/201107/09/200906p8mq2xcz989mlnlp.jpg][/img]
【so文件】添加第三方so文件
1、把相关文件放于 libs 目录下2、打开 app 目录的 build.gradle ,在 android{ } 目录下,添加以下代码sourceSets { main { jniLibs.srcDirs = ['libs'] } }
JNI调用第三方库文件
java的本地调用(JNI),经过验证完全成功的
Android JNI 调用非JNI规范的so文件
请问Android中可以使用JNI调用非JNI规范纯C函数编译出的so文件吗rnrn我使用的是针对特殊平台产生的非JNI规范的so文件,在Android官网看到谷歌采用了一种新的make方式,通过Cmake和CMakeLists.txt来链接编译rn我看到官方的源码[谷歌官方示例](https://github.com/googlesamples/android-ndk/tree/master/native-activity/app/src/main/cpp "")直接放在默认的libry目录下,我想让他在自己的目录下找,但是最新的这种CMake方式,不知道so文件和头文件的目录应该怎么建立。[谷歌官方NDK](https://developer.android.com/studio/projects/add-native-code.html#new-project "")rnrn```rn add_library( iconvrn SHAREDrn IMPORTED )rnset_target_properties( # Specifies the target library.rn iconvrnrn # Specifies the parameter you want to define.rn PROPERTIES IMPORTED_LOCATIONrnrn # Provides the path to the library you want to import.rn /libs/src/armeabi/libiconv.so)rn#include_directories( imported-lib/src/include/ )rnrntarget_link_libraries( # Specifies the target library.rn native-librnrn # Links the target library to the log libraryrn # included in the NDK.rn iconv $log-lib )rn```rn但是Make时一直报错,显示iconv.so needed by native-lib.so ; missing or no known rule to make it
Jni调用第三方的so库
Jni调用第三方的so库; 博文地址:http://blog.csdn.net/csqingchen/article/details/45247541
JNI调用第三方动态库
有关在android平台上 JNI调用第三方动态库的例子
JNI调用第三方so库
1.编译第三方so库 第三方so库必须经过交叉编译for arm的库,由于Android是arm架构,linux 自带的GCC编译出来的是X86架构,不然会提示incompatible target 不兼容目标。 ndk(android-ndk-r9)提供Android的交叉编译,Linux(Ubuntu15.04)系统下编译so库 linux终端进入android-ndk-r9的根目录,$
安卓jni之so文件打包和调用
详情点击我的github 如果有帮助到您,请给个star
使用JNI:调用第三方jar包
本课程起始于基础的开发环境搭建和Qt Creator介绍,帮助初学者入门;着力于Qt的内在机制,由浅入深介绍信号与槽、Qt模板库、事件、文件处理、XML、网络、多线程、各种GUI控件、布局管理器等各种Qt基础主题(这些主题可同时在Qt桌面编程和Android平台上使用),同时辅以简洁有效有针对性的实例程序(每个示例程序都可以在 Android 平台上运行)。
JNI调用第三方C++ dll
     最近工作需要要调用第三方厂商提供的dll,学了下JNI,来分享下。        说明:使用JNI来调用dll是JAVA调用符合JNI规范的dll,如需调用第三方的dll是在符合JNI规范的dll中再用c++掉用第三方的dll中的方法。       操作步骤:     1.新建java类将需要掉用的方法声明为native,增加导入dll的代码,例如:     publi...
jni调用第三方so库demo
在研究了几天JNI后,在自己生成的so库中调用第三方so库时遇到问题,解决之后特意整理、记录一下。 这是一个demo,在酷派、小米手机上测试可以运行。 相关详见我的博客: http://blog.csdn.net/u013403478/article/details/52134870
Ndk(jni)调用第三方的so库
本文主要讲述如何在jni中调用第三方共享so 项目源码地址:https://github.com/chenjim/thirdPartyJniSo 生成第三方共享.so库 生成HelloJni.java需要的.so库 注意问题 必须用ndk编译生成的.so,否则提示".so: File format not recognized"。 Application.mk 中APP_ABI的配置必须相同
JNI调用第三方dll实例
该实例是我自己写的jni调用第三方dll例子,可以作为参考,运行环境vs2010,其他环境没试过。
AndroidStudio JNI开发,通过Cmake编译so文件
官方文档:https://developer.android.com/ndk/guides/cmake 1、创建项目,在首界面勾选上Include C++ support,然后点击next,直至创建完成 2、项目会默认生成jni事例代码,观察项目结构,在app/src/main下有个cpp文件夹,我们要写或者要添加的c/c++文件就写在该文件夹下。 3、打开MainActivity.java...
androidStudio JNI开发,通过CMake编译so文件
NDK下载页面 NDK入门指南 CMake入门指南
Android 在jni编译完成后没有出现so文件
Android 在jni编译完成后没有出现so文件
Android Studio 调用写好的SO文件(JNI)
package org.ccser.warning; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import org.w3c.dom.Text; /** * Created by Administrator o
JNI调用多个so文件的问题,求教
大家好!rn我最近在做一个项目,需要用opencv里面的一些函数。现在我已经利用opencv中的一些函数写好了代码,并按照网上的教程生成了.so的动态链接库。问题是这个链接库中用到了opencv中的函数,在通过jni加载这个动态链接库并调用其中的函数的时候就会报错,提示说用到的opencv中的函数是“undefined symbol”。请问各位大神这个问题需要如何解决?
通过spark-submit运行java程序
原来程序是将所有jar打包到libs目录下,然后运行生成好的run.sh。现在要使用spark-submit将它提交到spark上运行。几经波折之后,终于圆满完成。 首先遇到的问题是如何使用gradle将工程打包成可执行的jar文件。这个问题网上已有答案,就是使用插件 "com.github.johnrengelman.shadow"。gradle的配置如下: apply plugin: '
Java调用不支持JNI的Linux so文件
Java调用不支持JNI的Linux so文件
Android NDK调用不符合jni规范的so文件
我们在使用Android静态加载so库的时候,一般都需要这个so库是符合jni命名规范的,像这样: Java_全类名_方法名 但是可能会遇到一些比较特殊的情况,同事只给了你一个so库,这个so库并不是用的jni命名,除此之外,他还给了你一个so库中函数的头文件,这时候我们就需要自己再次包装这个so库了。 建立java文件 这里建立的java文件命名可以是自定义的,而不需要遵守某...
Android Eclipse JNI 调用 so文件加载问题
Android Eclipse JNI 调用 so文件加载问题
Android studio调用第三方so文件(成功)
踩了很多坑,走了很长的路,网上各种各样的说法把我整得晕头转向,最终还是成功了,这里自己总结一下,也顺便分享有需要的伙伴。 如何利用ndk编译我这里就不说了。在linux中进行ndk编译:https://blog.csdn.net/FZeroTHero/article/details/89308312 在Android studio中ndk编译:https://blog.csdn.net/FZero...
Android Jni之编写so文件
开发中我们在集成第三方的时候经常用到一些so文件等,但这个so文件是如何编写的?并且我们为什么要用so文件?接下来我们就慢慢谈论一下这两个问题。     我们为什么要用so文件? 一些基础的概念就不说了:首先我们知道so文件中有我们需要的方法,我们可以直接调用,说明对我们开发方便。但是我们既然用起来方便,我们为什么不直接写成java类,供我们直接调用呢?原因有两个:1、so文件不太容易逆向(也...
Android之so文件、JNI和NDK
Android之so文件、JNI和NDK
android ndk调用第三方so文件的方法
修改CMakeLists.txt #For more information about using CMake with Android Studio, read the #documentation: https://d.android.com/studio/projects/add-native-code.html #Sets the minimum version of CMake req...
windows下使用eclipse java程序调用.so文件
问题描述: Java项目,做中间件的,之前是在Linux系统下开发,用JNI调用内核部提供的.so文件,但是现在又要Windows系统下测试运行情况,所以提出了题目中的问题:怎么在Windows下使用eclipse java程序调用.so文件?上网查全是在Linux下调.so和在Windows下调.dll文件,跟我的情况不匹配。以下是我的思考与总结。思路: 这个问题的本质其实在于JNI的缺点—-破坏
Java应用Crash ! JNI
请高手帮帮忙:rnrn[color=#FF0000]运行时显示错误:[/color]rn#rn# An unexpected error has been detected by HotSpot Virtual Machine:rn#rn# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x02dc12c3, pid=2364, tid=1140rn#rn# Java VM: Java HotSpot(TM) Client VM (1.4.2_11-b06 mixed mode)rn# Problematic frame:rn# C [aa.dll+0x12c3]rn#rn# An error report file with more information is saved as hs_err_pid2364.logrn#rn# If you would like to submit a bug report, please visit:rn# http://java.sun.com/webapps/bugreport/crash.jsprn#rn[color=#FF0000]rnhs_err_pid2364.log文件中显示:[/color]rnrn#rn# An unexpected error has been detected by HotSpot Virtual Machine:rn#rn# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x02dc12c3, pid=2364, tid=1140rn#rn# Java VM: Java HotSpot(TM) Client VM (1.4.2_11-b06 mixed mode)rn# Problematic frame:rn# C [cscmcoms.dll+0x12c3]rn#rnrn--------------- T H R E A D ---------------rnrnCurrent thread (0x00822380): JavaThread "main" [_thread_in_native, id=1140]rnrnsiginfo: ExceptionCode=0xc0000005, writing address 0x30303030rnrnRegisters:rnEAX=0x30303030, EBX=0x0006d228, ECX=0x0006d210, EDX=0x00000030rnESP=0x0006d0d8, EBP=0x00000001, ESI=0x31303030, EDI=0x0006d144rnEIP=0x02dc12c3, EFLAGS=0x00010206rnrnTop of Stack: (sp=0x0006d0d8)rn0x0006d0d8: 00aab98c 00aa25ab 0006d210 30303030rn0x0006d0e8: 31303030 30303130 30313030 00313030rn0x0006d0f8: 01000000 01000000 01000000 30320100rn0x0006d108: 31303730 30323130 31303730 30303130rn0x0006d118: 30303030 00003130 00000000 00000000rn0x0006d128: 00000000 00000000 00000000 00000000rn0x0006d138: 00000000 00000000 00000000 00000060rn0x0006d148: 00000000 00000002 0006f974 00000002 rnrnInstructions: (pc=0x02dc12c3)rn0x02dc12b3: 24 10 85 f6 7e 11 8b 44 24 0c 8b 4c 24 08 8a 11rn0x02dc12c3: 88 10 40 41 4e 75 f7 5e c3 cc cc cc cc 51 56 8d rnrnrnStack: [0x00030000,0x00070000), sp=0x0006d0d8, free space=244krnNative frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)rnC [cscmcoms.dll+0x12c3]rnrn[error occurred during error reporting, step 120, id 0xc0000005]rnrnJava frames: (J=compiled Java code, j=interpreted, Vv=VM code)rnj jp.co.hitachi.wms.cmnlib.Jnicore.Sakujo([BLjava/lang/String;II)I+0rnj jp.co.hitachi.wms.cmnlib.Jnicore.sakujo(Ljava/lang/String;II)[B+11rnj jp.co.hitachi.wms.commons.MfileStruct.sakujo(Ljava/lang/String;)I+15rnj jp.co.hitachi.wms.test.WmsTest.testSakujo()V+359rnj jp.co.hitachi.wms.test.WmsTest.main([Ljava/lang/String;)V+0rnv ~StubRoutines::call_stubrnrn--------------- P R O C E S S ---------------rnrnJava Threads: ( => current thread )rn 0x0082fe60 JavaThread "CompilerThread0" daemon [_thread_blocked, id=2212]rn 0x0082ea90 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=1976]rn 0x0082bc30 JavaThread "Finalizer" daemon [_thread_blocked, id=3792]rn 0x0082a890 JavaThread "Reference Handler" daemon [_thread_blocked, id=1816]rn=>0x00822380 JavaThread "main" [_thread_in_native, id=1140]rnrnOther Threads:rn 0x00829ab0 VMThread [id=2352]rn 0x00831f70 WatcherThread [id=3076]rnrnVM state:not at safepoint (normal execution)rnrnVM Mutex/Monitor currently owned by a thread: NonernrnHeaprn def new generation total 576K, used 282K [0x10010000, 0x100b0000, 0x104f0000)rn eden space 512K, 55% used [0x10010000, 0x10056870, 0x10090000)rn from space 64K, 0% used [0x10090000, 0x10090000, 0x100a0000)rn to space 64K, 0% used [0x100a0000, 0x100a0000, 0x100b0000)rn tenured generation total 1408K, used 0K [0x104f0000, 0x10650000, 0x14010000)rn the space 1408K, 0% used [0x104f0000, 0x104f0000, 0x104f0200, 0x10650000)rn compacting perm gen total 4096K, used 1227K [0x14010000, 0x14410000, 0x18010000)rn the space 4096K, 29% used [0x14010000, 0x14142ff8, 0x14143000, 0x14410000)rn................
jni文件编译成.so文件
1、jni文件在编译成.so文件的时候,必须首先下载ndk 2、配置好ndk的环境变量 3、进入jni文件以后,点击shift+鼠标右键,显示黑窗口。输入命令ndk_build即可
JNI动态加载so文件
最近在工作中遇到一个问题,就是一些c/c++工程师写好的代码要移植到移动端使用,但是这些函数本身不可能符合JNI规范,打包出来的so动态依赖库是没办法直接调用的。所以还是要写jni来动态加载so文件,把他们桥接起来,Jni怎么写这里就不说了,在c/c++文件里#include 这个头文件,写个函数指针,利用dlopen()函数就可以实现动态加载so文件。这里有如下几点心得体会: ①打包成
如何引用第三方SO文件
各位神,rn 鄙人的项目里已经有了3个SO文件,这三个SO文件都是自己写C语言然后生成的。当然也成功了。无话可说。rn 问题是,鄙人现在要引用BAIDU的locSDK3.SO,也就是GPRS。请问该如何添加呢?我直接把locSDK3.SO放进armeabi文件夹里,会被删除掉。请问该如何处理,一定要您自己做过的哦。rnrn我的做法如下:rn 第一步: 在JNI文件夹下面生成一个新的目录prebuilt,然后在里面生成一个android.mk,把locSDK3.SO COPY进prebuilt.此android.mk 内容如下:rn LOCAL_PATH := $(call my-dir)rn rn include $(CLEAR_VARS)rn rn LOCAL_MODULE := locSDK3rn LOCAL_SRC_FILES := liblocSDK3.sorn include $(PREBUILT_SHARED_LIBRARY)rn rnrn 第二步: 在jni目录下android.mk文件后面添加rninclude $(CLEAR_VARS)rnrnLOCAL_SHARED_LIBRARIES := prebuilt/locSDK3rninclude $(LOCAL_PATH)/prebuilt/Android.mkrnrnrn这时在libs目录下会新生成一个liblocSDK3.so文件,只有5K。系统会提示安装这个文件。rnInstall : liblocSDK3.so => libs/armeabi/liblocSDK3.sorn我觉得这是有问题的。因为我看armeabi目录下的liblocSDK3.so 只有5K。而真实的liblocSDK3.so有40Krn
运行sosreport导致OL7.3操作系统crash
运行sosreport导致OL7.3操作系统crash
调用opencv库的destroyAllWindows()导致crash的解决方法
大致发生的环境条件是: 在QT的工程里,起了一个新线程,并且在这个新线程里调用opencv库的函数cv::imshow("video", frame)打开了一个新窗口。最后希望调用destroyAllWindows()来关闭打开的窗口,导致应用crash。
求救,调用GetStringUTFChars导致JVM crash
JNI不是很熟,请高手指点下如何定位/debug,多谢!!!rnrnJNI代码实现如下:rnrn--------------------------------------------------------------------------------------------rn[code=Java]JNIEXPORT jint JNICALL Java_client_common_ClientJNI_GetPolicyrn(JNIEnv * env, jclass cl, jstring login_name, jstring ip_addr, jobject obj)rnrn std::cout << "===============GetPolicy." << std::endl;rn const char * c_username = env->GetStringUTFChars(login_name, NULL);rn if (NULL == c_username) rn std::cout << "Failed to get user name." << std::endl;rn return -1;rn rn const char * c_address = env->GetStringUTFChars(ip_addr, NULL);rn if (NULL == c_address ) rn std::cout << "Failed to get address." << std::endl;rn env->ReleaseStringUTFChars(login_name, c_username);rn return -1;rn rnrn // 访问数据库,根据c_username 和 c_address 读取数据....rnrn env->ReleaseStringUTFChars(login_name, c_username);rn env->ReleaseStringUTFChars(ip_addr, c_address);rn return 0;rn[/code]rn--------------------------------------------------------------------------------------------rnrntomcat里的Java程序会调用这个方法,一个连接时没有问题。当同时20个连接访问的时候,JVM发生了crash。rntomcat 的catalina.out:rn--------------------------------------------------------------------------------------------rnINFO: Server startup in 1481 msrn===============GetPolicy.rn//前面多个访问正常,然后突然就歇菜了... rn===============GetPolicy.rn#rn# A fatal error has been detected by the Java Runtime Environment:rn#rn# SIGSEGV (0xb) at pc=0xf7af14f8, pid=8715, tid=4088118160rn#rn# JRE version: 6.0_23-b05rn# Java VM: Java HotSpot(TM) Client VM (19.0-b09 mixed mode, sharing linux-x86 )rn# Problematic frame:rn# V [libjvm.so+0x4324f8]rn#rn# An error report file with more information is saved as:rn# /var/hs_err_pid8715.logrn#rn# If you would like to submit a bug report, please visit:rn# http://java.sun.com/webapps/bugreport/crash.jsprn#rn--------------------------------------------------------------------------------------------rnrn/var/hs_err_pid8715.log文件很长,部分内容:rnrn--------------------------------------------------------------------------------------------rnRegister to memory mapping:rnrnEAX=0x6c717370rn0x6c717370 is pointing to unknown locationrnrnEBX=0xf7b930b0rn0xf7b930b0: in /usr/iwss/AdminUI/jre/lib/i386/client/libjvm.so at 0xf76bf000rnrnECX=0x00000000rn0x00000000 is pointing to unknown locationrnrnEDX=0x6c717370rn0x6c717370 is pointing to unknown locationrnrn...rnrnStack: [0xf3a6b000,0xf3abc000], sp=0xf3aba138, free space=316krnNative frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)rnV [libjvm.so+0x4324f8]rnV [libjvm.so+0x238a7b]rnV [libjvm.so+0x238b15]rnV [libjvm.so+0x260759]rnC [libRClientJNI.so+0x243c8] _ZN10_Jv_JNIEnv12NewStringUTFEPKc+0x1crnC [libRClientJNI.so+0x23e48] Java_client_common_ClientJNI_GetPolicy+0x5a4rnj client.common.ClientJNI.GetPolicy(Ljava/lang/String;Ljava/lang/String;Ljava/lang/ObjectI+0rn--------------------------------------------------------------------------------------------rnrn多谢!
jni开发时第三方so文件被删除,怎么办
[img=https://img-bbs.csdn.net/upload/201409/24/1411527380_661740.png][/img][img=https://img-bbs.csdn.net/upload/201409/24/1411527388_787119.png][/img]rn刚接触jni , 每次编译或运行项目时候会清空libs下so文件。该怎么配置呢
JNI问题,在c++中调用java程序连接数据库时,出现错误
JNI问题rnrn在c++中调用java程序连接数据库时,出现错误,提示如下: rnjava.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerrn at java.net.URLClassLoader$1.run(URLClassLoader.java:200)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(URLClassLoader.java:188)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:306)rn at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:251)rn at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)rn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Class.java:164)rn at sx.Conn.getCon(Conn.java:37)rn at sx.Conn.getStmt(Conn.java:174)rn at sx.Conn.getData(Conn.java:77)rnNo suitable driverrnnullrnjava.lang.NullPointerExceptionrn at sx.Conn.getStmt(Conn.java:175)rn at sx.Conn.getData(Conn.java:77)rn An unexpected error has been detected by HotSpot Virtual Machine:rnrn Internal Error (455843455054494F4E530E4350500101), pid=4072, tid=2504rn#rn# Java VM: Java HotSpot(TM) Client VM (1.5.0_04-b05 mixed mode, sharing)rn# An error report file with more information is saved as hs_err_pid4072.rn#rn# If you would like to submit a bug report, please visit:rn# http://java.sun.com/webapps/bugreport/crash.jsprn#rnPress any key to continuernrn但是单独执行java程序时,却无法通过,请高手指教rnrn
vector循环遍历导致程序退出
同样JAVA程序, VECTOR循环发送WEBSERVICE, 在WINDOWS下运行几百次循环都没问题, 在LINUX下循环几十次突然程序退出, 也没报异常. 是什么原因?? rnrn
关于UITableViewController导致程序退出
我写了一个继承自UITableViewController的子类,其中一个函数会导致程序一启动就挂掉。我把那个函数给注释掉程序就不会出错了,那个函数是:rn[code=C/C++]rn- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionrnrn return [[masterColorList objectAtIndex:section] count];rnrn[/code]
对话框导致程序退出出错
我在一个FormView的程序中进行图像识别的任务rn设置了一些按钮 分别rn捕捉图像: 分配内存捕捉一帧图像rn灰度化 : 对图像进行灰度化处理rn图像平滑: 弹出一个对话框进行设计平滑算子进行平滑计算rnrn现在出现这个问题:rn如果我三个按钮一次按下来 程序完全正常rn但是如果我没动按钮 或者按了第一个 或者前两个 没按第三个rn关闭程序就出现就会出现 引用内存不能为read的错误rn检查指针没有问题,这到底是怎么回事呢rnrn大家看看到底可能是什么地方的问题 是控件哪里没设好么?
相关热词 c# stream 复制 android c# c#监测窗口句柄 c# md5 引用 c# 判断tabtip 自己写个浏览器程序c# c# 字符串变成整数数组 c#语言编程写出一个方法 c# 转盘抽奖 c#选中treeview