title: Android native library dependency not found
body: <p>In my Android Studio project I use a third-party library (which I cannot edit) which requires several native libraries. When I access this third-party library in my app, I get the following error:</p>
  
  <pre><code>java.lang.UnsatisfiedLinkError: Couldn't load avutil-52 from 
  loader dalvik.system.PathClassLoader
  [dexPath=/data/app/com.myApp.debug.apk, 
  libraryPath=/data/app-lib/com.myApp.debug]: 
  findLibrary returned null
  </code></pre>
  
  <p>I use Android Studio 1.2.2, so Gradle supports using a jniLibs folder. My Gradle build file specifies the jniLibs folder, for safety:</p>
  
  <pre><code>android {
      sourceSets {
          main {
              java {
                  srcDir 'src/main/src'
              }
              jniLibs {
                  srcDirs 'src/main/jniLibs'
              }
          }
      }
  </code></pre>
  
  <p>}</p>
  
  <p>And here I have my libraries:</p>
  
  <pre><code>src/main/jniLibs/armeabi/*.so
  </code></pre>
  
  <p>The folder includes some other libraries, which are working in the app, so I know the folder is being included. </p>
  
  <p>When I inspect the generated APK, all the *.so files are included in the libs folder. However, when I check the installed app, I only find three of the expected six libraries:</p>
  
  <pre><code>adb shell ls /data/app-lib/com.myApp
  
  first.so
  second.so
  third.so
  </code></pre>
  
  <p>I've also checked the <code>/data/data/com/myApp.debug/app_lib/</code> folder, and none of the other three dependencies are there. </p>
  
  <p>Not being a native Android developer, I find this very puzzling. What could be causing some dependencies to be included, and others to be excluded? Is there a way of forcing Android to recognise the three missing files, and making sure they're installed? Without having to edit the third party library which uses them, of course.</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>Could this code from the third-party library be causing a problem? </p>
  
  <pre><code>public StartFunction() {
      String arch = System.getProperty("os.arch");
      this.ARM = arch.toUpperCase().contains("ARM") || arch.toUpperCase().contains("AARCH64");
      if(this.ARM) {
          this.LoadLibraries();
      }
  }
  
  private void LoadLibraries() {
      System.loadLibrary("first");
      System.loadLibrary("second");
      System.loadLibrary("third");
      System.loadLibrary("fourth");
      System.loadLibrary("fifth");
      System.loadLibrary("sixth");
  }
  </code></pre>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>This is the full exception from logcat. Package names slightly changed to protect the guilty.</p>
  
  <pre><code>  06-30 09:19:08.505  15069-15069/com.myApp.debug E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: com.myApp.debug, PID: 15069
        java.lang.UnsatisfiedLinkError: Couldn't load avutil-52 from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.myApp.debug-1.apk,libraryPath=/data/app-lib/com.myApp.debug-1]: findLibrary returned null
                at java.lang.Runtime.loadLibrary(Runtime.java:358)
                at java.lang.System.loadLibrary(System.java:526)
                at com.thirdPartyApp.embedded.Call.LoadLibraries(Call.java:289)
                at com.thirdPartyApp.embedded.Call.&lt;init&gt;(Call.java:214)
                at com.thirdPartyApp.embedded.thirdPartyCall$29.run(thirdParty.java:963)
                at com.thirdPartyApp.embedded.DownloadFile.onPostExecute(DownloadFile.java:56)
                at com.thirdPartyApp.embedded.DownloadFile.onPostExecute(DownloadFile.java:16)
                at android.os.AsyncTask.finish(AsyncTask.java:632)
                at android.os.AsyncTask.access$600(AsyncTask.java:177)
                at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:146)
                at android.app.ActivityThread.main(ActivityThread.java:5487)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:515)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
                at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p><strong>EDIT 3:</strong></p>
  
  <p>I've managed to get this working, but in a kind of dirty way. I don't know exactly why this happened, but I do know what happened:</p>
  
  <p>I had all six the compiled libraries needed by the third party SDK I'm using placed in <code>src/main/jniLibs/armeabi</code>. Conventional wisdom dictates that this should work for all ARM devices. However, when installing the app on an ARM device only three of the six libraries were installed.</p>
  
  <p>Dirty solution: place all six libraries in the <code>src/main/jniLibs/armeabi-v7a</code> folder as well. This scattershot approach meant that all six libraries are installed, and available.</p>
  
  <p>I'll update this once we figure out why this happened.</p>