Process 'command 'NDK PATH' finished with non-zero exit value 2 - android

I'm trying to add this library to my app, but when I run the app I get this error :
Process 'command 'D:\Sdk\ndk-bundle\ndk-build.cmd'' finished with
non-zero exit value 2
Build.Gradle :
apply plugin: 'com.android.library'
android {
buildToolsVersion "28.0.3"
compileSdkVersion 28
sourceSets {
main {
java.srcDirs 'src'
res {
srcDirs 'res'
}
manifest.srcFile 'AndroidManifest.xml'
jni.srcDirs = []
jniLibs.srcDir 'libs'
}
}
task ndkBuild(type:Exec) {
workingDir file('./')
commandLine getNdkBuildCmd()
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task cleanJni(type:Exec) {
workingDir file('./')
commandLine getNdkBuildCmd(), 'clean'
}
clean.dependsOn cleanJni
}
def getNdkBuildCmd() {
def ndkbuild = "D:\\Sdk\\ndk-bundle\\ndk-build.cmd"
return ndkbuild
}
Path :

Modify this function to give drive name 'D\'
def getNdkBuildCmd() {
def ndkbuild = "D\:\\Sdk\\ndk-bundle\\ndk-build.cmd"
return ndkbuild
}

Related

Not able to add Tesseract OCR module to Android Studio

I followed the step by step guide found here:
https://www.codeproject.com/Articles/840623/Android-Character-Recognition
At step 2 when I added tess-two as module dependency to app and synced gradle, it failed with the following error:
Error:Project :app declares a dependency from configuration 'compile' to configuration 'default' which is not declared in the descriptor for project :libraries:tess-two.
I have tried many combinations of settings.gradle and searched for hours, any help will be much appreciated, thanks!
build.gradle file under tess-two
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
consumerProguardFiles 'proguard-rules.pro'
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
jni.srcDirs = []
jniLibs.srcDirs = ['libs']
}
}
// Call external ndk-build(.cmd) script to build the native code
task ndkBuild(type: Exec) {
def ndkDirProperty = properties.getProperty('ndk.dir')
def ndkDirPrefix = ndkDirProperty != null ? ndkDirProperty + '/' : ''
def ndkBuildExt = Os.isFamily(Os.FAMILY_WINDOWS) ? ".cmd" : ""
commandLine "${ndkDirPrefix}ndk-build${ndkBuildExt}", '-C', file('.').absolutePath,
'-j', Runtime.runtime.availableProcessors()
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
// Cleanup task to remove previously generated binaries
task ndkClean(type: Exec) {
def ndkDirProperty = properties.getProperty('ndk.dir')
def ndkDirPrefix = ndkDirProperty != null ? ndkDirProperty + '/' : ''
def ndkBuildExt = Os.isFamily(Os.FAMILY_WINDOWS) ? ".cmd" : ""
commandLine "${ndkDirPrefix}ndk-build${ndkBuildExt}", '-C', file('.').absolutePath, 'clean'
}
tasks.withType(Delete) {
cleanTask -> cleanTask.dependsOn ndkClean
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':libraries:tess-two')
}
// Settings for uploading module AAR to Bintray for library distribution
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
failOnError = false
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
options {
links "http://docs.oracle.com/javase/7/docs/api/"
linksOffline "http://d.android.com/reference","${android.sdkDirectory}/docs/reference"
}
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
install {
repositories.mavenInstaller {
pom.project {
name = 'tess-two'
packaging = 'aar'
groupId = 'com.rmtheis'
artifactId = 'tess-two'
developers {
developer {
id = 'rmtheis'
name = 'Robert Theis'
email = 'robert.m.theis#gmail.com'
}
}
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}
scm {
url 'https://github.com/rmtheis/tess-two'
}
}
}
}
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = 'maven'
name = 'tess-two'
userOrg = user
publish = true
}
}
settings.gradle
include ':app'
include ':libraries:tess-two'
include 'app:libraries:tess-two'
project(':libraries:tess-two').projectDir = new File('libraries/tess-two')

Android Studio Unable to Find Oculus SDK

