gradle dsl ndkBuild() not found - android

Error:(8, 0) Gradle DSL method not found: 'ndkBuild()'
Possible causes:<ul><li>The project 'OCR4' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>
I have the above error in my code although I have included all the dependencies. The path to ndk-build is also specified
task ndkBuild(type: Exec) {
workingDir = file("${android.sdkDirectory}/ndk-bundle")
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'C:\\Users\\yogita\\Download\\android-ndk-r10e\\ndk-build.cmd', '-C', file('.').absolutePath,
'-j', Runtime.runtime.availableProcessors()
} else {
commandLine './ndk-build', '-C', file('.').absolutePath,
'-j', Runtime.runtime.availableProcessors()
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
// cleanup task
task ndkClean(type: Exec) {
workingDir = file("${android.sdkDirectory}/ndk-bundle")
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'C:\\Users\\yogita\\Download\\android-ndk-r10e\\ndk-build.cmd', '-C', file('.').absolutePath, 'clean'
} else {
commandLine './ndk-build', '-C', file('.').absolutePath, 'clean'
}
}
tasks.withType(Delete) {
cleanTask -> cleanTask.dependsOn ndkClean
}

Related

Execution failed for task ':app:swigPs'. > Process 'command 'swig'' finished with non-zero exit value 1

I want to run my project to test the program that has been created, while sync Gradle not an error, but when there is a project build error:
Error:Execution failed for task ':app:swigPs'. > Process 'command 'swig'' finished with non-zero exit value 1
This my Gradle in app:
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}*/
task ndkBuild(type: Exec) {
commandLine "${ndkDir}/ndk-build${ndkExt}"
}
ndkBuild.outputs.dir "libs"
ndkBuild.outputs.dir "obj"
task mkdir < {
new File('build/generated-src/java').mkdirs()
}
task swigSb(type: Exec) {
commandLine 'swig',
"-I../sphinxbase/include", "-I../sphinxbase/swig",
"-java", "-package", "edu.cmu.pocketsphinx",
"-outdir", "build/generated-src/java", "-o", "jni/sphinxbase_wrap.c",
"../sphinxbase/swig/sphinxbase.i"
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn swigSb
}
task swigPs(type: Exec) {
commandLine 'swig',
"-I../sphinxbase/swig",
"-I../pocketsphinx/include",
"-I../pocketsphinx/swig",
"-java", "-package", "edu.cmu.pocketsphinx",
"-outdir", "build/generated-src/java",
"-o", "jni/pocketsphinx_wrap.c",
"../pocketsphinx/swig/pocketsphinx.i"
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn swigPs
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn mkdir
}
gradle.projectsEvaluated {
preBuild.dependsOn mkdir
preBuild.dependsOn swigSb
preBuild.dependsOn swigPs
preBuild.dependsOn ndkBuild
}
/*compileJava.dependsOn mkdir
compileJava.dependsOn swigSb
compileJava.dependsOn swigPs
compileJava.dependsOn ndkBuild*/
ndkBuild.dependsOn swigSb
ndkBuild.dependsOn swigPs
Full Gradle file Because my code too much
Gradle Console for error
Gradle Console
Help me please. Thanks

Why doesn't gradle tasks show group or description when using exec?

My Gradle task stopped showing the group and description in ./gradlew tasks, since I've added an exec {} in the root build.gradle.
What's going on, and how do I get it back?
task doSomething << {
group 'yourGroupName'
description 'Runs your bash script'
exec {
workingDir "$projectDir/../pathto/"
commandLine 'bash', '-c', './bashscript.sh'
}
}
Everything else works.
You cannot configure group and description in a doLast() closure
this code
task doSomething << {
exec {
workingDir "$projectDir/../pathto/"
commandLine 'bash', '-c', './bashscript.sh'
}
}
is the same than
task doSomething {
doLast {
exec {
workingDir "$projectDir/../pathto/"
commandLine 'bash', '-c', './bashscript.sh'
}
}
}
In the following group and description are not taking into account
task doSomething {
doLast {
group 'yourGroupName'
description 'Runs your bash script'
exec {
workingDir "$projectDir/../pathto/"
commandLine 'bash', '-c', './bashscript.sh'
}
}
}
But here it does :
task doSomething {
group 'yourGroupName'
description 'Runs your bash script'
doLast {
exec {
workingDir "$projectDir/../pathto/"
commandLine 'bash', '-c', './bashscript.sh'
}
}
}

Execution failed for task ':app:buildNative'

