Android NDK dlopen failed: cannot locate symbol "ASensor_getReportingMode" referenced by "lib*.so"
<p>I have a project that uses Android NDK to access the accelerometer sensor of my device. The application works, except if I try to use the <code>ASensor_getReportingMode()</code> or <code>ASensor_isWakeUpSensor()</code> since it doesn't find the symbols. It probably happens with other functions as well. Strangely there are functions of the same header file such as <code>ASensor_getName()</code> or <code>ASensor_getVendor()</code> that work without problem. Does anyone know what could be missing here?</p>

<p>build.gradle (Module)</p>

<pre class="lang-js prettyprint-override"><code>apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.0"

        defaultConfig {
            applicationId "com.apidae.sensorndk"
            minSdkVersion.apiLevel 19
            targetSdkVersion.apiLevel 24
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles.add(file('proguard-rules.pro'))
            }
        }
        ndk {
            moduleName "ndkfeatures"
            ldLibs.addAll([ 'android', 'log'])
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0'
}
</code></pre>

<p>Java Class</p>

<pre class="lang-java prettyprint-override"><code>package com.apidae.sensorndk;

public class NdkFeatures {
    static {
        System.loadLibrary("ndkfeatures");
    }
    public native boolean init();
} 
</code></pre>

<p>C++ Source segment</p>

<pre class="lang-cpp prettyprint-override"><code>#include &lt;android/sensor.h&gt;
...
    Log::info("Sensor Info:\n  Name:\t%s\n  Vendor:\t%s\n  Mode:\t%d",
        ASensor_getName(mAccelerometer),
        ASensor_getVendor(mAccelerometer),
        ASensor_getReportingMode(mAccelerometer)); // &lt;- Taking this line out runs
...
</code></pre>

<p>build.gradle (App)</p>

<pre class="lang-js prettyprint-override"><code>buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.7.2'
        classpath 'com.android.tools.build:gradle:2.1.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
</code></pre>

<p>Full Exception:</p>

<pre><code>E/AndroidRuntime: FATAL EXCEPTION: main 
        Process: com.apidae.sensorndk, PID: 6855
        java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "ASensor_getReportingMode" referenced by "libndkfeatures.so"...
            at java.lang.Runtime.loadLibrary(Runtime.java:371)
            at java.lang.System.loadLibrary(System.java:553)
            at com.apidae.sensorndk.NdkFeatures.&lt;clinit&gt;(NdkFeatures.java:6)
            at com.apidae.sensorndk.MainActivity.onCreate(MainActivity.java:13)
            at android.app.Activity.performCreate(Activity.java:5264)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
            at android.os.Handler.dispatchMessage(Handler.java:110)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:5299)
            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:825)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
            at dalvik.system.NativeStart.main(Native Method)
</code></pre>