3

I have an android project with FFmpeg and other external libraries. I downloaded the latest version of the ndk (ndk-r10) and am running Android Studio 0.8.0. I am also running Windows 8 64bit with the latest version of cygwin.

My project builds without issue and I added the ndk.dir to local.properties. When I try to run I get this error message:

The System cannot find the path specified

Error:Execution failed for task ':app:compileDebugNdk'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\John1\AppData\Local\Android\android-ndk-r10\ndk-build.cmd

NDK_PROJECT_PATH=null      
APP_BUILD_SCRIPT=C:\Users\John1\AndroidstudioProjects\android-project\app\build\intermediates\ndk\debug\Android.mk 
APP_PLATFORM=android-18 
NDK_OUT=C:\Users\John1\AndroidstudioProjects\android-project\app\build\intermediates\ndk\debug\obj 
NDK_LIBS_OUT=C:\Users\John1\AndroidstudioProjects\android-project\app\build\intermediates\ndk\debug\lib 
APP_ABI=all

Error Code:
    1
Output:
    The system cannot find the path specified.

Looking for advice. Thank you.

a2800276
  • 3,272
  • 22
  • 33
nyc0202034
  • 113
  • 1
  • 3
  • 14
  • are these paths correct: `C:\Users\John1\AppData\Local\Android\android-ndk-r10\ndk-build.cmd`, `C:\Users\John1\AndroidstudioProjects\android-project\app\build\`? – Alex Cohn Jul 31 '14 at 10:30
  • Yes, the ndk-build.cmd is definitely correct and C:\Users\John1\AndroidstudioProjects\android-project\app\build does exist (inside are two sub-folders, generated and intermediates) – nyc0202034 Jul 31 '14 at 13:00
  • @nyc0202034 are you building using gradle? – sujithvm Jul 31 '14 at 16:38
  • @sujithvm yes I am using gradle in Android studio – nyc0202034 Aug 01 '14 at 00:34
  • ndk-r10 supports 64 bit. If you would like to compile to for 32 bit targets you need to specify APP_ABI:=all32. Also use the default toolchain that is available. Check your application.mk to make sure it is set to default – G3M Aug 01 '14 at 05:55
  • @g3m I don't have an application.mk only an android.mk file. Please advise. – nyc0202034 Aug 02 '14 at 15:55
  • I also noticed that the intermediates folder exists but is not part of the project. Will that effect anything? – nyc0202034 Aug 02 '14 at 16:10

1 Answers1

16

with Android Studio, NDK support is preliminary and your *.mk files are ignored. You can make Android Studio/gradle reuse them by deactivating the default NDK integration, make it call ndk-build(.cmd) by itself, and use standard libs/ location for integrating .so files:

import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig{
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 101
        versionName "1.0.1"
    }

    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
        jni.srcDirs = [] //disable automatic ndk-build call
    }

    // call regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
        } else {
            commandLine 'ndk-build', '-C', file('src/main').absolutePath
        }
    }

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }
}

If you need more information, here is my blog post on this topic: http://ph0b.com/android-studio-gradle-and-ndk-integration/

ph0b
  • 14,353
  • 4
  • 43
  • 41
  • Doing this hides "c" folder from project, so I can't open c files from Android Studio. Is there any workaround? – Parmaia May 22 '15 at 09:41
  • after doing this getting this error "A problem occurred starting process 'command 'ndk-build.cmd'' " – Adi Oct 16 '15 at 11:31
  • read the logs to see the error. Maybe the ndk directory hasn't been added to your environment path? – ph0b Oct 16 '15 at 16:21
  • NB : These edits should be made to `build.gradle` file, when using react-native this is not straightforward as everything is abstracted, hope it helps. – Marc_Alx Dec 01 '17 at 09:38
  • @ph0b I am using android-studio3.5 and ndk21r. why ndk-build is not running in latest version of ndk. is there any issue with latest build. – Peter Mar 03 '20 at 04:59