Android ndk development basics-Environment Setup 1

Source: Internet
Author: User
Document directory
  • 2. Download and install Android ndk
  • 3. Download and install cygwin
  • 4. Configure ndk Environment Variables
  • 5. Use ndk to compile the program
  • 6. Integrate the C/C ++ development environment in eclipse
  • 7. Configure the C/C ++ Compiler

It took almost one day to build this environment ~ It's really not easy!

The detailed steps are as follows:

1. Build an android Development Environment

Setting up the android development environment is not a key point. I believe many people who have read this article have successfully set up the environment. Let's give a brief description here.

<! -- [If! Supportlists] --> 1) <! -- [Endif] --> download JDK

<! -- [If! Supportlists] --> 2) <! -- [Endif] --> download eclipse

<! -- [If! Supportlists] --> 3) <! -- [Endif] --> download Android SDK

<! -- [If! Supportlists] --> 4) <! -- [Endif] --> Start eclipse and install ADT

2. Download and install Android ndk

My ndk version is R5.

The latest ndk output from Google is r7

Http://developer.android.com/sdk/ndk/index.html

 

3. 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. Next we will install cygwin step by step.

(I forgot it during installation)

First, you have to go to the http://www.cygwin.com to download setup.exe

1. Double-click "run". After running, you will see the Installation Wizard interface:

2. click Next.

In this case, select the installation method:

1) install from Internet: Download the package directly from the Internet and install it immediately (after the installation is complete, the downloaded package will not be deleted, but will still be retained so that the package can be installed again next time ).

2) download without installing: Download the installation file to your local computer, but it is not installed yet.

3) install from local directory: without downloading the installation file, install it directly from a local directory containing the installation file.

3. Select the first item and click Next:

4. Select the directory to be installed. Note that it is best not to place it in a directory with Chinese characters and spaces, which may cause installation problems. Other options do not need to be changed. Next, click:

Step 5: select the cygwininstallation directory. This is the directory of the installation package you downloaded. Click Next To Run setup.exe:

6. You have three Connection Methods:

1) Direct Connection: a direct connection.

2) use ie5 settings: Use the connection parameter settings of IE to connect.

3) Use http/FTP Proxy: Use http or FTP Proxy Server for connection (you need to enter the server address and port number ).

You can select based on your network connection. Generally, you can select the first method, that is, direct connection. Then click "Next ",

7, this is the choice to download the site, I use a http://mirrors.kernel.org, the speed is quite fast, after the selection of the next step

8. The installation package list will be downloaded.

9. Search allows you to enter the name of the package you want to download and quickly filter out the package you want to download. The four single-choice buttons select the style of the bottom tree. By default, they do not need to be moved. The default value of view is category. We recommend that you change it to "full" to show all packages and check them again. Save some of the packages to be hidden. The check box in the lower-left corner shows whether to hide the expired package. By default, you just need to check it. Download the package we want to install below to avoid downloading it all, the following packages used for ndk development are listed: autoconf2.1, automake1.10, binutils, GCC-core, GCC-G ++, gcc4-core, gcc4-g ++, GDB, PCRE, PCRE-devel, gawk, make a total of 12 packages

10. Choose to install these packages, click skip, and convert it to the digital version format. Make sure that the bin item is converted to the cross sign, and the SRC item is the source code. This is unnecessary.

11. 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-V, G ++-V, make-V, and GDB-V in sequence for testing. If both of them print the published information and some description information, I am very happy to tell you, your cygwin installation is complete!

4. Configure ndk Environment Variables

In order to keep everyone away from me

Note: It is recommended that you do not use NotePad to open the. bash_profile file. When you use ultraedit to open the file, a message is displayed, "Do you want to convert C: \ cygwin \ home \ Administrator \. bash_profile to DOS format ?"Haha !! Do not click here. Otherwise, the encoding format will be changed. When running ndk with cygwin, the following error will be displayed:

"-Bash: $ '\ R': Command not found
-Bash: $ '\ R': Command not found
-Bash: $ '\ R': Command not found
-Bash:/home/Lenovo/. bash_profile: line 47: syntax error: unexpected end of File
"If this is the case, solution: In cygwin, the ETC \ skel and etc \ defaolts \ etc \ skel have this file, and copy it again, the one you modified. bash_profile content copy overwrites the content of this file, and then copies it to c: \ cygwin \ home \ administrator, and then runs it.

1. 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 ).

2. Open the bash_profile file and add ndk =/cygdrive/<your drive letter>/<Android ndk 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.

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

5. Use ndk to compile the program

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

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

3. Enter $ ndk/ndk-build. After successful execution, it will automatically generate a libs directory and put the compiled. So file 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)

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

6. Integrate the C/C ++ development environment in eclipse

NOTE: If your eclipse is of that version, you can select the corresponding CDT. If you select a different version, you have to make an error ~! My version is Helios Service Release 2, so select the version below CDT 7.0.2 for eclipse Helios.

1. 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.

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

3. 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.

4. 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

1. 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, and then click builders to bring up the compilation tool list of the project, click new to add a new compiler. The add page is displayed. Select Program and click OK.

2. 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"

Note: javaworkspace/blog/ndk_02 is the project directory and name. Every time we run a new ndk, we have to set it to the corresponding project directory. The younger brother does not know whether the settings are correct. He can only use this dumbest method. If a friend knows how to set this value dynamically, leave a message to me. Thank you.

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

3. Switch to the refresh tab and hook refresh resources upon completion

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

5. Click specify resources, select the Resource Directory, and select your project directory.

6. 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.

7. You must be tired after this process. Congratulations again, the compilation configuration is complete. Now, let's test whether automatic compilation can be performed, open the hello-jni.c file in the project JNI directory and prompt hello from JNI! Change it to another text, such as hello, my name is Alex., and then run your program in the simulator. If the simulator displays your latest modified text, then congratulations! You have all configured successfully!

Reference: http://www.cnblogs.com/luxiaofeng54/archive/2012/03/13/2136982.html

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.