Configure the Android NDK environment in Eclipse to compile the. so file with Eclipse

Source: Internet
Author: User

When doing Android NDK development, C code needs to be compiled with Ndk-build, while Java code needs to be compiled with the Android SDK.

There are two methods of compiling C code:

First, write the C code, and then use Cygwin to build ndk-build environment, with Ndk-build to compile the relevant. so file (Libs directory),

Then use eclipse to compile the Java program, thus using the. so file. This method was introduced in the previous article to build the NDK environment.

Second, the use of eclipse can fully achieve the purpose of compiling. So.

First of all, install the CDT, which is the eclipse-C + + environment plug-in, and you can create a C + + project and code file in eclipse. Plug-in installation There are two ways, one is online installation, one is to download the installation package itself, this is only the first way, the other way to Baidu itself. First sign in to Http://www.eclipse.org/cdt/downloads.php, find the online installation address for your Eclipse version of the CDT plugin, as shown in:, locate the online installation address for your Eclipse version of the CDT plugin, as shown in:

2. Find the CDT plugin address that corresponds to your eclipse version, then open Eclipse, click the Help menu, find the Install New software menu, and note that some older versions of the Eclipse menu are different, such as the Europa version, is Help--software Updates-find and Install--search for new features to Install--new Remote Site, in addition to the menu is not the same, the installation method is similar, Can be self-Baidu, the Indigo version shall prevail:

3, the address to fill in, out of the plug-in list, select All, as shown:

Then you can complete the installation with a little bit of madness.

You can also click the Add button to install the offline method. The dialog box appears, click the Archive button, select the offline installation package that you downloaded earlier, and install the installation process with the online installation.

4, after the installation is complete, the Point menu File-new-project, the new project interface appears, if there is a C + + project, then congratulations, the CDT installation has also been completed, as shown in:

5, but the light has CDT still not, CDT compiled code still need to call Cygwin in the compilation tool, so we also need to manually configure the C + + compiler, or with the NDK's own hello-jni as an example, first open eclipse,file->new- >project->android->android Project->next, in the New Android Project tab, select Create Project from existing source At location: Click Browse to find the Hello-jni directory that comes with the NDK.

After selecting the Android SDK version, click Finish to complete the import.

6. Import this project into the import, as shown in the following:

7. Compile C File:

After you right-click Hellojni, click Properties, pop up the configuration screen, and then click Builders, as shown in:

Click the New button, add a compiler, click on the Add screen, select program, click OK:

8, click OK, there is an add interface:

In the Main tab interface, fill in the following:
Name:

compiler name, fill it out. such as: Ndk_builder

Location:

The location of the executable tool. This is the location of the Ndk-build.cmd under the NDK installation directory.

You can click Browser File System ... button to select the Ndk-build.cmd file under the Android NDK installation directory to specify location. Such as:

You can also set a variable to specify the location after the Android NDK installation directory. Click the Variables button to specify. Such as:

The Select Variable selection box appears.

Click Edit Variables ... Button. A variable management interface appears. Click the New button to add variable.

Enter a name for the variable, such as: Ndk_home. Then click Browse ... button, after selecting the Android ndk installation directory, click OK.

At this point, the NDK's variable setup is complete.

Then, click on the variables of location on the Main tab interface ... button to select the Ndk_home variable you just set. Such as:

After clicking OK, there will be a selected Ndk-home variable in the edit box of the location, after which the/ndk-build.cmd,ok,location setting is completed.

Such as:


Working Directory:

The working directory of the C + + program to compile. Typically assigned to the JNI folder, because all C + + programs are implemented within that folder.

First select the browse Workspace in working directory ... buttons, such as:

Then, select the Jni folder for the project Hellojni you want to compile.

9, then switch to the Refresh tab, to refresh resources upon completion, select the project containing the selected resource item,

Indicates that only the item containing the selected resource is updated, and the selected resource item is the JNI folder of main tab selection.

After completion such as:

10. Finally switch to the Build Options tab and tick during auto builds as shown in:

Specify Resources button click, select the Jni folder for the Hellojni project.

11. After clicking Apply OK to confirm the settings, ensure that this NDK builder is set to the first entry in the list by Selecting the Up button until it is at the top of the Builders list

Remember to point the up button, put it first, otherwise C code compiled later than Java code compilation, will cause your C code to compile two times to see the latest changes, after the first position as shown:

12, now again congratulations, compile configuration is also configured to complete, then try to see if you can automatically compile it, open the left Jni directory in the Hello-jni.c file to change the hint Hello from jni!, as shown:

After you click on the project and select Build project, the Libs folder will be out of the HELLOJNI project and the. So file will be stored here.

In addition, the console console outputs the prompt message for successful compilation.

After compiling, click the Run button to run to see if the simulator appears in your new changes to the prompt message, then once again congratulations, has been fully configured successfully!

========================================================================

Android Ndk:your App_build_script points to an unknown file:

My error message is as follows:

Android Ndk:your App_build_script points to an unknown file:d:\android\workspace/jni/android.mk
d:/android/adt-bundle-windows-x86_64-20130917/android-ndk-r9/build/core/add-application.mk:176: * * * Android NDK:  Aborting .... Stop.

Obviously, the path can not find the problem;

As a general rule, because when we add builder, we specify Workdirctory as the path where workspace is located, and Ndk_project_path in environment will default to this value as long as the ndk_project_ is modified. PATH is the item whose value points to a specific workspace;

If this problem can occur, it is recommended to first use the command line to enter CMD, and then use the CD to your Workspace/yourproject, and then run the Ndk-build command, successful will output the following information:

This situation shows that the environment variable configuration of the system is not a problem, but the environment variable configuration of Eclipse, the following:

1. Select the project you want to compile->properties->builders; Select the builder that you configured for NDK, my name is Ndkbuilder; then select, Edit, select Environment to select the tab, add a Ndk_project_path, and the value is the path of PROJECT under your workspace :

Configure the Android NDK environment in Eclipse to compile the. so file with Eclipse

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.