7

I am loosing my mind trying to build my NDK project from eclipse using the CDT plugin and i get the error:-

NDK (Cannot run program "ndk-build": Unknown reason)

The application runs but i loose all of the console output for the build process, this is a nightmare when trying to compile and i have to do it on the command line.

This is how i got there:-

I Downloaded and installed the CDT plugin for Eclipse.

Then:

Added my JNI folder and also your Android.mk in the JNI directory.

Then:

Go FILE / NEW / OTHER /C/C++ / ( Convert to a C/C++ Project )

On setting up my build target:

Check the project, choose MakeFile Project and Other Toolchain click NEXT

Then finally in project properties:

PROJECT / PROPERTIES / C/C++ uncheck " use default build command" replace "make" with "ndk-build" 

Then when it builds it spits the error to the console. Though it compiles and makes the build which runs on the device i cant see any of the build output.

I have "ndk-build' in my .bash_profile with the following variables:

:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_NDK

I can compile using ndk-build from command line fine. It seems that Eclipse cant see my PATH:

This is on Mac OSX, in Helios version 2.

EDIT: Ok so this compiles fine, and the output from the build is infact hidden underneath this message, this is far from ideal, as when i need to review what items have been built i cant as its covered up. How do i get rid of it?

Dev2rights
  • 3,469
  • 3
  • 25
  • 42
  • Well there is your problem right there your using a Mac...Did you configure your Builder properly did you make sure to add all dirs to the builder? I used these guides and I seemed to get it working with out that much pain. Hope one of these helps, http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/comment-page-2/#comment-18105 http://www.rbgrn.net/content/348-get-your-eclipse-integrated-ndk-on http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/ – JPM Mar 09 '12 at 20:13

9 Answers9

13

In my case, I had to give complete path to my ndk-build command in eclipse in order for it to build:

Eclipse -> Your Prj -> Right Click -> C/C++ Build -> "Builder" group: the value for "Build command" should be complete path something like below (instead of just "ndk-build")

/Users/vshakya/MySoftware/android-ndk-r8/ndk-build

I hope this will help others in future for I just wasted like 30 minutes to figure this out.

Viren
  • 2,161
  • 22
  • 27
  • This is the only solution I have been able to get working. I cant figure how to change the default Builder settings. Eclipse is always defaulting the build command to ${NDKROOT}/ndk-build.cmd Major P.I.T.A! – Akos Cz Jul 23 '12 at 21:38
4

I had the same problem and although the description at http://developer.android.com/tools/sdk/ndk/index.html#Installing for installing the NDK is good, it does not cover the solution to this frequent problem.

Eclipse seems to allow you to configure stuff in multiple places, you can do global modifications via Window menu or project specific configurations via the Properties option. Simplest is to add full path for ndk-build (ndk-build.cmd for windows) in the {Properties; C/C++ Build} Build command box.

Pete
  • 143
  • 8
4

It might seem stupid but have you check if there are several consoles ? I can imagine there is one for the message you quoted, and another for build output.

See also this : the answer has an interesting link, dealing with setup but also related to eclipse integration.

Community
  • 1
  • 1
rockeye
  • 2,765
  • 2
  • 30
  • 44
  • When you say several consoles... do you mean several tab in the output pane of Eclipse? or several threads of execution having access to the same log output? Can you expand a little? Its a work around if i can suppress the error, but to be honest at this stage it works and only every the builds i need to clean to see the output underneath. But i would love to know why the ndk compiler causes this most marvelous;y definitive error :P – Dev2rights Mar 15 '12 at 11:20
  • Ok after ages of playing about with this i found that the answer was to click the little monitor (to display Selected console ) icon and that seems to display the errors so somewhere the out put gets overwritten by ndk-buikd. – Dev2rights Apr 03 '12 at 17:27
3

In my case, I had to give complete path to my ndk-build.cmd command in eclipse in order for it to build:

Eclipse -> Your Prj -> Right Click -> C/C++ Build

C:\Prateek\android-ndk-r9\ndk-build.cmd

user1530779
  • 409
  • 5
  • 8
3

The easier solution, build with the command ndk-build from eclipse project path:

$PROJECT>ndk-build

Everytime you change your native code.

To compile on eclipse, i followed the next steps:

  • Create the eclipse project.
  • Add the native code (.cpp) at jni folder
  • Create Android.mk and Application.mk following the typically structure
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := $$Add source files$$

LOCAL_LDLIBS := -lpcap

LOCAL_MODULE := libtest

LOCAL_C_INCLUDES := $$Path of the header files used$$

include $(BUILD_SHARED_LIBRARY)

----------------

Aplication.mk depends that the type of options you want
  • When eclipse throw warnings, put your mouse on jni code part, and check the option: "convert project to native code", and will convert the project automatically.

Next time you compile, ndk-build V=1 will be called, compiling native code, and then, compile Android part.

NOTE:

You must be able to use ndk-build in all folder on your system. The command detect where has been called, and look for the jni folder, to use the Android.mk to compile all native code.

The basic structure that look for is:

  • $PROJECT>jni/
    • /Android.mk
    • /Application.mk
    • /code.cpp

But you can modify Android.mk to look for code in other paths.

I hope it help you!

vgonisanz
  • 11,831
  • 13
  • 78
  • 130
  • But NDK-BUILD isn't in the project path its in the path of the the NDK. Or am im missing something here? – Dev2rights Mar 16 '12 at 14:36
  • you must be able to use ndk-build in all folder on your system. The command detect where has been called, and look for the jni folder, to use the Android.mk to compile all native code. – vgonisanz Mar 16 '12 at 22:11
  • Oh i see, i can call ndk-build from all folders. I have the NDK on my path and it compiles fine from calling ndk-build from terminal and also it compiles fine in eclipse i just get this error that covers up the errors found when compiling. – Dev2rights Mar 16 '12 at 22:22
  • If you need to look whats is compiling, lines, paths, etc, use the command: $(warning Compiling Android.mk from $(MYVAR)), this command write compiling extra info with variables and text – vgonisanz Mar 17 '12 at 07:44
  • Is this in my Application.mk or my Android.mk and what precendence does this hold ? – Dev2rights Mar 17 '12 at 10:00
  • if you put $(warning XXX) on you make file (Android.mk) you can get userfull info – vgonisanz Mar 17 '12 at 10:45
  • Ok i looked into it, it outputs additional information at compile time which i didn't know, but still at the end of the compile i get the same error – Dev2rights Mar 17 '12 at 12:42
3

Sequoya is your friend. It is a part of Eclipse since Indigo release.

http://www.eclipse.org/sequoyah/

pinxue
  • 1,736
  • 12
  • 17
  • I read about Sequoya, but this is a separate piece of technology and im 99.9% there minus this issue, id rather just find out why this happens, – Dev2rights Mar 17 '12 at 09:58
2

Just in case you are somehow only seeing your stdout and not stderr, try redirecting your stderr to stdout.

ndk-build 2>&1

Phuong Nguyen
  • 909
  • 7
  • 20
1

make sure to use "absolutepath\ndk-build.cmd" instead "absolutepath\ndk-build" in windows. It compiles without error with .cmd added

ksu
  • 882
  • 1
  • 11
  • 17
0

In addition to system environment.

In Eclipse, You also need to go to preferences->c/c++ Build -> environment. Add a new variable with the name "NDKROOT" and value set to the NDK installation path.

This works for me.

msjianghu
  • 11
  • 1