Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio failed build NDK project non-zero exit value

I imported a project that I was working on from an Eclipse Android SDK environment to the new Android Studio. Trying to run the project I get this

Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'ndk/ndk-build'' finished with non-zero exit value 2

So first of all for me it's weird to see this error, because working in Eclipse Android SDK before, I ran ndk-build by myself which I still do. So is Android Studio running ndk-build for me now? Because when I run it in Terminal I have no problem at all and here it tells me bad exit-value.

And then I searched on the internet and found a "quick fix", which is to create an empty .c file, because you can't build/run ndk project with no .c files. This, not surprisingly, does not work for me because we have plenty of .c files in the .jni folder.

Just to mention I'm on a Macbook Pro under Yosemite, and the project should have no problems in itself.

Thanks in advance for any help.

like image 490
Denis Davydov Avatar asked Apr 13 '15 12:04

Denis Davydov


Video Answer


3 Answers

Encountered same error while importing a project from windows to mac, I tried all the above solutions, did not work. Finally noticed that there were "multiple target patterns" which was causing this error.

Solution : Delete the "obj" folder within your NDK and rebuild.

Done !!

like image 198
Bhanz Avatar answered Sep 25 '22 15:09

Bhanz


To see what is the exact problem do these:
1- Make sure you have set ndk path correctly, for example in my project I put ndk.dir=/usr/local/opt/android-ndk-r13b in local.properties file
2- Go to app directory of your android app
3- Run this command: <ndk_build_path> -C <jni_path> NDK_OUT=<jniLibDir> all NDK_DEBUG=1 example :

/usr/local/opt/android-ndk-r13b/ndk-build -C /MYAPP/app/src/main/jni -j 4 NDK_OUT=../jniLibs all NDK_DEBUG=1

then you can see what's going wrong.

like image 21
Iman Mirzadeh Avatar answered Sep 24 '22 15:09

Iman Mirzadeh


This is known problem of Android Studio, caused by very limited support of NDK-enabled projects. Answering to your question: yes, Android Studio now run ndk-build on its own, but it ignore existing Android.mk and generate one on the fly (and do it wrong for any non-trivial NDK-enabled project). Practically, the best way to fix this is to disable Android Studio's limited NDK support and call ndk-build from gradle script. Here I've described it more detailed and how to get it fixed.

like image 20
Dmitry Moskalchuk Avatar answered Sep 25 '22 15:09

Dmitry Moskalchuk