Android NDK keeps looking for "g/David/..." - android

I installed the latest version of the Android NDK (r4) on Windows, plus a fresh installation of cygwin with the required packages, latest Android SDK, Eclipse + Android plugins.
Whenever I try to build any of the JNI code from cygwin (Be it the samples from the NDK, or a custom project), I'm getting:
$ make APP=demo
Android NDK: Building for application 'demo'
Compile thumb : demo_lib <= apps/demo/project/jni/demo.c
cc1: error: /cygdrive/g/David/ndk/build/platforms/android-3/arch-arm/usr/local/i
nclude: not a directory
cc1: error: /cygdrive/g/David/ndk/build/platforms/android-3/arch-arm/usr/include
: not a directory
make: *** [out/apps/demo/armeabi/objs/dmeo_lib/demo.o] Error 1
My name is not David, and I don't have a G drive.
Seems like this path is somehow hard-coded into this release. I tried looking for the string g/David in the NDK directory. It appears in many of the binaries, some .info files, as comment in some headers, and in two mkheaders.conf files:
<NDK>\build\prebuilt\windows\arm-eabi-4.2.1\lib\gcc\arm-eabi\4.2.1\install-tools\mkheaders.conf:
SYSTEM_HEADER_DIR="/cygdrive/g/David/ndk/build/platforms/android-3/arch-arm/usr/include"
and
<NDK>\build\prebuilt\windows\arm-eabi-4.4.0\lib\gcc\arm-eabi\4.4.0\install-tools\mkheaders.conf:
SYSTEM_HEADER_DIR="/cygdrive/g/David/ndk/build/platforms/android-3/arch-arm${sysroot_headers_suffix}/usr/include"
I changed both files to point to the correct path, but I get exactly the same error (with the original path).
I have limited experience with cygwin, unix, or make. Any ideas?

This is probably the symptom of an incomplete / broken NDK installation.
The gcc binaries always hard-code the original sysroot directory within their executable, but these are not normally found if appropriate system headers and libraries are provided otherwise. And they should.
Can you try re-downloading and re-unzipping the NDK package from the official site, and see if this fixes the problem ?

I had the same problem.
It's because maybe you have a G: drive for DVDRom or HDD (for me G: was the DVDROM). Problem resolved when i unactivate the G: drive ....

I have an (inactive) G: drive in Windows XP, too (some USB drive assigned for it). This prevents some builds with NDK r4, and I could not figure why sometimes the error pops up.
Anyway, here's the workaround:
prepare the alternative cygdrive path: mkdir c:\cygwin\ccc
use cygwin's mount -c ccc to change the cygdrive path prefix
create missing directories:
mkdir -f /cygdrive/g/David/ndk/build/platforms/android-3/arch-arm/usr/local/include
mkdir -p /cygdrive/g/David/ndk/build/platforms/android-3/arch-arm/usr/include
Now, you can run android-ndk-r4\ndk-build

Related

How to Build curl with NDK 10rd in windows

