如何在普通的非Android Java应用程序中使用NDK编译的JNI库? [英] How to use NDK-compiled JNI library in a normal non-Android Java application?

查看:64
本文介绍了如何在普通的非Android Java应用程序中使用NDK编译的JNI库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JNI库,供NDK的Android应用程序使用. 我没有资源,只有一些拱门的编译过的.so文件.

I have a JNI library that was made to be used by Android app with NDK. I do not have sources, only compiled .so files for some archs.

我想在64位x86 linux PC上的简单控制台Java应用程序中从此库中调用函数.

I want to call functions from this library in a simple console Java application on a 64-bit x86 linux PC.

我所做的:

  1. 我从x86_64文件夹中获取了库,并使用System.loadLibrary
  2. 将其加载到了Java程序中
  3. 试图启动程序,并收到UnsatisfiedLinkError及其详细信息liblog.so: cannot open shared object file: No such file or directory.
  4. 所以我从官方NDK处获取了用于x86_64 arch的liblog.so并也加载了它,然后在libstdc++.so: cannot open shared object file: No such file or directory上出现了相同的错误
  5. 为libstdc ++.so库提供了相同的功能,并获得了/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header.
  6. 打开libc.so,它似乎只是一个文本文件...已将其替换为正确的libc.so文件
  7. 最后在我的库中出现了undefined symbol: __stack_chk_guard注释的UnsatisfiedLinkError.看起来我的图书馆对Android的使用非常严格
  1. I took the library from x86_64 folder and loaded it in my Java program using System.loadLibrary
  2. Tried to launch the program and got UnsatisfiedLinkError with details liblog.so: cannot open shared object file: No such file or directory.
  3. So I took liblog.so for x86_64 arch from official NDK and loaded it too, then got a same error with libstdc++.so: cannot open shared object file: No such file or directory
  4. Did the same thing for libstdc++.so library and got this /usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header.
  5. Opened libc.so and it appeared to be just a text file... Replaced it with the proper libc.so file
  6. Finally got UnsatisfiedLinkError for my library with undefined symbol: __stack_chk_guard comment. Looks like my library is strongly tightened with Android things

在没有任何特定于Android的程序的情况下,如何在普通程序中使用此库?

What should I do to use this library in my normal program without anything Android-specific?

推荐答案

仅用几句话-Android和台式机Linux二进制文件不兼容,即使它们针对的是相同的CPU体系结构.

Just in few words - Android and desktop Linux binaries are incompatible, even if they are targeted to the same CPU architecture.

这篇关于如何在普通的非Android Java应用程序中使用NDK编译的JNI库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