How to add openssl lib in android studio with experimental gradle plugin (NDK)?
<p>I'm trying to add openSSL library to my project in <code>android studio 2.0 preview 7</code> with <code>experimental gradle plugin</code>. </p>

<pre><code>dependencies {
    classpath 'com.android.tools.build:gradle-experimental:0.4.0'
}
</code></pre>

<p>What I did is that I downloaded the <code>openSSL library</code> and put it into <code>jni</code> folder. And I have another .c file that uses this library. I have included the files that I need and there are no errors in code. My <code>.c</code> file name is <code>hello-jni.c</code> and I declared it into my <code>build.gradle (module: app)</code> like this:</p>

<pre><code>android.ndk {
    moduleName = "hello-jni"
}
</code></pre>

<p>and also I loaded my library in my MainActivity like this:</p>

<pre><code>static {
    System.loadLibrary("hello-jni");
}
</code></pre>

<p>but when I try to build my project, an error shows up like this:</p>

<pre><code>Error:(51) undefined reference to `RSA_generate_key'
Error:error: ld returned 1 exit status
Error:Execution failed for task ':app:linkArm64-v8aDebugHello-    jniSharedLibrary'.
&gt; A build operation failed.
  Linker failed while linking libhello-jni.so.
</code></pre>

<p>My hello-jni.c source code:</p>

<pre><code>#include &lt;jni.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;unistd.h&gt;
#include &lt;stdio.h&gt;
#include "boringssl/crypto/openssl/base.h"
#include "boringssl/crypto/openssl/rsa.h"
#include "boringssl/crypto/openssl/pem.h"

#define KEY_LENGTH  2048
#define PUB_EXP     3
#define PRINT_KEYS
#define WRITE_TO_FILE 0

size_t pri_len;            // Length of private key
size_t pub_len;            // Length of public key
char   *pri_key;           // Private key
char   *pub_key;           // Public key
char   msg[KEY_LENGTH/8];  // Message to encrypt
char   *encrypt = NULL;    // Encrypted message
char   *decrypt = NULL;    // Decrypted message
char   *err;               // Buffer for any error messages

JNIEXPORT jstring JNICALL
Java_com_example_ndktest_SignUpActivity_testString(JNIEnv *env, jobject activity) {

// In this line, the error happens!(in build time)
RSA *keypair = RSA_generate_key(KEY_LENGTH, PUB_EXP, NULL, NULL);

//continue to work with key pair ...

return "some jstring";
}
</code></pre>