title: Shared library bundled in the apk is not found at runtime
body: <p>I do some native Android development which involves OpenSSL.</p>
  
  <p>I cross compile it for <code>armeabi</code> (32b) using the Android NDK stand-alone toolchains. I cross-compile the native C libraries, copy the OpenSSL/native library <code>.so</code> files inside of my <code>libs/</code> folder, which is referenced by my gradle this way:</p>
  
  <pre><code>sourceSets {
      main {
          jniLibs.srcDir(file("libs/"))
      }
  }
  </code></pre>
  
  <p>Anyway, the end result is that my <code>.apk</code> looks like this:</p>
  
  <pre><code> - &gt; classes.dex
   - &gt; lib/
       -&gt; armeabi/
          -&gt; libcrypto.so
          -&gt; libssl.so
          -&gt; libmynativelibrary.so
   - &gt; res/ (...)
   - &gt; resources.arsc
   - &gt; META-INF/ (...)
   - &gt; kotlin/ (...)
   - &gt; AndroidManifest.xml
  </code></pre>
  
  <p>The shared libraries are correct 32-bit ARM ELF files. I've been using this exact APK on an API level 24 device with great success (Android 7.0+).</p>
  
  <p><strong>The issue:</strong> When I switch to an API level 21 device (Android 5.1-, I suspect that I would have the same issue with Android 6.0), the program instantly crashes when loading <code>libmynativelibrary.so</code>.</p>
  
  <p>Since <code>libcrypto.so</code> is a dependency of <code>libmynativelibrary.so</code>, the program attempts to load it. It actually works fine on API level 24+, but crashes on API level 23-. It's because the loaded library is <strong>not</strong> the one in my <code>.apk</code>, but the one in the system. <a href="https://developer.android.com/about/versions/nougat/android-7.0-changes" rel="nofollow noreferrer">And such libraries seem to not be available below API level 24.</a></p>
  
  <p><strong>My question:</strong> How do I explicitly tell Android to look for the library in the <code>.apk</code> file first instead of the regular system libraries directories?</p>
  
  <p>Thanks in advance.</p>