首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将代码移动到包中后的UnsatisfiedLinkError

将代码移动到包中后的UnsatisfiedLinkError
EN

Stack Overflow用户
提问于 2019-06-15 03:50:10
回答 1查看 133关注 0票数 0

我正在处理一个需要使用.so库(ubuntu18.04)的项目,当我将java代码放入/src文件夹(我使用IntelliJ的想法)时,一切都运行良好,但是当我将代码移动到一个命名的包(Smutil)之后,它会导致一些错误,比如“线程中的异常”主“java.lang.UnsatisfiedLinkError: smutil.GmSSL.digest(Ljava/lang/String;[b)”[B“)。

这是我的密码

代码语言:javascript
复制
package smutil;
public class GmSSL {

public native String[] getVersions();
public native String[] getCiphers();
public native String[] getDigests();
public native String[] getMacs();
public native String[] getSignAlgorithms();
public native String[] getPublicKeyEncryptions();
public native String[] getDeriveKeyAlgorithms();
public native byte[] generateRandom(int length);
public native int getCipherIVLength(String cipher);
public native int getCipherKeyLength(String cipher);
public native int getCipherBlockSize(String cipher);
public native byte[] symmetricEncrypt(String cipher, byte[] in, byte[] key, byte[] iv);
public native byte[] symmetricDecrypt(String cipher, byte[] in, byte[] key, byte[] iv);
public native int getDigestLength(String digest);
public native int getDigestBlockSize(String digest);
public native byte[] digest(String algor, byte[] data);
public native String[] getMacLength(String algor);
public native byte[] mac(String algor, byte[] data, byte[] key);
public native byte[] sign(String algor, byte[] data, byte[] privateKey);
public native int verify(String algor, byte[] digest, byte[] signature, byte[] publicKey);
public native byte[] publicKeyEncrypt(String algor, byte[] in, byte[] publicKey);
public native byte[] publicKeyDecrypt(String algor, byte[] in, byte[] privateKey);
public native byte[] deriveKey(String algor, int keyLength, byte[] peerPublicKey, byte[] privateKey);
public native String[] getErrorStrings();

static {
    System.loadLibrary("gmssljni");
}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-15 09:40:11

您可能会将.so文件打包到JAR中。请注意,一旦您有了.so,加载库就不那么容易了。

为了加载共享库,您必须确保它在文件系统上。您可以通过将其提取到临时位置来克服此问题。

在这里查看一个完整的示例,说明这个主题:

https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo031

基本上,你要做的是:

  • 在JAR中找到您的资源
  • 将其提取到临时位置
  • 用户System.load(fullPathToFile)

(就是这样:)

和JNI玩得开心!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56607165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档