简体   繁体   中英

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. Now i have the libcrypto.so that i need, but i don´t know how to link it with my wrapper.

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

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. 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.

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. You might want to rename the OpenSSL library though, because the system already has a libcrypto.so . As for your own JNI wrapper, just take the shared library sample from the NDK and modify to use your own files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM