Home » Android » Application.mk is ignored by Android Studio

Application.mk is ignored by Android Studio

Posted by: admin June 15, 2020 Leave a comment

Questions:

I would like to include c++ header iostream into my NDK code. In order to do that, I have to include APP_STL := stlport_static (or similar) into Application.mk file as mentioned in Android ndk-build iostream: No such file or directory.

It all works well if I compile using command line ndk-build, however while compiling using Android Studio, I still get the same error as iostream not found. It looks like application.mk is ignored by Android Studio and I am not sure how to configure it in build.gradle.
Can anyone help me including APP_STL := stlport_static using android studio?

Thanks

How to&Answers:

It looks like at the moment there is no support for including Application.mk file in build.gradle, however adding stl “stlport_static” under ndk section of build.gradle works well (thanks Michael for quick reply).

Under defaultConfig section, add:

    ndk {
        moduleName "app"
        stl "stlport_static"
    }

Details can be found at: https://groups.google.com/forum/#!topic/adt-dev/pHnST37HrlM

Answer:

For Gradle 2.5, it should look like this:

    android.ndk {
        moduleName = "app"
        stl = "stlport_static"
    }

Answer:

For Gradle 4.4 :
Adding

path 'jni/Application.mk'

to the app level build.gradle solved my problem. It should be like this

externalNativeBuild {
    ndkBuild {
        path 'jni/Android.mk'
        path 'jni/Application.mk'
    }
}

Then Android Studio checks for your Application.mk file.

My folder structure is like this