Android development Environment Step, ADT, JDK, SDK, NDK, Eclipse, CDT

Source: Internet
Author: User
Tags unpack

The following information, only to prepare for forgetting.

Here are the process records that I configured to install the Android environment.

1. First you need to install JDK with Java Runtime environment

2. Then install Eclipse, which is the tool used to write code, similar to VS, or Xcode,

3. After installing eclipse, download ADT Online to make it easy for Eclipse to write a control that is prepared by the Android program, download it, unpack it, and then place it under the installation generated folder in Eclipse. (you will usually be prompted to replace the file, select Yes). There is also a way to configure ADT, in Eclipse-->help-->install New software ... It is also possible to enter the installation address of ADT in the

4. Download the Android SDK online and unpack it after downloading. Start Eclipse-->windows-->preferences below the Android item on the left, select it, and then select the path to the SDK location in the right-hand interface.

5. After installing the Android SDK, restart Eclipse, then under the Eclipse-->windows-->android SDK and AVD Manager, go to create a new AVD and start it, if it starts successfully, Indicates that the Android SDK is already installed.

Then create a new Andriod project and run it to see if it works. If it works, the environment is already configured.

If not, then see the information on the Internet, and some say you also need to configure the path in the "My Computer" attribute of the environment variables, please check the information on the Internet.

Let's talk about the NDK,

Because Android runs a variety of phone configurations, running some programs on a low-profile phone may not work because the configuration is too low. Because Android uses Java programming, is a virtual machine mechanism, so its operational efficiency will be very influential, usually better, if you encounter brush screen or manipulate the network layer of data, and data exchange frequently, it is recommended to use the bottom C or C + + to complete the time-consuming action. So this involves the mutual invocation of Java and C.

Java is a DLL, or EXE code or library file, that cannot be called directly by C. You need to use an intermediate conversion to the NDK. NDK installation Please refer to my reprint of another article, I am referring to that article configured the NDK.

1. After the NDK is installed, copy the. c file, create a new JNI folder, and place the. c file under this folder.

2. Start the Cygwin program, and then CD to this Jni folder, enter the command $ndk/ndk-build command, after the command succeeds, will generate a Libs folder, and put the resulting so file inside. This Libs folder is added to the program and is in the same class as JNI.

3. Call this. c function in the. Java code. If used: _textview.settext (Stringfromjni ()); You can use it. This completes the call. C code in Java.

But in eclipse, this. C file is in an unrecognized state because there is no environment plugin installed for C/s + +: CDT, as I reprinted in another article about how the NDK article mentions, after installing this CDT, once again open eclipse can be seen, this. c file is available and viewable and can be modified. However, if you want to recompile the. c File after you modify it, you need to regenerate the. So file with the NDK command, and then make the call in your code.

Note the name of the function in this. c file, such as: Java_com_example_hellojni_hellojni_stringfromjni ();

Where: Java is required in the front, followed by the use of this method of the package name Com.example.hellojni; then the current project name Hellojni, then the specific function name. Call this method in Android using Stringfromjni () to make the call.

Construction of the NDK development environment under Windows (CYGWIN+ANDROID-SDK+NDK)

One: What is the NDK?

The NDK provides a range of tools to help developers quickly develop C (or C + +) dynamic libraries and automatically package so and Java applications together as APK. These tools are great for developers.

The NDK integrates the cross compiler and provides the corresponding MK file isolation CPU, platform, ABI and other differences, developers simply need to modify the Mk file (stating "which files need to compile", "compilation characteristics Requirements", etc.), you can create a so. The NDK can automatically package so with Java applications, greatly reducing the developer's packaging effort. To put it simply, the NDK is a cross-compilation tool that can help you compile your code in C or C + + into. So (similar to the. dll) format, which allows you to invoke the code in the Java language (JNI) in your Android program.

II: Download and install Cygwin

Since the NDK compiles code with make and GCC, you must first build a Linux environment, Cygwin is a UNIX simulation environment running on the Windows platform, for learning unix/linux operating environment, or porting applications from UNIX to Windows is useful. With it, you can use the NDK to compile C, C + + code without installing Linux. Let's install Cygwin step-by-step.

(Forgotten when installing)

First of all, you have to run to http://www.cygwin.com to download setup.exe (I have downloaded)

1. Then double-click Run, and after running you will see the Installation Wizard interface:

2. Click Next

At this point you choose how to install:

1) Install from the Internet: downloaded directly from the Internet and installed immediately (after the installation is complete, the download of the installation files is not deleted, but is still retained for the next installation). (long time, it should be this)

2) Download without installing: Just download the installation file locally, but not install it temporarily.

3) Install from the local directory: Do not download the installation files, directly from a locally containing the installation files to be installed.

3. Select the first item and click Next:

4, select the directory to install, note, it is best not to put in Chinese and white space in the directory, it seems to cause installation problems, other options do not change, then click Next:

5, the previous step is to choose to install Cygwin directory, this is to choose the directory where you download the installation package, the default is that you run the Setup.exe directory, directly click the next step:

6, at this time you have a total of three connection options:

1) Direct Connection: Connect directly.

2) Use IE5 Settings: Connect using IE's connection parameter settings.

3) Use HTTP/FTP Proxy: Connect using HTTP or FTP Proxy server (you need to enter the server address, port number).

Users can choose according to their own network connection situation, under normal circumstances, the choice of the first, that is, the direct connection method. Then click "Next",

7, this is the choice to download the site, I use the http://mirrors.kernel.org, the speed feeling is quite fast, select the next point (http://mirror.lupaworld.com/cygwin/This is my address from this, It seems to be a domestic server, very fast, with other, some 2k/s, and Ann several times, a quick good, the server off, embarrassed ...)

