0

I followed this tutorial https://www.youtube.com/watch?v=JIHfqzTdOcQ and in the final stage i can't compile the project. There is something wrong with my ndk, but i have no idea what to do. I tried everything, for example:

NDKBuild Failure

After many changes, I'm a little confused right now.

Here is the code of my build.gradle

import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
defaultConfig {
    applicationId "com.example.aidan.opencvdemo"
    minSdkVersion 14
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}

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
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile project(':openCVLibrary310')
}

Here is messages gradle build

Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:openCVLibrary310:compileLint
:openCVLibrary310:copyReleaseLint UP-TO-DATE
:openCVLibrary310:mergeReleaseProguardFiles UP-TO-DATE
:openCVLibrary310:preBuild UP-TO-DATE
:openCVLibrary310:preReleaseBuild UP-TO-DATE
:openCVLibrary310:checkReleaseManifest
:openCVLibrary310:prepareReleaseDependencies
:openCVLibrary310:compileReleaseAidl UP-TO-DATE
:openCVLibrary310:compileReleaseRenderscript UP-TO-DATE
:openCVLibrary310:generateReleaseBuildConfig UP-TO-DATE
:openCVLibrary310:generateReleaseAssets UP-TO-DATE
:openCVLibrary310:mergeReleaseAssets UP-TO-DATE
:openCVLibrary310:generateReleaseResValues UP-TO-DATE
:openCVLibrary310:generateReleaseResources UP-TO-DATE
:openCVLibrary310:packageReleaseResources UP-TO-DATE
:openCVLibrary310:processReleaseManifest UP-TO-DATE
:openCVLibrary310:processReleaseResources UP-TO-DATE
:openCVLibrary310:generateReleaseSources UP-TO-DATE
:openCVLibrary310:compileReleaseJava UP-TO-DATE
:openCVLibrary310:processReleaseJavaRes UP-TO-DATE
:openCVLibrary310:packageReleaseJar UP-TO-DATE
:openCVLibrary310:compileReleaseNdk UP-TO-DATE
:openCVLibrary310:packageReleaseJniLibs UP-TO-DATE
:openCVLibrary310:packageReleaseLocalJar UP-TO-DATE
:openCVLibrary310:packageReleaseRenderscript UP-TO-DATE
:openCVLibrary310:bundleRelease UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72221Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42221Library UP-TO-DATE
:app:prepareOpenCVdemoOpenCVLibrary310UnspecifiedLibrary UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:ndkBuild FAILED
Error:Execution failed for task ':app:ndkBuild'.
> A problem occurred starting process 'command 'ndk-build.cmd''
Information:BUILD FAILED
Information:Total time: 1.673 secs
Information:1 error
Information:0 warnings
Information:See complete output in console

Here is my project structure

http://oi68.tinypic.com/152eu86.jpg

Community
  • 1
  • 1
  • Have you considered using the experimental gradle plugin for Android Studio 1.x? It replaces ndk-build, and has the extra benefit of enabling (imperfect but better than nothing) debugger support in the IDE. Details here: http://tools.android.com/tech-docs/new-build-system/gradle-experimental – Ian Ni-Lewis Apr 11 '16 at 14:01

1 Answers1

0

Based on the Gradle docs for Exec tasks, I'd guess that there are two problems with your build script on Windows:

  1. Unlike Linux, Windows doesn't consider shell scripts to be executables. There's no #! on Windows. You need to specify cmd.exe as the executable, and ndk-build.cmd as the first argument.
  2. Windows likes to see a / before options, rather than the - that Linux uses. So /c instead of -c.

You might also want to explicitly set workingDir. It defaults to the project root, which may or may not be what you want.

Ian Ni-Lewis
  • 2,377
  • 20
  • 20