Search code examples
androidandroid-studioandroid-ndkopus

Android Studio ndk-build can't find files


I 'm trying to compile OPUS in Android Studio. When I call ndk-build from command line, everything works fine. When I build it from Android Studio, it fails.

My app.gradle:

externalNativeBuild {
    ndkBuild {
        path 'src/main/jni/Android.mk'
    }
}

Android.mk has some includes:

include celt_sources.mk

The error:

Error while executing process G:\ASDK\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=F:\TP2\ram\android\app\src\main\jni\Android.mk NDK_APPLICATION_MK=F:\TP2\ram\android\app\src\main\jni\Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=0 APP_PLATFORM=android-19 NDK_OUT=F:/TP2/ram/android/app/build/intermediates/ndkBuild/release/obj NDK_LIBS_OUT=F:\TP2\ram\android\app\build\intermediates\ndkBuild\release\lib APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}

Why NDK_PROJECT_PATH null? How do I tell Android Studio to set the current directory before calling ndk-build?

Best,


Solution

  • You probably followed this or similar solution to prepare opus for Android build. The statements like

    include celt_sources.mk
    

    are not a good practice, because they force you to run ndk-build in the same directory as the Android.mk file. It's not too hard to force Android Studio work this way, add the following block to your build.gradle:

    android {
        defaultConfig {
            externalNativeBuild {
                ndkBuild {
                    arguments '-C src/main/jni'
                }
            }
        }
    }
    

    But it is much cleaner to follow one of the many other versions of Android.mk for opus that can be found on the WWW, e.g. this one which uses

    include $(LOCAL_PATH)/celt_sources.mk
    

    This way, the build doesn't depend on working directory for ndk-build command.