Build Android C development environment on eclipse

1. Tools and software to be prepared

  JDK

Invalid Sign

Adt12.0 (of course, the latest ADT is available to avoid too much trouble.)

  Android SDK  

  Android NDK

  Cygwin

2. Environmental construction process

First, install the JDK in the normal way. This part is omitted because there are a large number of online searches.

Decompress the SDK and DNK into a directory. Note that the path should not have Chinese as much as possible. My decompression path is

SDK:D:\android\android-sdk-windows

NDK:D:\android\android-ndk-r6

Install cygwin. Cygwin is a sharp tool for embedded programming under windows. The installation process is as follows (quoted from http://www.2cto.com/kf/201104/87831.html ):

"/ / / reference start

Click the setup.exe program, and a dialog box for selecting the download method will pop up. Because I am used to backing up the installation files to facilitate the installation of the second machine, I chose the second item: "download without installing", as shown in the figure:

After a series of "next steps", a dialog box for selecting the download component is displayed. In order to avoid strange problems in the future, I suggest to choose install all, as shown in the figure:

If you download the whole cygwin by installing, the size is about 1.7g, so it is destined to be a long process. In particular, we can't use our usual download tools, and the server is abroad, which makes it more time-consuming. 4. Install cygwin

Still click setup.exe, but this time we choose "install from local directory", as shown in the figure:

5. Setting environment variables

After installation, in order to compile NDK conveniently, it is better to set corresponding environment variables. Open the home folder under the installation directory of cygwin, and then enter the corresponding user name. If you find. Bash under the user name_ Profile file, then the next step is much simpler. Open the file directly with Notepad, and then add the following text at the end of the file: # create the path of NDK. In windows, my path is D: program files androidndk NDK_ Root = / cygdrive / D / programfiles / Android / NDK # add to the path environment variable export NDK_ After root is saved, open cygwin and enter CD $NDK on the command line_ ROOT。 Note that unlike CMD under windows, it must be case sensitive. If nothing happens, you will enter our NDK installation directory. If the file is not changed in the corresponding user name folder, the problem may not be so simple. If you create a. Bash under this user name_ Profile, and add the corresponding text, and then if everything is normal as mentioned above, Congratulations! But in fact, it is often not so smooth. You will probably find that even if we created the file under the user name, it seems that the environment variable has not been set successfully at all. This is probably because the path of the user name is not set correctly. To check the path, directly enter PWD in cygwin. For example, after I finish installing, enter PWD, and the screen displays:

Next, let's try compiling a program.

First, enter the D: program files androidndk sampleshello JNI path in the cygwin command line interface. If you are not familiar with the command line, you can enter the following command: CD / cygdrive / D / programfiles / Android / NDK / samples / Hello JNI, and then enter "$ndk_root / NDK build" to compile$ NDK_ Root was previously in. Bash_ Profile sets the environment path, and NDK build is the compilation tool that calls NDK. If there is no problem, it will generate a LIBS directory, and all the. So files generated by compilation will be here, as shown in the following figure:

”/////End of reference

At this point, we have completed the configuration of cygwin

Install the SDK. Double click the SDK manager.exe file in the SDK directory. After startup, the SDKs that can be installed will be listed. If you don't want to bother to find out that there are dependencies between them, you can choose to install them all. It just takes a long time. After starting the installation, you can go to bed. Get up in the morning and click OK to complete the installation.

Install eclipse. In fact, you don't need to install it. You can use it by decompressing it directly. After running eclipse, you will find that cygwin's C compiler has been integrated into eclipse on eclipse. So what we need to do now is install ADT.

help--->install new software。 Add ADT 12.0 that we have downloaded in this dialog box. Just go all the way to next. Eclipse will automatically install ADT. After installation, you need to add an SDK path to the SDK. Project--->Properties。 On this page, we select the build option for Android, then add the SDK directory to the text box, and click Apply after completion. Eclipse will parse out all Android versions contained in the SDK.

So far, we have completed the construction of the environment.

2、 Test the environment

The test environment generally uses the samples project brought in the NDK file.

Open SDK manager.exe to create a simulator. The SDK used by the simulator should be consistent with the SDK of the project you develop.

Previously, we have compiled the so file of Hello JNI in NDK. We add an Android project on the eclipse ide. The content of the project refers to the source file of Hello JNI. After the project is created. Add a debug configuration for Android in run - > Run configurations. The project uses the hellojni project folder, and the target uses the simulator created earlier.

Start the simulator in SDK manger.exe and wait until the simulator is fully started. Click the run as button to see the effect of the project on the simulator.

References:

Invalid Sign

Android Developer------- http://developer.android.com/

Eclipse Website --------------------------------------------------- http://www.eclipse.org/

Reproduced at: https://www.cnblogs.com/imagelab/archive/2011/08/17/2141699.html

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>