title: Link .so library in android studio project
body: <p>As the title suggests I am trying to link a native <code>.so</code> to an android studio project. I have gone through the docs in android developer website and some more articles but unsuccessful in connecting the <code>.so</code> file with the project. </p>
  
  <p>Whenever I try to run the code I get the following error</p>
  
  <blockquote>
    <p>CMake Error: The following variables are used in this project, but
    they are set to NOTFOUND. Please set them or make sure they are set
    and tested correctly in the CMake files: testlib</p>
  </blockquote>
  
  <p>Here is my CMake file </p>
  
  <pre><code>cmake_minimum_required(VERSION 3.4.1)
  
  add_library( # Sets the name of the library.
               native-lib
  
               # Sets the library as a shared library.
               SHARED
  
               # Provides a relative path to your source file(s).
               src/main/cpp/native-lib.cpp )
  
  find_library( # Sets the name of the path variable.
                log-lib
  
                # Specifies the name of the NDK library that
                # you want CMake to locate.
                log )
  
  add_library(testlib SHARED IMPORTED)
  
  set_property(TARGET testlib PROPERTY IMPORTED_LOCATION "E:/project/Remote_Native/remote_attempt_1/app/libs/armeabi-v7a/libremotedesktop_client.so")
  
  #find_path(testlib E:/project/Remote_Native/remote_attempt_1/app/libs/armeabi-v7a/RemoteDesktop.h)
  find_library(testlib E:/project/Remote_Native/remote_attempt_1/app/libs/armeabi-v7a/libremotedesktop_client.so)
  
  #add_library(remote SHARED IMPORTED)
  
  #set_target_properties(remote PROPERTIES IMPORTED_LOCATION libs/${ANDROID_ABI}/libremotedesktop_client.so )
  
  # Specifies libraries CMake should link to your target library. You
  # can link multiple libraries, such as libraries you define in this
  # build script, prebuilt third-party libraries, or system libraries.
  
  target_link_libraries( # Specifies the target library.
                         native-lib
  
                         # Links the target library to the log library
                         # included in the NDK.
                         ${log-lib}
  
                         ${testlib})
  
  target_include_directories()
  </code></pre>
  
  <p>I have four <code>.so</code> files each for arm64, armeabi, armeabi-v7a, x86. I have harcoded the armeabi-v7a lib in the path, android studio is throwing the above mentioned error when I do that. My actual aim is to dynamically load the library based on the chip in the phone. I am pretty sure that my current code is not achieving that.</p>
  
  <p>Here are my queries</p>
  
  <ol>
  <li><p>How to solve the error that I am getting? I have tried giving both relative and absolute path but to no avail I am getting the same error.</p></li>
  <li><p>How do I add a <code>.so</code> and a <code>.h</code> file into a native android studio project? That has variations based on the chip on which the code is running? </p></li>
  <li><p>When I directly add the <code>.h</code> file to the native folder I can reference the classes and functions in that header in my C code but I am unable to run the code. I have a <code>getInstance()</code> method in the <code>.h</code> file. Whenever I call the 
  <code>getInstance()</code> function it says <code>undefined refernce to getInstance()</code>. What I understand from that is the '.h' file is linked correctly but the definition of the function of the <code>.h</code> files which are actually present in the <code>.so</code> files are not linked. I believe this will be solved if question 1 and 2 are answered.</p></li>
  <li><p>Is it necessary for all native android projects to have a .mk file? I didn't add one to my project and think it might be one of the cause for the error that I am getting.</p></li>
  </ol>