[英]How to link crypto shared library in Android JNI
I am writing a wrapper to use some functions of crypto. 我正在编写一个包装程序以使用某些加密功能。 I build crypto lib from openssl-android with Android-NDK.
我使用Android-NDK从openssl-android构建crypto lib。 Now i have the libcrypto.so that i need, but i don´t know how to link it with my wrapper.
现在,我有了所需的libcrypto.so,但我不知道如何将其与包装器链接。
My project tree is like this 我的项目树是这样的
(proj root)
|
|->(src)
|->(src)-> com.package
|->(src)-> com.package->NativeCipher.java
|
|->(jni)
|->(jni)->Android.mk
|->(jni)->NativeCipher.c
NativeCipher.java NativeCipher.java
public class NativeCipher {
static {
System.loadLibrary("crypto");
System.loadLibrary("NativeCipher");
}
public static native byte[] AESEncrypt(byte[] in, byte[] key);
}
NativeCipher.c 本机密码
#include <string.h>
#include <jni.h>
#include <aes.h>
jbyteArray Java_com_package_NativeCipher_AESEncrypt(JNIEnv* env, jobject this, jbyteArray in, jbyteArray key)
{
// All my code here
}
I need to use the functions of #include that crypto provides. 我需要使用crypto提供的#include功能。 However, i don't know what to do with the .so files that NDK generates and how to make the Android.mk file to build.
但是,我不知道NDK生成的.so文件如何处理以及如何构建Android.mk文件。
Thanks in advance, i tried to be as specific as posible. 在此先感谢,我尽力做到尽可能具体。
Native libraries go to the libs/armeabi
or libs/armeabi-v7a
of your Android project. 本机库转到您的Android项目的
libs/armeabi
或libs/armeabi-v7a
。 You might want to rename the OpenSSL library though, because the system already has a libcrypto.so
. 但是,您可能想重命名OpenSSL库,因为系统已经有一个
libcrypto.so
。 As for your own JNI wrapper, just take the shared library sample from the NDK and modify to use your own files. 至于您自己的JNI包装器,只需从NDK中获取共享库示例,然后进行修改以使用您自己的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.