I am new to NDK, Now I want to build curl with NDK 10rd in windows 7. I download curl's code at[https://github.com/bagder/curl].
I have tried and searched many ways. But It does not work.
The error info is :
E:/study/thrid_lib/curl-master//jni/src/setup.h:41:25: fatal error: curl_config.h: No such file or directory
#include "curl_config.h"
INFO:
My curl 's path is "E:/study/thrid_lib/curl-master/jni".
Using cmd into this path and typing "ndk-build",then error will appear.
At last, thanks.
I have solved this problem.The details are below:
Put the curl(My curl's version is 7.42.1) into the jni folder.
Download the file(http://mtterra.com/files/curltest.tar.gz) and extracting it.
Copy the curl_config.h to the curl/lib.
Copy the Android.mk to the jni folder.
Run ndk-build in cmd.
That 's all. If you have anythings confused, feel free to contact me.
The instructions explain how to cross-compile curl with a standalone toolchain.
As in many similar cases, you may find it easier to launch Linux in a VirtualBox and compile the library there, rather than to struggle with cygwin or mingw.

Compile libpcap using Android NDK

I've been doing a lot of attempts to get libpcap compiled for Android, and I don't see any pattern or any progress worth writing down.
I have a very simple sniffer (that works fine in a MIPS linux) that uses libpcap, so I thought to myself oh, ok... no biggie... I'll just compile libpcap for Android (in the end, Android is just a Linux)... and here's where the problems started. I have no idea on how to compile libpcap using ndk-build and the Android.mk and all that infrastructure.
I have the Android NDK in a directory. That NDK has the toolchains built (I have a lot of directories under ~/Documents/Projects/Android_NDK/toolchains/ ) but none of the toolchains has libpcap available.
I've tried with two different libpcap version or... branches:
The Android one, which is the one I'd like to use,
https://android.googlesource.com/platform/external/libpcap/
and the regular one:
http://www.tcpdump.org/release/libpcap-1.5.3.tar.gz
All tries I've done have been very unsuccessful. I've seen the question Android NDK: Link using a pre-compiled static library which is similar, but I'm still getting various errors.
I have downloaded those pcap libraries to their own directories. Maybe is that the problem? Do I need to put the Android libpcap in some directory within the NDK root directory and re-create the toolchains?
I'm using NDK-r9 on a MacOSX 10.9.2 64bit.
Finally!!
After getting annoyed by the non existing headers in and stuff like that, I found this question, that pointed to a SVN repo (http://sourceforge.net/p/prueba-android/code/HEAD/tree/trunk/jni/) with a libpcap that compiled!
If someone else wants additional details on how my Android.mk and directory structure looks like, please add a comment and I'll extend this answer.
Please read an excellent article at http://blog.umitproject.org/2011/05/libpcap-for-android.html. There are instructions that will help you link to libpcap, but the most important takeaway is that you cannot use libpcap on non-rooted Android. So maybe it's not worth your effort.
On a rooted device, you can simply install a free sniffer like Shark for Root.
If anyone else is having problems compiling libpcap for Android using the NDK, there is version 1.5.2 here with a built Android.mk file in it: https://android.googlesource.com/platform/external/libpcap.git and instructions for compiling this using the NDK are here: http://ducbh.blogspot.co.uk/2013/12/cross-compile-libpcap-for-android.html . I can confirm this works using the current NDK (r10b)...although you may have to add AndroidManifest.xml (blank) and and Application.mk that points to your Android.mk file.
I don't think it would be that difficult to modify the .mk file for the current libpcap version (1.6.2)
In case anyone ends up here in 2022+. You can now cross-compile for Android from the official source. Steps:
First, setup the NDK:
Download Android NDK (I used r21e) and extract to a directory of your choosing:
$ cd ~
$ mkdir Android
$ unzip android-ndk-r21e-linux-x86_64.zip
Prepare the environment variables for cross-compilation by placing the commands below (replace <YOUR_USER>) into a file named setup_env.sh (can be saved anywhere):
export NDK=/home/<YOUR_USER>/Android/android-ndk-r21e
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export TARGET=aarch64-linux-android
export API=21
export AR=$TOOLCHAIN/bin/$TARGET-ar
export AS=$TOOLCHAIN/bin/$TARGET-as
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/$TARGET-ld
export RANLIB=$TOOLCHAIN/bin/$TARGET-ranlib
export STRIP=$TOOLCHAIN/bin/$TARGET-strip
Now, build libpcap:
Download libpcap tar ball (e.g. https://www.tcpdump.org/release/libpcap-1.10.1.tar.gz)
Extract (in a directory of your choosing): tar xf libpcap-1.10.1.tar.gz
Prepare your env: source <path_to>/setup_env.sh
Change into the extract libpcap directory and configure: ./configure --host=aarch64-linux-android
I found the Makefile generated had the wrong linker set (line 48), so I had to change it to: LD = /home/<YOUR_USER>/Android/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/x86_64-linux-android/bin/ld
Finally, build: make
This build worked for me with running tcpreplay on a rooted Android, hopefully it works for other purposes as well!

How to install Android NDK

I'm trying to use FastCV, https://developer.qualcomm.com/mobile-development/mobile-technologies/computer-vision-fastcv/setting-developer-environment. It tells me that I need to install Android NDK. I did that and put it in the place that it told me to.
I then try: cd /cygdrive/c/Development/Android/android-ndk-r6/samples/san-angeles
And it tells me that there is no file or folder by that name.
I then try the command ndk-build and it tells me that there is no command by that name.
Note: there is a cygwin section in the "How to get started" section, but it says that it is not relevant for mac users.
Here is another part that I don't understand:
MAC: Update $path variable to point to the ndk directory. Modify the /Users/<login-name>/.tcshrcfile to set the path by adding /Users/<login-name>/Development/Android/android-ndk-r6. Along with the changes applied in the section 'Android SDK Downloader' you will have:
set path = ( $path /Developer/usr/bin /Users//Development/Android/android-sdk-mac_x86/tools /Users//Development/Android/android-ndk-r6 )
I have NO idea what is being asked of me here.
I just want to solve this, so I can actually start doing things.
Edit: I think (emphasis on I think) that I misread the instructions about cygwin. So I don't need to do the ndk-build commands. However, I still don't know what the instructions mean about the path stuff
You should download NDK for Mac OS, the 64-bit version can be found here. Note that today we don't use r6 anymore, the current version is r9.
NDK is distributed as a plain compressed archive. Mac will open it for you and extract all files. Copy this whole tree wherever you like, and add the top directory to ${path} environment variable.
Let's say you decided to copy extracted NDK into /Users/user678392/ndk. Then you should try
cd /Users/user678392/ndk/samples/san-angeles
ndk-build

Fatal Error: openssl/evp.h No such file or directory

I successfully compiled openssl using android ndk build and .so files are built successfully.
I am trying to 'include' built .so files in an android project.
Getting an error in below line:
#include "openssl/evp.h"
fatal error: openssl/evp.h: No such file or directory
compilation terminated.
make: * [obj/local/armeabi/objs/iedemo/anotherdemo.o] Error 1
However, I am include stdio.h and string.h files.
I am explore /usr/include/openssl directory, I am able find all openssl related .h files here. And, stdio.h and string.h files are present in /usr/include directory.
I have installed libssl-dev package too. Command (sudo apt-get install libssl-dev)
Please help me!!
When encountering this problem on Debian or Ubuntu, it can be solved with the following command:
apt-get install libssl-dev
For people like me, that uses windows OS and they accidently came to this page and the above solutions did not solve their problem, can try the following solution:
I downloaded the OpenSSL executable from the official website, and selected the file with the description that contanins the following line (Recommended for software developers by the creators of OpenSSL).
At the time of writing this solution, the file version is (Win64 OpenSSL v3.0.0), and it can be directly downloaded from the following link.
Here is an Image for more declaration:
After that, I did the following steps:
Install the OpenSSL form the .exe file.
Copy the bin folder directory path (in my case it was C:\Program Files\OpenSSL-Win64\bin) and add it to the system enviroment variables.
Copy the include folder directory path (in my case it was C:\Program Files\OpenSSL-Win64\include) and add it to the system enviroment variables.
Then compile the source code that used the openssl library and header files, they should be compiled with no errors.
Your Android.mk should specify the openssl include directory (not /usr/include/openssl, but the one that goes with the files that you built for Android using NDK. Something similar to
LOCAL_C_INCLUDES += /home/Charan/openssl/include
But you will also need to specify the path for .so files that you have built, and make sure they are correctly deployed with your app. The things can go messy, but luckily there is a working example: openSSL using Android's NDK problems.
I ran into this when building a PHP package using PECL and was able to install the header file as part of openssl-devel
On CentOS/RHEL: yum install openssl-devel
On Ubuntu/Debian: apt-get install openssl-devel

Android.mk rules to make a file.o from many files.txt then link it with other files.o produced from files.cpp

I'm porting a modem connection manager written in C++ from linux to gingerbread. This does not end up being an "app" with a "gui" that I would use a java wrapper with the NDK but a service that is called at boot from "init.rc". I found some not up to date docs related to android build system under build/core/. There you find some html files explaining the basics of Android build system and several "file.mk" which are some templates for common situation like creating a c++ executable, static libraries, shared library etc.
I place my tree with all the sources under external/myservice and it's meant to be compiled at the same time as Android itself. (I've already ported the kernel to my platform and it works, just the modem left to go)
In a subfolder in an Android.mk file, I have a bunch of ".cpp" files listed with the variable LOCAL_SRC_FILES := cppfile1.cpp cppfile2.cpp .... That will generate cppfile1.o cppfile2.o ...
I need to link those cppfile*.o with objfile.o to form a libfile.so. I found the rules on how to generate a libfile.so from a bunch of files.o.
Where things get complicated, is to port the "linux makefile" command to create objfile.o. Here is how it looks like
$(LD) $(LDFLAGS) -r -b binary -o QMIDB.o \
QMI/Entity.txt \
QMI/EnumEntry.txt \
QMI/Enum.txt \
QMI/Field.txt \
QMI/Struct.txt
Which means it is a linker job to merge a bunch of text file to make that objfile.o. That file is just a bunch of initialized data structure, there is no code to execute in it but it's pretty ugly to look at all files.txt with a text editor.
I have no clue how to integrate that in the Android.mk file. How can it be done? I'd even appreciate just a hint on where I can find more information. It is easy to find information on building Android applications but it's another story to find anything closer to Android/Kernel itself.
From the mk. file file you can easily get so file....
You need to use android Ndk setup and cygwin setup if you are using windows platform to genreate so file from your native code.
Firstly install and place ndk to a location...
Then install cygwin setup not default one check all features in the installation process (it a sort of linux terminal) as ndk-build command is recognized from linux terminal.
Now from your cygwin terminal get access to your project folder jni file.. or where mk is placed...
http://developer.android.com/sdk/ndk/index.html
Use the following referal how to run ndk-build command from cygwin terminal..
Now providing complete path of ndk we use the ndk-build command...
After that the complied code generates the .so file for our project...
Now what we are using System.loadlibrary command to use the so file i.e our native code can now be used.
Note to get so file form mk we need to complie using ndk setup.We can't directly copy paste so file to make our native code run.Also we we are using windows platfrom we will need to use cygwin setup to do that

Categories

Resources