At the beginning, I have to say I already searched around as many possible answers as I can to my answer. Some of them are really helpful, but not in Android Studio way. Also, I can get my JNI worked with the well-known example "getStringFromNative()", so please don't give me this kind of links. What I have tried so far :
1. structure of my directory
app |- src |- main |- java |- jni |- libs |- libcrypto.a |- libssl.a |- openssl |- xxxxx.h |...... -> those .h file of openssl |- com_ais_ndksample_MainActivity.h |- CipherModule.cpp |- CipherModule.h 2. build.gradle
apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion "23.0.0 rc3" defaultConfig { applicationId "com.ais.ndksample" minSdkVersion 16 targetSdkVersion 22 versionCode 1 versionName "1.0" ndk { moduleName "JniDemo" } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.pro' } } sourceSets { main { jni.srcDirs = ['src/main/jni'] jniLibs.srcDirs = ['src/main/jni/libs'] } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.1' } The errors occurred in my CipherModule.cpp, I have several statement on the top as below:
#include "CipherModule.h" #include <openssl/aes.h> #include <stdio.h> #include <iostream>
and the #include shows warning that Unused import statement, but I did use that. When I built, I got the error message indicated as followed:
undefined reference to `AES_set_encrypt_key` undefined reference to `AES_cbc_encrypt` As a result, I doubted that I didn't make my openssl library right, but I did specify it in my build.gradle. I had made so much efforts on this and got no luck. Any clue or thought would be appreciated!!!!
.afiles.