title: No implementation found for int com.example.nimashahbazi.mooshak.EncryptingActivity.encrypt
body: <p>I am trying to use a C++ code in an android app but I keep getting this error (no need to mention this is my first time using NDK):</p>
  
  <pre><code>com.example.nimashahbazi.mooshak E/art: No implementation found for int com.example.nimashahbazi.mooshak.EncryptingActivity.encrypt(java.lang.String, java.lang.String, java.lang.String) (tried Java_com_example_nimashahbazi_mooshak_EncryptingActivity_encrypt and Java_com_example_nimashahbazi_mooshak_EncryptingActivity_encrypt__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2)
  com.example.nimashahbazi.mooshak D/AndroidRuntime: Shutting down VM
  com.example.nimashahbazi.mooshak E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.nimashahbazi.mooshak, PID: 17797
  java.lang.UnsatisfiedLinkError: No implementation found for int com.example.nimashahbazi.mooshak.EncryptingActivity.encrypt(java.lang.String, java.lang.String, java.lang.String) (tried Java_com_example_nimashahbazi_mooshak_EncryptingActivity_encrypt and Java_com_example_nimashahbazi_mooshak_EncryptingActivity_encrypt__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2)
  at com.example.nimashahbazi.mooshak.EncryptingActivity.encrypt(Native Method)
  at com.example.nimashahbazi.mooshak.EncryptingActivity.onCreate(EncryptingActivity.java:35)
  ...
  </code></pre>
  
  <p>This is my EncryprtingActivity.java:</p>
  
  <pre><code>package com.example.nimashahbazi.mooshak;
  import android.content.Intent;
  import android.os.Environment;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  
  public class EncryptingActivity extends AppCompatActivity {
  
  static {
  
      try
      {
          System.loadLibrary("native-lib");
          System.loadLibrary("aes256");
  
  
      }
      catch (UnsatisfiedLinkError use)
      {
          Log.e("JNI", "WARNING: Could not load native library");
      }
  
  }
  public native int encrypt(String encryptionKey, String inputFile, String outputFile);
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_encrypting);
  
      String input= Environment.getExternalStoragePublicDirectory("Android/data/"+ getApplicationContext().getPackageName()+"/Files/Download").toString()+"DSC_0001.jpg";
      String output= Environment.getExternalStoragePublicDirectory("Android/data/"+ getApplicationContext().getPackageName()+"/Files/Download").toString()+"DSC_0001.jpg.encr";
  
      encrypt("12345678",input,output);
  }
  
  public void onBackPressed() {
      Intent mainIntent = new Intent(EncryptingActivity.this, HomeActivity.class);
      EncryptingActivity.this.startActivity(mainIntent);
      EncryptingActivity.this.finish();
  }
  }
  </code></pre>
  
  <p>and this is my native-lib.cpp:</p>
  
  <pre><code>#include &lt;jni.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  #include &lt;string&gt;
  #include "aes256.cpp"
  
  using namespace std;
  
  #define BUFFER_SIZE 1024*1024
  
  JNIEXPORT jint  JNICALL
  Java_com_example_nimashahbazi_mooshak_EncryptingActivity_encrypt(JNIEnv *env, jobject obj,
                                                                   jstring encryptionKey,
                                                                   jstring inputFile,
                                                                   jstring outputFile);
  
  JNIEXPORT jint  JNICALL
  Java_com_example_nimashahbazi_mooshak_DecryptingActivity_decrypt(JNIEnv *env, jobject obj,
                                                                   jstring encryptionKey,
                                                                   jstring inputFile,
                                                                   jstring outputFile);
  
  JNIEXPORT jint  JNICALL
  Java_com_example_nimashahbazi_mooshak_EncryptingActivity_encrypt(JNIEnv *env, jobject obj,
                                                                   jstring encryptionKey,
                                                                   jstring inputFile,
                                                                   jstring outputFile) {
  
      const char *_encryptionKey = env-&gt;GetStringUTFChars(encryptionKey, NULL);
      const char *_inputFile = env-&gt;GetStringUTFChars(inputFile, NULL);
      const char *_outputFile = env-&gt;GetStringUTFChars(outputFile, NULL);
  
      ByteArray key, enc;
      size_t file_len;
  
      FILE *input, *output;
  
      srand(time(0));
  
      size_t key_len = 0;
      while (_encryptionKey[key_len] != 0)
          key.push_back(_encryptionKey[key_len++]);
  
      input = fopen(_inputFile, "rb");
      if (input == 0) {
          fprintf(stderr, "Cannot read file '%s'\n", _inputFile);
          return 1;
      }
  
      output = fopen(_outputFile, "wb");
      if (output == 0) {
          fprintf(stderr, "Cannot write file '%s'\n", _outputFile);
          return 1;
      }
  
      Aes256 aes(key);
  
      fseek(input, 0, SEEK_END);
      file_len = ftell(input);
      fseek(input, 0, SEEK_SET);
      printf("File is %zd bytes\n", file_len);
  
      enc.clear();
      aes.encrypt_start(file_len, enc);
      fwrite(enc.data(), enc.size(), 1, output);
  
      while (!feof(input)) {
          unsigned char buffer[BUFFER_SIZE];
          size_t buffer_len;
  
          buffer_len = fread(buffer, 1, BUFFER_SIZE, input);
          printf("Read %zd bytes\n", buffer_len);
          if (buffer_len &gt; 0) {
              enc.clear();
              aes.encrypt_continue(buffer, buffer_len, enc);
              fwrite(enc.data(), enc.size(), 1, output);
          }
      }
  
      enc.clear();
      aes.encrypt_end(enc);
      fwrite(enc.data(), enc.size(), 1, output);
  
      fclose(input);
      fclose(output);
  
      return 0;
  }
  
  JNIEXPORT jint  JNICALL
  Java_com_example_nimashahbazi_mooshak_DecryptingActivity_decrypt(JNIEnv *env, jobject obj,
                                                                   jstring encryptionKey,
                                                                   jstring inputFile,
                                                                   jstring outputFile) {
  
      const char *_encryptionKey = env-&gt;GetStringUTFChars(encryptionKey, NULL);
      const char *_inputFile = env-&gt;GetStringUTFChars(inputFile, NULL);
      const char *_outputFile = env-&gt;GetStringUTFChars(outputFile, NULL);
  
      ByteArray key, dec;
      size_t file_len;
  
      FILE *input, *output;
  
      srand(time(0));
  
      size_t key_len = 0;
      while (_encryptionKey[key_len] != 0)
          key.push_back(_encryptionKey[key_len++]);
  
      input = fopen(_inputFile, "rb");
      if (input == 0) {
          fprintf(stderr, "Cannot read file '%s'\n", inputFile);
          return 1;
      }
  
      output = fopen(_outputFile, "wb");
      if (output == 0) {
          fprintf(stderr, "Cannot write file '%s'\n", outputFile);
          return 1;
      }
  
      Aes256 aes(key);
  
      fseek(input, 0, SEEK_END);
      file_len = ftell(input);
      fseek(input, 0, SEEK_SET);
      printf("File is %zd bytes\n", file_len);
  
      aes.decrypt_start(file_len);
  
      while (!feof(input)) {
          unsigned char buffer[BUFFER_SIZE];
          size_t buffer_len;
  
          buffer_len = fread(buffer, 1, BUFFER_SIZE, input);
          printf("Read %zd bytes\n", buffer_len);
          if (buffer_len &gt; 0) {
              dec.clear();
              aes.decrypt_continue(buffer, buffer_len, dec);
              fwrite(dec.data(), dec.size(), 1, output);
          }
      }
  
      dec.clear();
      aes.decrypt_end(dec);
      fwrite(dec.data(), dec.size(), 1, output);
  
      fclose(input);
      fclose(output);
  
      return 0;
  }
  </code></pre>
  
  <p>and this is my android.mk:</p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  
  include $(CLEAR_VARS)
  
  LOCAL_MODULE    := native-lib
  LOCAL_SRC_FILES := native-lib.cpp\
                     aes256.cpp
  
  LOCAL_C_INCLUDES := aes256.hpp
  
  include $(BUILD_SHARED_LIBRARY)
  </code></pre>
  
  <p>This is my CMakeLists.txt</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.4.1)
  
  add_library(native-lib SHARED src/main/cpp/native-lib.cpp)
  add_library(aes256 SHARED src/main/cpp/aes256.cpp)
  
  find_library(log-libd log )
  
  target_link_libraries(native-lib ${log-lib})
  
  target_link_libraries(aes256 ${log-lib})
  </code></pre>
  
  <p>And this is my build.gradle</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 25
      buildToolsVersion '25.0.2'
      defaultConfig {
          applicationId "com.example.nimashahbazi.mooshak"
          minSdkVersion 16
          targetSdkVersion 20
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
          externalNativeBuild {
              cmake {
                  cppFlags "-frtti -fexceptions"
              }
          }
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  
      externalNativeBuild {
          cmake {
              path 'CMakeLists.txt'
          }
      }
  }
  
  dependencies {
      compile fileTree(include: ['*.jar'], dir: 'libs')
      androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
          exclude group: 'com.android.support', module: 'support-annotations'
      })
  
      compile 'com.android.support:appcompat-v7:25.3.1'
      compile 'com.github.angads25:filepicker:1.1.1'
      compile 'com.android.support.constraint:constraint-layout:1.0.2'
      compile 'de.hdodenhof:circleimageview:2.1.0'
      compile 'com.daimajia.numberprogressbar:library:1.4@aar'
      compile 'com.theartofdev.edmodo:android-image-cropper:2.4.+'
      compile 'com.github.johnkil.android-appmsg:appmsg:1.2.0'
      compile 'com.android.support:recyclerview-v7:25.3.1'
      compile 'com.google.code.gson:gson:2.7'
      compile group: 'net.lingala.zip4j', name: 'zip4j', version: '1.2.4'
      testCompile 'junit:junit:4.12'
  }
  </code></pre>
  
  <p>There are also a couple of more files called aes256.cpp and aes256.hpp that are used from <a href="https://github.com/Urban82/Aes256" rel="nofollow noreferrer">here</a>.</p>
  
  <p>I have checked every proposed solution on the topic and they are mostly on the name and format of C++ function but I can't find the problem here. Can anybody please help me here? Thanks in advance.</p>