title: Android NDK Linker wrong path
body: <p>I'm currently working with a NDK Project that uses shared libraries. And I have two shared libraries to integrate: libsatprotocol.so and libsat-tanca.so.</p>
  
  <p>So I added to my Android.mk these libraries so I could make a wrapper. For libsatprotocol everything is working fine. But for libsat-tanca, I get a crash on android:</p>
  
  <pre><code> java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "/home/lucas/Rockspoon/satlib/Android/app/src/main/obj/local/armeabi/libsat-tanca.so" needed by "libsat-jni.so"; caused by library "/home/lucas/Rockspoon/satlib/Android/app/src/main/obj/local/armeabi/libsat-tanca.so" not found
                                                                                at java.lang.Runtime.loadLibrary(Runtime.java:371)
                                                                                at java.lang.System.loadLibrary(System.java:989)
  </code></pre>
  
  <p>So the weird thing is that this path in my computer path for the library, and I have no clue from where it is getting it. If I remove the libsat-tanca of the dependencies, it works fine (in libsatprotocol).</p>
  
  <p>Here are my Android.mk:</p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  #LOCAL_ALLOW_UNDEFINED_SYMBOLS=true
  
  include $(CLEAR_VARS)
  
  LOCAL_MODULE    := sat-tanca
  LOCAL_SRC_FILES := tanca/$(TARGET_ARCH_ABI)/libsat-tanca.so
  
  include $(PREBUILT_SHARED_LIBRARY)
  
  include $(CLEAR_VARS)
  
  LOCAL_MODULE    := sat-dimep
  LOCAL_SRC_FILES := dimep/$(TARGET_ARCH_ABI)/libsatprotocol.so
  
  include $(PREBUILT_SHARED_LIBRARY)
  
  include $(CLEAR_VARS)
  
  LOCAL_MODULE    := sat-jni
  LOCAL_SRC_FILES := satlib.c
  LOCAL_LDLIBS    += -L$(SYSROOT)/usr/lib -lz -llog
  LOCAL_SHARED_LIBRARIES := sat-tanca sat-dimep
  
  include $(BUILD_SHARED_LIBRARY)
  </code></pre>
  
  <p>Application.mk</p>
  
  <pre><code>APP_ABI := armeabi #armeabi-v7a mips x86 x86_64
  LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libsatprotocol.so $(TARGET_ARCH_ABI)/libsat-tanca.so
  </code></pre>
  
  <p>SATControl.java</p>
  
  <pre><code>static {
    System.loadLibrary("sat-jni");
  }
  </code></pre>
  
  <p>build.gradle (app)</p>
  
  <p>apply plugin: 'com.android.application'</p>
  
  <pre><code>android {
      compileSdkVersion 23
      buildToolsVersion "23.0.3"
  
      defaultConfig {
          applicationId "com.rockspoon.libraries.satlib"
          minSdkVersion 19
          targetSdkVersion 23
          versionCode 1
          versionName "1.0"
          ndk {
              moduleName "sat-jni"
          }
      }
  
      sourceSets.main {
          jni.srcDirs = [] // This prevents the auto generation of Android.mk
          jniLibs.srcDir 'src/main/libs' // This is not necessary unless you have precompiled libraries in your project.
      }
  
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  
      task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
          def ndkDir = android.ndkDirectory
          commandLine "$ndkDir/ndk-build",
                  '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
                  '-j', Runtime.runtime.availableProcessors(),
                  'all',
                  'NDK_DEBUG=1'
      }
  
      task cleanNative(type: Exec, description: 'Clean JNI object files') {
          def ndkDir = android.ndkDirectory
          commandLine "$ndkDir/ndk-build",
                  '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
                  'clean'
      }
  
      clean.dependsOn 'cleanNative'
  
      tasks.withType(JavaCompile) {
          compileTask -&gt; compileTask.dependsOn buildNative
      }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      testCompile 'junit:junit:4.12'
      compile 'com.android.support:appcompat-v7:23.4.0'
  }
  </code></pre>
  
  <p>Any idea why it is linking just the libsat-tanca.so with my PC path?</p>