Android NDK in Eclipse :: (Cannot run program "ndk-build": Unknown reason) - android

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?

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.

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.

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.

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!

Sequoya is your friend. It is a part of Eclipse since Indigo release.
http://www.eclipse.org/sequoyah/

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

Just in case you are somehow only seeing your stdout and not stderr, try redirecting your stderr to stdout.
ndk-build 2>&1

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

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.

Related

Android NDK build, Method could not be resolved

I have an Android project with native code. I'm able to build native code from command line by calling ndk-build command with no errors or warnings. But when I open it in ADT it shows the following error.
Error message: Method CallStaticIntMethod could not be resolved. There are many files with similar errors in the project.
I double checked configuration and here is what I have. Android build, tool chain and includes are properly configured (see pictures below)
Required includes are also visible in the Project Explorer and they are valid (not empty and point to correct header files).
But when I Clean the project and Build it, the errors are still there. Any ideas on how to solve this?
Configuration: ADT 22.6.2, NDK r9d (64-bit), OSX 10.9.2
After some struggling with preferences, I finally found a solution. This is a bug in NDK plugin which was reported to AOSP but not yet fixed. A past of the answer is described in comment #50. Here is the sequence which worked our for me.
Open Project Properties -> C/C++ Build -> Tool Chan Editor
In the section Used Tools replace Android GCC Compiler with GCC C Compiler. If section is empty, just add GCC C Compiler entry in there.
Open Project Properties -> C/C++ General -> Paths and Symbols and add directories, where your h-files to be included are located. Use Move up button to add a folder with your local includes (/AudioPlayer/jni in my case) to the first place. Then add platform and toolchains includes. Built-in includes should stay at the very bottom.
In my case the full paths to the toolchain includes were like below. These are built-in paths of original Android GCC Compiler toolchain, which we have replaced at step 2.
/Tools/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.6/include
/Tools/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.6/include-fixed
Press OK button, clean and re-build the project. All errors must go away. If they stay, try to remove them from Problems view and re-build project once again.
Update: I have found another place, where you can add paths to include files. However it appears to be Eclipse version dependent. Project Settings -> C/C++ General -> Processor Include Paths, Macros etc. -> CDT User Settings Entries -> Add. After I added the paths listed above, there is no compilation issues anymore. Development is fun again.
Yes, its caused by the IDE not knowing where all of your headers and any libs you linking again are. The errors are generated by the IDE's autocomplete/bug system. You can either fix your includes within eclipse or remove them as errors in the preferences. 
I had a similar error and solved it by going to project->properties->discovery options and changing the discovery profile from managed build system to GCC, after changing to GCC C Complier from Android GCC Compiler and updating the include directories.

Tesseract OCR Android in Windows

I've read all of questions forums and blogs about it but i still have a problem. Firstly, i ticked tess-two as a library also my project's using tess-two as a library. I downloaded Android-NDK and from my project's properties i clicked Builders and then new -> Program then i choose ndk's ndk-build file. By the way my project is Gautam Gupta's project. He'd given project. Link: https://github.com/GautamGupta/Simple-Android-OCR. When i run that project in my phone, application starts and captures photo but when i press save then application gives error below. http://t1307.hizliresim.com/1c/l/qg0rl.png
Looks like you need to download only TessTwo, make sure you have properly setup the environments variables (ANT_HOME, ANDROID_HOME and ANDROID_NDK) so these point to where you have Ant and Android SDKs.
Then it's a matter of building the project by following TessTwo guidance. That you set up the library-project that can be imported.
Don't forget that the line commands must be performed in CygWin. Once the library project is built you should have correct .so files in libs/*. In order to actually use these, you could start with this link.
#Burak:
I have solved my problem. For Windows;
Write the codes below to Cygwin
a.cd <project-path'i>/tess-two
b.export TESSERACT_PATH=${PWD}/external/tesseract-3.01
c.export LEPTONICA_PATH=${PWD}/external/leptonica-1.68
d.export LIBJPEG_PATH=${PWD}/external/libjpeg
e./cygdrive/<ndk-directory>/ndk-build
Write the codes below to CMD
f.android update project --target 1 --path .
g. ant release
Don't forget the "." at step f.

build-local.mk: No such file or directory

