NDK Technology, Java Project calls C code

Source: Internet
Author: User

Installing Cygwin

Decompression Android-ndk-r5c-windows.zip

Decompression Cygwin Package.rar

Cygwin installation Steps

Run Setup.exe, select the third item to install from the local Cygwin


Set Cygwin to install there


Specify the location of the installation program


Select the installed content, just choose Devel.


Cygwin and NDK integration

You must open the. profile file with EditPlus and never open it with Notepad


Home folder is not empty

D:\ndk\cygwin\home\username\.bash_profile (username is the user name you logged into the computer ) add the following two lines

NDK=/CYGDRIVE/D/ANDROID-NDK-R5C-WINDOWS/ANDROID-NDK-R5C (D is the ndk-sdk After the decompression of the letter, followed by The path where the NDK is located )

Export NDK

Home folder is empty

If the after installation home directory is empty, there is no. bash_profile file, find the. bash_profile file under \cygwin\etc\skel\ to add the following two lines

ndk=/cygdrive/d/android-ndk-r5c-windows/android-ndk-r5c

Export NDK

Then copy to (C:\Documents andsettings\administrator), some Win7 to be copied to C:\Users directory, restart Cygwin can use the

For example: My NDK path is: D:\tarena\1408\program\ndk\android-ndk-r5c-windows\android-ndk-r5c

The

ndk=/cygdrive/d/tarena/1408/program/ndk/android-ndk-r5c-windows/android-ndk-r5c

Test the success of Cygwin integration with NDK

Double-click Run installed Cygwin with Desktop icon and executable file under installation path

$ CD $NDK

The path to the folder where the NDK is displayed indicates that the integration was successful

Writing C code

In Windows Explorer, locate D:\android-ndk-r5c-windows\android-ndk-r5c\samples\hello-jni\jni\hello-jni.c in view hello-jni.c, Modify Code

Generate. So

[Email protected] ~

$ CD $NDK

[Email protected]/cygdrive/d/android-ndk-r5c-windows/android-ndk-r5c

$ CD Samples

[Email Protected]/cygdrive/d/android-ndk-r5c-windows/android-ndk-r5c/sample

S

$ CD Hello-jni

[Email Protected]/cygdrive/d/android-ndk-r5c-windows/android-ndk-r5c/sample

S/hello-jni

$ $NDK/ndk-build

Gdbserver: [Arm-linux-androideabi-4.4.3]libs/armeabi/gdbserver

Gdbsetup:libs/armeabi/gdb.setup

Compile Thumb:hello-jni <= HELLO-JNI.C

Sharedlibrary:libhello-jni.so

install:libhello-jni.so = libs/armeabi/libhello-jni.so

Use. So in Andori

Copy the libs to the root directory of your Android project


Add the following code to the Android class


Advantages of using the NDK

Protect code

Code reuse.

C Fast running speed

Memory can be manually allocated, such as video



NDK Technology, Java Project calls C code

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.