How to build a windows _ ndk Environment

Source: Internet
Author: User

I have been studying androidndk development for several days. I will review how androindk is built in a Windows environment and learn some principles from it:

First, before developing androidndk, we must use the basic software developed by Android (Eclipse, Adt, Android-SDK, and other source code viewing software). On this basis, we also need the following:

1. The latest version of Android-ndk is R7.

2. Download and install cygwin;

Since make and GCC must be used to compile the ndk code, you must first build a Linux environment. cygwin is a UNIX simulation environment running on Windows, it is very useful for learning Unix/Linux operating environments or porting applications from UNIX to Windows. With this feature, you can use ndk to compile C and C ++ code without installing Linux.

Remember that when cygwin is installed, you will be asked to select some required packages for installation. If you select all the required packages, it will take a lot of time. Here we list the packages used for ndk development: autoconf2.1, automake1.10, binutils, GCC-core, GCC-G ++, gcc4-core, gcc4-g ++, GDB, PCRE, PCRE-devel, gawk, make a total of 12 packages;

Test whether cygwin has been installed:

Run cygwin. In the displayed command line window, enter the cygcheck-C cygwin command to print the current cygwin version and running status. If the status is OK, cygwin runs normally.

Input gcc-version, G ++ -- version, make-version, and GDB-version in sequence for testing. If both print the published version and some description information, your cygwin installation is complete!

3. Configure the ndk environment variable, not in windows, but in cygwin.

First, find the installation directory of cygwin and find a home \ <your username> \. bash_profile file. Mine is: e: \ cygwin \ home \ Administrator \. bash_profile, (note: I didn't have any Trojans in my home folder during installation. Solution: First open the environment variable and delete the home variable from the user variable. In E: in the \ cygwin \ home folder, create a folder named "Administrator" (user name), and then set E: \ cygwin \ etc \ skel \. bash_profile ).

Open the bash_profile file and add ndk =/cygdrive/<your drive letter>/<androidndk directory> for example:

Ndk =/cygdrive/e/android-ndk-r5

Export ndk

The ndk name is random. For future convenience, select a short name and save it.

Open cygwin and enter CD $ ndk. If the/cygdrive/e/android-ndk-r5 information configured above is output, the environment variable is set successfully.

4. Use ndk to compile the program

Now let's use the installed ndk to compile a simple program. Let's choose the built-in ndk example hello-JNI, my location is E: \ android-ndk-r5 \ samples \ hello-JNI (depending on your location ),

Run cygwin and enter the command CD/cygdrive/e/android-ndk-r5/samples/Hello-JNI to go to the E: \ android-ndk-r5 \ samples \ hello-JNI directory.

Enter $ ndk/ndk-build. After successful execution, it will automatically generate a libs directory and put the. So file generated by compilation in it. ($ Ndk is used to call the environment variable we configured previously, and ndk-build is used to call the Compilation Program of ndk)

Go to the libs directory of hello-JNI to check whether the. So file is generated. If yes, your ndk will run normally!

5. Integrate the C/C ++ development environment in eclpse

Install the C/C ++ environment plug-in of Eclipse: CDT. Here, install it online.

First, log on to http://www.eclipse.org/cdt/downloads.php and find the on-line installation address of your own cdtplug.

Click the Help menu and find the install new software menu.

Click the Add button and enter the obtained address. After the plug-in list is displayed, select all. Then, select next to complete the installation.

After the installation is complete, right-click a new project in eclispe. If the C/C ++ project appears, your CDT plug-in is successfully installed!

7. Configure the C/C ++ Compiler

Open eclipse, import the hello-JNI example that comes with ndk, right-click the project name, and click Properties to bring up the configuration interface. Then click builders to bring up the compilation tool list of the project, and then click New, add a new compiler. Click the Add interface. Select Program and click OK.

The add interface appears. First, name the compilation configuration, for example, c_builder.

Set location to <your cygwin installation path> \ bin \ bash.exe program, for example, E: \ cygwin \ bin \ bash.exe, and set working directory to the <your cygwin installation path> \ bin directory, example: e: \ cygwin \ bin

Set arguments

-- Login-c "CD/cygdrive/I/javaworkspace/blog/ndk_02 & $ ndk/ndk-build"

In the above configuration,/cygdrive/I/javaworkspace/blog/ndk_02 is the directory of the program to be compiled, and $ ndk is the environment variable of the previously configured ndk, these two parameters are configured based on your specific installation directory. Other parameters do not need to be changed. The parameters of arguments are actually passed to the bash.exe command line program to enter the program directory to be compiled, then run the ndk-build Compilation Program

Switch to the refresh tab and hook refreshresources upon completion.

Switch to the build options tab and check the last three items.

Then click specify resources, select the Resource Directory, and check your project directory.

Finally, click Finish and click OK to save the configuration. Note: If the compiler you configured is under another compiler, remember to set it to the first place by clicking the up button, otherwise, the compilation of C code is later than that of Java code, which may cause your C code to be compiled twice before you can see the latest modification.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.