JNI development in Android (I) Development Environment

Source: Internet
Author: User

JNI development environment in Android:

There are about four steps:

1.Install cygwin, install cygwin online, and install cygwin during installation (Note: Do not forget to install make and GCC in addition to common tools );

2.Download the ndk and decompress it directly;

3.Configure the environment --> This is very simple.
Find the cygwin directory, open the home/user/. bash_profile file, and add "ndk =/cygdrive/<your drive letter>/<Android ndk directory>", for example:
Ndk =/cygdrive/e/android-ndk-r5
Export ndk
 

4.Now that the configuration is complete, you can directly compile C/C ++ In the android project by running the "$ ndk/ndk-build" command and compress it into a library. After successful execution, it will automatically generate a libs directory to compile the generated. put the so file in it ..

Note: It must be executed in the root directory of the android project during compilation;

For example: CD $ ndk-enter the root directory of the ndk
CD samples/Hello-JNI/-Enter the directory of the hello-JNI Project
$ Ndk/ndk-Build-compile the project
Find the project directory and find that a libs directory is the compiled result. Open it. If there is a libhello-jni.so, this file will work.


Note: : Some errors may occur in these steps.

1. The following message is displayed during compilation:
Error: you are using a non-cygwin compatible Make program.
This means that the make tool you use is not cygwin. Later, we found that wingw was configured in my environment and was not prompted after the temporary deletion.

2. The following message is displayed during compilation:
Can't open file/cygdrive/D/Android-ndk-k/check-awk.awk
Source line number 1 source file/cygdrive/D/android-ndk-r7/build/awk/check-awk.awk
Context is
>>>< <
Android ndk: Host 'awk' tool is outdated. Please define host_awk to point to gawk or Naw
/Cygdrive/D/android-ndk-r7/build/CORE/init. mk: 258: *** Android ndk: aborting .. Stop
Find the \ ndk directory \ prebuilt \ windows \ bin \ awk.exefolder, delete or rename awk.exe, and compile the file.

3. The following message is displayed during compilation:
Cannot find 'make' program. Please install cygwin make package or define ....
This means that cygwin has not installed the make tool. I used cygwin to install it online again, select the same installation directory, and re-check the make tool. Other tools previously installed will not be deleted.

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.