8. Download the list of load installation packages at this time

9, search is able to enter the name of the package you want to download, you can quickly filter out the package you want to download. The four radio buttons are the style of selecting the tree below, and by default it's OK to move. View default is category, suggest change to full show all package again check, some of the province's packages are hidden away. The bottom left corner of the check box is whether to hide the expired package, the default tick, do not care it on the line, the bottom to download the package we want to install, in order to avoid all download, here are listed below the development of the NDK needed package: autoconf2.1, automake1.10, Binutils, Gcc-core, gcc-, g++, Gcc4-core, gcc4-g++, GDB, Pcre, Pcre-devel, gawk, make (rather than choose more than a few) a total of 12 packages.

10, then start to choose to install these packages, point skip, turn it into a digital version format, to ensure that the bin item into a fork, and the SRC item is the source code, this is not necessary to choose.

11, the following test Cygwin is not already installed.

Run Cygwin, in the popup command line window input: Cygcheck-c Cygwin command, will print out the current Cygwin version and running state, if the status is OK, then Cygwin run normally.

Then enter gcc–v,g++--version,make–version,gdb–version to test, (note the space and-) if you print out the version information and some descriptive information, very happy to tell you that your Cygwin installation is complete!

Three: Configure NDK environment variables

1, first find Cygwin installation directory, find a home\< your user name >\.bash_profile file, my is: E:\cygwin\home\Administrator\.bash_profile, ( Note: When I installed my home folder under the god horse do not have, the solution: first open the environment variable, the inside of the user variable to delete the home variable, in the E:\cygwin\home folder to create a folder named Administrator (is the user name), Then copy the E:\cygwin\etc\skel\.bash_profile to the folder).

2. Open the Bash_profile file, 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 the convenience of later use, choose a short name, and then save

3, open Cygwin, enter the CD $NDK, if the output of the/CYGDRIVE/E/ANDROID-NDK-R5 information configured above, it indicates that the environment variable setting is successful.

Four: Using the NDK to compile the program

1, now we use the installed NDK to compile a simple program, we choose the NDK's own example Hello-jni, I am located in E:\android-ndk-r5\samples\hello-jni (depending on your specific installation location),

2, run Cygwin, enter the command Cd/cygdrive/e/android-ndk-r5/samples/hello-jni, enter into the E:\android-ndk-r5\samples\hello-jni directory.

3, input $ndk/ndk-build, after successful execution, it will automatically generate a libs directory, the compiled generated. so file inside. ($NDK is to invoke the environment variables we configured earlier, Ndk-build is the compiler that calls the NDK)

4, at this time to hello-jni the Libs directory to see if there are no generated. So files, if any, your NDK is functioning properly!

After the build, you can then use the NDK samples inside the example to generate Eclipse project.

As below, select New Android Project and then as:

Then you can experiment with a few other examples. I'm still in the study, and we're going to refuel together!!!

V: integrated C/D + + development environment in eclipse

(This is like in the domestic tragedy Ah, do not move ah, in the transmission of two fan wall software)

1, install the eclipse of A/C + + Environment plug-in: CDT, here choose Online Installation.

First sign in to http://www.eclipse.org/cdt/downloads.php to find the online installation address for your Eclipse version of the CDT plugin.

2. Then click the Help menu to find the Install New software menu

3, click the Add button, the address to fill in, out of the plug-in list, select All, and then choose the next step to complete the installation

4, after the installation is complete, right click on the new project in Eclispe, if a C + + project appears, then your CDT plugin installed successfully!

VI: Configure the compiler for C + +

(It is recommended to use the command line to compile, and then study the Google NDK samples inside the example, and then study the Fool-style compilation)

1. Open Eclipse, import the NDK Hello-jni example, right-click on the project name, click Properties, pop up the configuration interface, then click Builders, pop Up the project's compilation tool list, then click New, add a compiler, Click on the Add interface, select program, click OK

2, there has been added interface, first to compile a name for the configuration, such as: C_builder

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

Set arguments to

--login-c "Cd/cygdrive/e/android-ndk-r5/samples/hello-jni && $NDK/ndk-build" (Cannot change the,--login–c is God horse meaning I do not understand)

In the above configuration,/cygdrive/e/android-ndk-r5/samples/hello-jni is the directory of the program you are currently compiling, $NDK is the environment variable of the NDK that was previously configured, the two are configured according to your specific installation directory, the other does not change, Arguments this string of parameters is actually to bash.exe command-line program parameters, enter the program directory to be compiled, and then run the Ndk-build compiler program

3. Then switch to the Refresh tab and give the refresh resources upon completion the bait.

4. Then switch to the Build Options tab and tick the last three items

5, then click the Specify Resources button, select the Resource directory, tick your project directory to

6, finally click Finish, click OK all the way to save the configuration just now, note: If you configure the compiler under other compilers, remember to point up the button to the first, or C code is compiled later than the compilation of Java code, Will cause your C code to compile two times to see the latest changes

7, this all the way down must be very tired, now again congratulate you, compile configuration is also configured to complete, now to test whether you can automatically compile it, open the project JNI directory in the Hello-jni.c file to the hint Hello from jni! to other text: such as: Hello,my Name is Alex, and then run your program in the emulator, if the emulator shows you the latest modified text, then congratulations! You have all the configuration success!

This article turns from: Jacky Shin's Column http://blog.csdn.net/smking/article/details/7594019

Android development Environment Step, ADT, JDK, SDK, NDK, Eclipse, CDT

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.