|
Android NDK for Windows setup guideBy Radu Motisan Posted on August 24th, 2010 , 5787 Views (Rate 5.79) |
Introduction
Since most of the NDK tools are coming from the Linux environment, that OS was my first approach in building native C applications for Android. See this tutorial for a start.
However, I also needed to be able to compile JNI Android apps using the Windows environment. It proved an easy task, but there were some issues, so I decided to write this guide.
Install Android NDK on Windows and use it to compile a JAVA/JNI application
You will need an internet connection to install Cygwin and the Android SDK automatically from the Internet.
Download link.
Current version of the file is: android-ndk-r4b-windows.zip 45MB
Download link. (Direct Link)
Select the mirror you need to download from then follow the installation guide.
On package selection, Open Devel category and check "make":

I've installed it to C:\cygwin
Download link.
Current version is android-sdk_r06-windows.zip 23MB
4.1) Unzip the zip content to a location on your harddisk. I choose:
D:\work_code\android\android-sdk-windows\
You will find SDK Setup.exe . Run it. I get a warning to install JAVA JDK
4.2) Download Java JDK
Download link.
Select platform "Windows". Current file is: jdk-6u21-windows-i586.exe (Direct link)
4.3) Install the Java JDK: simply run the exe . It takes a few minutes to complete.
4.4) Re-run the SDK Setup.exe from the Android SDK.
This opens the Android SDK and AVD Manager. If you get a HTTPS Error:

go to Settings and check the "Force https:// ..." checkbox:

4.5) Go to Available Packages, select all, and press Install Selected:

The installer will download the packages from the internet, and might prompt you to accept terms, which you must do if you want to continue with the installation. This step takes a few minutes.
5.1) Unzip the NDK zip file. My choice is: D:\work_code\android\android-ndk-r4b\
5.2) Configure Cygwin parameters
Go to the Cygwin folder and open Cygwin.bat. It contains something like this:
@echo off C: chdir C:\cygwin\bin bash --login -i
Using any text editor change it to:
@echo off set IS_UNIX= set DEV_ROOT=d:/work_code/android/BlueInput set JAVA_HOME=c:/Progra~1/Java/jdk1.6.0_21 set CLASSPATH=d:/work_code/android/BlueInput/obj set PATH=D:/work_code/android/android-sdk-windows/tools;D:/work_code/android/android-ndk-r4b set ANDROID_NDK_ROOT=/cygdrive/d/work_code/android-ndk-r4b set NDK_PROJECT_PATH=/cygdrive/d/work_code/android/BlueInput C: chdir C:\cygwin\bin bash --login -i
The path in the config, d:/work_code/android/BlueInput, is something I'm currently working on. Change to your Own project name. The project must be organized as follows:
A) The JNI part (the .c and .h and Android.mk files) in:
d:/work_code/android/BlueInput/jni
B) The JAVA part (assets,bin,gen,jni,libs,obj,res,src with the .java files) in:
d:/work_code/android/BlueInput
For these paths always use forward slashes.
5.3) Open Cygwin and browse to the NDK folder, using cd

cd d:/work_code/android-ndk-r4b
5.4) Type ./ndk-build to compile the JNI project

The C files have been successfully built. Now using Eclipse, you can build the Java android project, and it will include the JNI part automatically. Easy.
|
|






















August 26th, 2010 at 1:38 pm
For debug output use ./ndk-build NDK_LOG=true APP=BlueInput V=1
November 16th, 2010 at 7:52 pm
Thanks. That helper a lot.
November 18th, 2010 at 11:49 am
[...] NDK has been released and the JNI development is not only possible, but also easy. Have a look on this article on the Android NDK. The new challenge is to use the NDK to compile Native ARM-EABI executables that [...]
December 24th, 2010 at 1:42 pm
I get the error that GNUMAKE must be defined. for a sample app.
I am using android NDK r5
February 1st, 2011 at 3:35 pm
[...] Some additional resources: http://www.pocketmagic.net/?p=665 http://developer.android.com/sdk/installing.html http://www.pocketmagic.net/?p=1332 [...]
February 14th, 2011 at 10:19 pm
[...] AW: Android NDK: Wie verwenden? schau dir mal folgendes Tutorial an: Android NDK for Windows setup guide « PocketMagic [...]
March 15th, 2011 at 7:58 pm
I am trying to write some part of an indoor navigation application in my HTC Desire with Android 2.2 is installed in. I am currently working on writing a bluetooth device detector. I am going to use bluetooth headsets whose mac addresses already known and try to detect whether they are visible or not. I would like only to ping all the bluetooth devices in the list I have. Isn’t there any way to do that without using “hcitool” or “l2ping” applications and parsing their results? I dont want to root my phone if it is possible.
March 15th, 2011 at 8:23 pm
Hi Mehmet , thanks for posting your message here.
You said “..and try to detect whether they are visible or not” . If they are visible (discoverable), you can do a bluetooth discovery to detect the nearby devices. Would this suit you?
l2cap is not implemented on all Android devices and a general solution is currently problematic.
March 15th, 2011 at 8:29 pm
The problem is, the devices I want to detect are not discoverable. They only stay discoverable for about 30 minutes, however I want them to use longer.
March 15th, 2011 at 8:31 pm
if those remote devices as smartphones, you could write a service that runs on them and keeps a bluetooth host port open (serial, l2cap, etc).
Then you can “detect” if they are in range by opening a connection to your predefined list of addresses.
March 15th, 2011 at 8:33 pm
No they are not smartphones, they are just bluetooth headsets. So I am not able to do anything on the other side.
March 15th, 2011 at 8:42 pm
I see, unfortunately you can’t (yet) relay on L2CAP either.
March 15th, 2011 at 8:59 pm
Do you have any suggestions for my case then??
March 15th, 2011 at 10:19 pm
Clearly what you need is L2CAP Ping. I’ve used it on Windows Mobile for a similar purpose and it works great.
But on Android you’ll run into problems with L2CAP – it will only work on a few devices.
If compatibility is not an issue for you, go for L2CAP Ping.
March 15th, 2011 at 11:25 pm
I am using an HTC Desire, I did not found “l2ping” inside the file system, is it possible to push “l2ping” somehow into the filesystem without root access and use it?
March 15th, 2011 at 11:44 pm
Unfortunately, the Desire is one of the devices that doesn’t have L2CAP support.
March 15th, 2011 at 11:48 pm
Does it make sense to root my device and push “l2ping” inside?
March 16th, 2011 at 12:01 am
No, it won’t work. The BlueZ stack installed on the Desire seems to be incomplete.
April 17th, 2011 at 11:22 am
Hi!
I’m trying to write an application that reads the rssi value of a connection, but I have difficulties connecting to the phone using MAC address.
I managed to build my project using ndk r5b, and I see the logs written in my C code, so the building is complete I think, but every time I want to connect to a device, my phone returns “can’t connect’. I copied all the needed header files into build path and libbluetooth.so too, rooted my phone using z4root and granted superuser rights to the app using “Process p=Runtime.getRuntime().exec(“su”);”(so my app asked for superuser rights and I granted it to it), but I couldn’t connect to any device so far using this code for connection:
jint Java_com_bluetooth_RSSI_connectbt(JNIEnv* env, jobject this, jstring mac)
{
int s, status;
int dd;
int i;
struct sockaddr_rc addr = { 0 };
struct hci_conn_info_req *cr;
char * dest;// = “00:1E:E1:7D:54:B4″;
struct timeval timeout;
dest = (*env)->GetStringUTFChars(env, mac, 0);
__android_log_print(ANDROID_LOG_INFO, TAG, “rfcomm %s”, dest);
// allocate a socket
s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
// set the connection parameters (who to connect to)
addr.rc_family = AF_BLUETOOTH;
addr.rc_channel = (uint8_t) 1;
str2ba( dest, &addr.rc_bdaddr );
// connect to server
__android_log_print(ANDROID_LOG_INFO, TAG, ” Trying to connect”);
//setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(struct timeval));
status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
if (status == 0){
__android_log_print(ANDROID_LOG_INFO, TAG, ” CONNECTED!!!”);
return s;
}
__android_log_print(ANDROID_LOG_INFO, TAG, ” no connect”);
return -1;
}
I get every time
04-17 11:08:11.524: INFO/native_service(7973): Trying to connect
04-17 11:08:11.524: INFO/native_service(7973): no connect
Do you have any ide, what should be the problem?
Thanks in advice
Peter
April 17th, 2011 at 11:24 am
Oh, and I’m using Samsung Galaxy S(rooted, SDK 2.1) and tryed to connect to several phones/laptops.
Peter
April 26th, 2011 at 8:21 am
Thanks man. This got me up and running on Windows.
April 26th, 2011 at 10:18 am
@Karen, you’re welcome, glad it helped
June 16th, 2011 at 5:00 pm
What if our pathes contain spaces ? I tried everything I could found (backslash before space, 40 instead of space, path between quotes,…) but it didn’t help.
June 22nd, 2011 at 9:33 am
I followed the steps, i’m getting following error,
Android NDK: Your APP-BUILD_SCRIPT points to an unknown file: /cygdrive/c/ndkworkspace/ndkfoo/jni/Android.mk
/cygdrive/c/android-ndk-r5b/build/core/add-appplication.mk:116: *** Android NDK:Aborting… .Stop.
Strugling hard to fix this. Please suggest.
June 22nd, 2011 at 9:35 am
Sorry for the typo error. Its APP_BUILD_SCRIPT.
June 23rd, 2011 at 7:37 am
wat does obj contain i thing it has object file where do i get this file…
can any body help me…
July 2nd, 2011 at 10:59 pm
@Nikhil: Same here. Did you ever resolve it?
$ ndk-build
ERROR: You are using a non-Cygwin compatible Make program.
Currently using: C:/utils/mingw/bin/mingw32-make.exe
To solve the issue, follow these steps:
1. Ensure that the Cygwin ‘make’ package is installed.
NOTE: You will need GNU Make 3.81 or later!
2. Define the GNUMAKE environment variable to point to it, as in:
export GNUMAKE=/usr/bin/make
3. Call ‘ndk-build’ again.
Administrator ~
$ c:/utils/mingw/bin/mingw32-make.exe –version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This program built for i386-pc-mingw32
October 5th, 2011 at 12:11 pm
can i use this to change an imei?
October 5th, 2011 at 2:17 pm
I don’t think you can.
October 23rd, 2011 at 8:17 pm
In what version of the windows does this work? Works on 7 too?
May 13th, 2012 at 1:40 pm
i am having problem in my cygwin does not appear as here in @echo off instead is appear my laptop name that’s why the command chdir c:\cygwind\bin does not works what should i do to fix this please help me as soon as possible
May 25th, 2012 at 7:40 am
[...] [...]
August 5th, 2012 at 3:27 pm
Thank you Very much
December 7th, 2012 at 1:51 pm
Hi, i am able to build using ndk-build from the project directory using cygwin in Windows 7, after that i refresh my eclipse project and try to run the android app.
Still i am getting a force close with the following exception:
12-07 17:17:23.260: E/AndroidRuntime(713): FATAL EXCEPTION: main
12-07 17:17:23.260: E/AndroidRuntime(713): java.lang.ExceptionInInitializerError
12-07 17:17:23.260: E/AndroidRuntime(713): Caused by: java.lang.UnsatisfiedLinkError: Couldn’t load test-jni: findLibrary returned null
March 14th, 2013 at 4:34 am
Hi,
It’s a good thing I came across this. Thanks for posting. Will I be able to get an idea from this on how I can pair and connect my android phone with a bluetooth mouse? Hope you can advise and guide me.
Thanks and have a nice day.
Joel
May 6th, 2013 at 4:32 pm
hi,
thanks for this tuto,
so i have to change the cygwin.bat forr every project?