Please help, I have a very wierd error here, while I trying to compile project. Console says:
03:17:23 ** Auto Build of configuration Default for project
MyProject * bash ndk-build all make.exe:
C:\workspace/MyProject/build/core/build-local.mk: No such file or
directory make.exe: ** No rule to make target
`C:\workspace/MyProject/build/core/build-local.mk'. Stop.
03:17:24 Build Finished (took 654ms)
So I'm trying compile code from book "Android NDK for Beginnners". First of all, an author telling to convert java project to C++ project. Once I did it - an error appears. To fix it I need to build library with ndk-build , an autor offers to make changes in project properties, exactly go to Builders and change default build command to ndk-build, but thats woun't work without bash word before it. So when I figured that out and tried to build the project - an error occures.
Help please, I can' find the solution.
Your book is probably outdated, or it does not address Windows environment. On Windows, instead of ndk-build command or bash ndk-build, use ndk-build.cmd. Download and ise the latest version of NDK.

How to setup cocos2dx for android on MacOs Lion?

I am trying to setup cocos2dx with eclipse on a MacOs Lion. I am following the tutorial below:
http://www.raywenderlich.com/11283/cocos2d-x-for-ios-and-android-getting-started
When I try and execute the ndk build shell tool i get the following error:
Davids-iMac:~ davidcavanagh$ /Users/davidcavanagh/Downloads/android-ndk-r8b/ndk-build ;
exit;
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/Users/davidcavanagh/Downloads/android-ndk-r8b/build/core/build-local.mk:130: *** Android
NDK: Aborting . Stop.
logout
[Process completed]
I have tried defining the NDK_PROJECT_PATH through the terminal by using
export NDK_PROJECT_PATH=/Users/davidcavanagh/Downloads/android-ndk-r8b/
This doesn't work. Can anyone help me as I have been stuck on this for ages. Is there a certain way of setting the path that I am not doing?
Thanks
Re-read and re-read again his tutorial. You shouldn't be executing the ndk-build script without supplying the arguments it needs for building your project.
He mentions using the create-android-project.sh script inside the cocos2d-x directory. Make sure you do that, and follow the steps there where you'll supply the project name, reverse-domain application ID (e.g. com.company.project), and so on. This will generate your project directory inside of the cocos2d-x directory, which you can easily & safely move to another location.
Once you have that project set up, you can import it into Eclipse, which, primarily, allows you to build the Android project, but does not refer to the C++ code directly. (You'd need to get CDT and the NDK plugin to actually hook your C++ code up inside of Eclipse).
Otherwise, what's worked for me so far is to run the build_native.sh script inside the project directory whenever I have new code that I want to test on my device. This script references the jni/Android.mk file, where you need to specify your header paths and *.cpp files (similar to how you'd have to specify all of your implementation files with g++ on the command line).
But before you do that, you need to make sure all the environment variables that build_native.sh uses are set up. You can either put them in your ~/.bashrc file, or you can just stick them in that project directory (up to you. bashrc will make them available to all projects whenever you launch a new terminal, whereas hardcoding them into build_native.sh will only offer them to that specific project). I think all you need is to assign the full paths to NDK_ROOT, COCOS2DX_ROOT, and APP_ROOT, and build_native.sh should run successfully.
If you look down at the bottom of build_native.sh, you'll notice an invocation of ndk-build, along with all the necessary parameters that you were missing in your terminal session.

NDK build error

Hi I am new to Android NDK Development.
MacBook-Pro:JNIexample sk$ ndk-build
usage: dirname path
gmake: /Users/sk/build/core/build-local.mk: No such file or directory
gmake: *** No rule to make target `/Users/sk/build/core/build-local.mk'. Stop.
Why do I get his error?
So I was having the same trouble, and it looks like if I have any directory which is a part of full dir-path which has dir-name with space (' ') in between then 'ndk-build' wont be able to resolve paths. So my directory name "development tools" wasnt good enough so I changed it to "developmenttools" and it worked. If I hard-code the path in 'ndk-build' then it was working so found out the reason.
You need to specify the project you want to build. Like this: ndk-build -C location_of_project.
For example, to build the hello-neon sample that comes with the NDK you would go to your ndk install root and do ndk-build -C samples/hello-neon
The ndk-build tool is actually just a wrapper that calls gmake with the build-local.mk file. It finds the build-local.mk file by creating a relative path rooted at the location of the ndk-built tool. Sounds like you don't have the full NDK installed, or maybe moved the ndk-build tool without moving the rest of the NDK contents?
I also faced this problem. And i solved it and post entire answer here. I hope it helps you.
Please notice that from the error message:
gmake: /Users/sk/build/core/build-local.mk: No such file or directory.
The build/core/builid-local.mk is actually in the ndk's root directory, why is it listed as the /Users/username/build…?
I've encountered the same error on my Macbook. I've put the ndk inside /Applications/Android Studio.app directory, since there is a space between the name, somehow the tool in ndk can't resolve the implied path. That's why the error message is printed.
Later I renamed Android Studio.app to Android-Studio.app and thus resolved the issue.
The solution for me was different. If you look in the ndk-build script, you see it immediately runs `dirname $0` to get the directory to work in.
I was calling "ndk-build" from my command line, which was using a copy of the ndk-build script that I had put in /usr/local/bin/ and so my error was '/usr/local/bin/build/core/build-local.mk: No such file or directory'.
The solution is to be in the ndk folder where the real ndk-build script lives, and use the -C /path/to/project option to tell it where to start. So, 'cd /path/to/ndk' and then run './ndk-build -C /path/to/project'
I was having same problem. I created new workspace and import existing project to it. But forgot to add ndk location in windows->preferences->Android->NDK.

Categories

Resources