0

I need to develop an audio app in NDK using Android Studio. I have added

the ndk path to local.properties -

    ndk.dir=/opt/android-ndk-r10
    sdk.dir=/opt/adt-bundle-linux-x86_64-20140702/sdk

In build.gradle I added an entry for OpenSLES -
apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.hellojni"
        minSdkVersion 8
        targetSdkVersion 21

        ndk {
            moduleName "HelloJNI"
            ldLibs "OpenSLES"       // Link with these libraries!
            stl "stlport_shared"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:20.0.0'
    compile 'com.android.support:appcompat-v7:20.0.0'
}

Next I tried to add #includes for opensl -

#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>

but the IDE is not recognising the headers saying it cannot find the include files. I also tried importing the native-audio project into android studio but that too did not compile or run. I am aware that the official support is still not there for using NDK with Android Studio. But I have seen some videos that show how to integrate ndk with android studio. Is there a way to do it. Thanks in advance

Pankaj
  • 327
  • 3
  • 14

1 Answers1

0

OpenSL library is available for android platforms with API 9+, so you may want to change the mininimum required sdk.

Not sure how NDK chooses for which platform to compile, but you may need to compile yourself also using a custom Application.mk file like this:

APP_ABI := armeabi
APP_PLATFORM := android-9
TARGET_PLATFORM := android-9

Also, you should always target and compile with the highest available sdk.

Here's an example of what your build file should look like:

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.hellojni"
        minSdkVersion 9
        targetSdkVersion 22

        ndk {
            moduleName "HelloJNI"
            ldLibs "OpenSLES"       // Link with these libraries!
            stl "stlport_shared"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
}

Note: With the above configuration, the libraries are found for me (with the built-in ndk configurations).

Simas
  • 43,548
  • 10
  • 88
  • 116