The same error question has been asked on SO, but their solutions didn't work for me. I couldn't figure it out myself, therefore I need help. Here's my build.gradle:
apply plugin: 'com.android.application'
def VUFORIA_SDK_DIR = '../../..'
def JAR_DIR = 'build/java/vuforia'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir "src/main/libs"
}
defaultConfig {
applicationId "com.qualcomm.QCARSamples.ImageTargets"
minSdkVersion 8
targetSdkVersion 22
versionCode 200
versionName "5.0"
}
archivesBaseName = rootProject.projectDir.getName()
buildTypes {
release {
minifyEnabled false
ndk {
abiFilters "armeabi-v7a"
}
}
debug {
minifyEnabled false
debuggable true
ndk {
abiFilters "armeabi-v7a"
}
}
}
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
println('compiling jni code with ndk-build...')
def ndkDir = android.ndkDirectory
if (System.properties['os.name'].toLowerCase().contains('windows')) {
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni').absolutePath
// Additional ndk-build arguments, such as NDK_DEBUG, can be provided here
} else {
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath
// Additional ndk-build arguments, such as NDK_DEBUG, can be provided here
}
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
if (System.properties['os.name'].toLowerCase().contains('windows')) {
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni').absolutePath,
'clean'
} else {
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath,
'clean'
}
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
}
dependencies {
compile files("$VUFORIA_SDK_DIR/$JAR_DIR/Vuforia.jar")
}
Gradle build always fails with this error:
Error:Execution failed for task ':app:buildNative'.
A problem occurred starting process 'command 'null/ndk-build''
What could be the reason?
My reading of what you have here is as follows:
def ndkDir = android.ndkDirectory
May be returning a null value. The other option i see is that
commandLine "$ndkDir/ndk-build",
Doesn't properly reference your ndkDir variable, and your commandLine execution fails on that.
Error:Execution failed for task ':app:buildNative'. A problem occurred starting process 'command 'null/ndk-build''
aligns well with those two theories.
Try ensuring you don't get a null back when trying to asign to ndkDir, and/or converting the variable to a string prior to the commandLine command.

Android NDK- Error:Execution failed for task ':app:buildNative'

I am developing an Video Compression app so i am using NDK and getting error when run the app.
I seen the many stackOverflow Questions (Execution error in app:buildNative) but the stackOverflow solutions are not works for this error.
Gradle Build Message:
Gradle tasks [:app:assembleDebug]
:app:buildNative FAILED
Error:Execution failed for task ':app:buildNative'.
> A problem occurred starting process 'command 'null/ndk-build.cmd''
Is anyone help for my questions?
build.gradle(Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.xxxx.videocompressor"
minSdkVersion 16
targetSdkVersion 22
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main {
jni.srcDirs = [] // This prevents the auto generation of Android.mk
jniLibs.srcDir 'src/main/libs'
// This is not necessary unless you have precompiled libraries in your project.
}
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni/').absolutePath, // Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=1'
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni/').absolutePath, // Change src/main/jni the relative path to your jni source
'clean'
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.+'
compile 'com.android.support:support-v4:22.2.+'
compile 'com.android.support:appcompat-v7:22.2.+'
compile 'com.android.support:recyclerview-v7:22.2.+'
compile 'com.android.support:design:22.2.+'
compile 'com.google.android.gms:play-services-ads:7.8.0'
}
Instead of using only this
// 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
}
}
Use this
// 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
}

How do I use this Gradle Script in Android Studio?

I found this gradle script built for android studio to allow the use of the NDK until the team can create an official (and more understandable) way of accomplishing this. I don't really understand how it works or how it ties in to a normal gradle script as I am still new to this IDE. Can anybody explain it to me?
The script is:
//////////////
// NDK Support
//////////////
// If using this, Android studio will fail run the following to set the environment
// variable for android studio:
// launchctl setenv ANDROID_NDK_HOME
// /Users/boos_patrick/Development/Android/android-ndk-r8e
// otherwise remove the dependsOn part and run ./gradlew buildNative from the
// command line
task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {
dependsOn 'buildNative'
from(new File('libs')) { include '**/*.so' }
into new File(buildDir, 'native-libs')
}
tasks.withType(Compile) { compileTask -> compileTask.dependsOn copyNativeLibs }
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniDir new File(buildDir, 'native-libs')
}
task buildNative(type: Exec) {
if (System.env.ANDROID_NDK_HOME != null) {
def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
commandLine ndkBuild
} else {
doLast {
println '##################'
println 'Skipping NDK build'
println 'Reason: ANDROID_NDK_HOME not set.'
println '##################'
}
}
}

Categories

Resources