I just added a library to my project, Gear VRF, and the build.gradle file for the library is unable to find the Oculus sdk. I am getting the error "not copying Oculus files: OVR_MOBILE_SDK not found, as well as "relying on hard-coded paths and environment variables; OVR_MOBILE_SDK not found. At the bottom of the Gradle log I also get "execution failed for task framework:buildNative. User/../../Android/sdk/ndk-bundle/ndk-build finished with nonzero exit value 2.
Any help on this issue is appreciated, I have put the code for the library's build.gradle below. Thanks.
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion '23.0.3'
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
ndk {
moduleName "gvrf"
}
}
task copyOculusFiles(type: Copy) {
println "copying oculus binaries"
if (rootProject.hasProperty("OVR_MOBILE_SDK")) {
def oculusDir = rootProject.property("OVR_MOBILE_SDK")
copy {
from oculusDir+'/VrApi/Libs/Android/VrApi.jar'
into 'src/main/libs'
}
copy {
from oculusDir+'/VrApi/Libs/Android/armeabi-v7a/libvrapi.so'
into 'src/main/libs/armeabi-v7a'
}
copy {
from oculusDir+'/VrAppSupport/SystemUtils/Libs/Android/SystemUtils.jar'
into 'src/main/libs'
}
} else {
println "WARNING: not copying Oculus files; OVR_MOBILE_SDK not found"
}
}
task buildNative(type: Exec) {
if (rootProject.hasProperty("OVR_MOBILE_SDK")) {
environment 'OVR_MOBILE_SDK', rootProject.property("OVR_MOBILE_SDK")
} else {
println "WARNING: relying on hard-coded paths and environment variables; OVR_MOBILE_SDK not found"
}
def ndkbuild = ""
if (rootProject.hasProperty("ANDROID_NDK_HOME")) {
ndkbuild = rootProject.property("ANDROID_NDK_HOME")
ndkbuild += '/'
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ndkbuild += 'ndk-build.cmd'
} else {
ndkbuild += 'ndk-build'
}
if (rootProject.hasProperty("OVR_MOBILE_SDK")) {
environment 'OVR_MOBILE_SDK', rootProject.property("OVR_MOBILE_SDK")
}
commandLine '/Users/edhillon3/Library/Android/sdk/ndk-bundle/ndk-build', '-C', file('src/main').absolutePath, '-j', 16//, 'NDK_DEBUG=1'
}
buildTypes {
debug {
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
releaseToGitHub {
}
}
sourceSets.main {
java.srcDirs = ['src/main/java', 'src/main/backends/oculus']
jni.srcDirs = [] // no auto generation of Android.mk
// pre-compiled libraries
jniLibs {
srcDir 'src/main/libs'
}
}
task cleanNative(type: Exec) {
def ndkbuild = ""
if (rootProject.hasProperty("ANDROID_NDK_HOME")) {
ndkbuild = rootProject.property("ANDROID_NDK_HOME")
ndkbuild += '/'
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ndkbuild += 'ndk-build.cmd'
} else {
ndkbuild += 'ndk-build'
}
if (rootProject.hasProperty("OVR_MOBILE_SDK")) {
environment 'OVR_MOBILE_SDK', rootProject.property("OVR_MOBILE_SDK")
}
commandLine '/Users/edhillon3/Library/Android/sdk/ndk-bundle/ndk-build', '-C', file('src/main').absolutePath, '-j', 16, 'clean'
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative, copyOculusFiles
}
task eclipseZip(type: Zip) {
into('GearVRf/res/') {
from 'src/main/res/'
}
into('GearVRf/libs/') {
from('src/main/libs/') {
exclude 'libassimp.so'
exclude 'libjnlua.so'
}
from('build/intermediates/bundles/release/') {
include 'classes.jar'
rename('classes.jar', 'gvrf.jar')
}
}
into('GearVRf/') {
from('src/main/') {
include 'AndroidManifest.xml'
include '.project'
include '.classpath'
include 'project.properties'
}
}
into('GearVRf/java') {
from('src/main/') {
include 'donotdelete.txt'
}
}
baseName 'gvrf-for-eclipse'
}
task eclipseAssembleReleaseToGitHub() << {
println "preparing android library project for eclipse"
eclipseZip.execute()
copy {
from 'build/distributions/gvrf-for-eclipse.zip'
into 'build/outputs/aar/'
}
project.delete('build/distributions/gvrf-for-eclipse.zip')
}
task uploadToGitHub(type: Exec) {
onlyIf {
System.env['RELEASE_ID'] != null
}
onlyIf {
System.env['ACCESS_TOKEN'] != null
}
commandLine '../../tools/upload_to_github', file('build/outputs/aar/framework-releaseToGitHub.aar').absolutePath
}
uploadToGitHub.doFirst {
println('uploading to github')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(dir: 'src/main/libs', include: ['*.jar'])
}
assembleDebug {}.doLast {
task copyAARFiles(type: Copy) {
if (rootProject.hasProperty("LIBS_DIRECTORY")) {
println "copying aar files to the libs_directory"
def libsdirPath = projectDir.absolutePath + '/../../../' +
rootProject.property("LIBS_DIRECTORY")
def libsDir = new File(libsdirPath);
if (libsDir.exists()) {
from 'build/outputs/aar'
into libsDir
include '**/*.aar'
} else {
println "Cannot copy aar files, libs directory does not exist!"
}
}
}
assembleReleaseToGitHub {}.doLast {
println 'removing oculus binaries'
exec {
commandLine = ['zip', '-d', 'build/outputs/aar/framework-releaseToGitHub.aar', 'libs/VrApi.jar']
}
exec {
commandLine = ['zip', '-d', 'build/outputs/aar/framework-releaseToGitHub.aar', 'libs/SystemUtils.jar']
}
exec {
commandLine = ['zip', '-d', 'build/outputs/aar/framework-releaseToGitHub.aar', 'jni/armeabi-v7a/libvrapi.so']
}
eclipseAssembleReleaseToGitHub.execute()
uploadToGitHub.execute();
}
Find gradle.properties file and add the following:
# Un-comment and add the path to ovr directory
OVR_MOBILE_SDK=\.\.\/GearVRf\/ovr_mobile_sdk

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
}

Android nkd-build script finisched with error (exit value 2)

Every time i try to build an android app, that uses ndk to run native code, i get the following error:
Error:Gradle: Execution failed for task ':sampleNDK:ndkBuild'.
> Process 'command 'C:\NDK\android-ndk-r10e/ndk-build.cmd'' finished with non-zero exit value 2
I use Intellij with a grandle projekt. I think the error appears in this function in the build.gradle file:
task ndkBuild(type: Exec) {
def ndkDir = plugins.getPlugin('com.android.application').sdkHandler.getNdkFolder()
if(org.gradle.internal.os.OperatingSystem.current().windows){
commandLine "$ndkDir/ndk-build.cmd", 'NDK_PROJECT_PATH=src/main'
//does not work too
//commandLine "$ndkDir\\ndk-build.cmd", 'NDK_PROJECT_PATH=src/main'
}else{
commandLine "$ndkDir/ndk-build", 'NDK_PROJECT_PATH=src/main'
}
}
In fact that i'm using windows, i think the error appears in the if case.
Does anyone know what went wrong or what i can try to avoid the failure?
UPDATE
That's the whole build script. Maybe that is helpful.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
}
apply plugin: 'com.android.application'
repositories {
jcenter()
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "de.anmi.android.samplendk"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
sourceSets.main.jni.srcDirs = []
sourceSets.main.jniLibs.srcDirs = ['src/main/libs']
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
task ndkBuild(type: Exec) {
// http://stackoverflow.com/questions/28615439/android-gradle-plugin-1-1-0-getndkfolder-not-found-anymore-any-replacement
def ndkDir = plugins.getPlugin('com.android.application').sdkHandler.getNdkFolder()
if (org.gradle.internal.os.OperatingSystem.current().windows) {
commandLine "$ndkDir/ndk-build.cmd", 'NDK_PROJECT_PATH=src/main'
//does not work too
// commandLine "$ndkDir\\ndk-build.cmd", 'NDK_PROJECT_PATH=src/main'
} else {
commandLine "$ndkDir/ndk-build", 'NDK_PROJECT_PATH=src/main'
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}

Categories

Resources