我正在处理一个需要使用.so库的项目(ubuntu 18.04),当我将Java代码放在/ src文件夹中(我正在使用IntelliJ Idea)时,一切工作正常,但是在我移动之后我的代码放入命名包(smutil),它会引起一些错误,例如“线程“ main”中的异常” java.lang.UnsatisfiedLinkError:smutil.GmSSL.digest(Ljava / lang / String; [B] [B“
这是我的代码
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");
}
}
答案 0 :(得分:0)
您可能将.so
文件打包到JAR中。请注意,一旦将.so
放在这里,加载库就不那么容易了。
为了加载共享库,您必须确保它在文件系统上。您可以将其提取到临时位置来解决此问题。
在这里查看说明该主题的完整示例:
https://github.com/mkowsiak/jnicookbook/tree/master/recipeNo031
基本上,您要做的是:
System.load(fullPathToFile)
就这样:)
与JNI玩得开心!