Cygwin installation and simple use examples in Android JNI

Source: Internet
Author: User
Tags posix

Cygwin is a UNIX-like simulation environment that runs on the Windows platform and is a free software developed by Cygnussolutions Corporation. Cygwin is a collection of many free software, and the main purpose of Cygwin is to re-compile the software on the POSIX system onto windows. Cygwin includes a library that implements POSIX system invoke APIs on Win32 systems, and a GNU development toolset (such as GCC,GDB) for simple software development and some common programs under UNIX systems. Cygwin does not support Unicode, and in fact does not support other character sets except for the current Windows system and the OEM Codepages,cygwin.

1, download setup-x86_64.exe from http://cygwin.com/install.html;

2, store it in the D:/soft/cygwin folder, run setup-x86_64.exe,-> next->install from the Internet, next->rootdirectory:d:\ Programfiles\cygwin64, Next->local packagedirectory, next->direct Connection, next->http://mirrors.kernel.org , next->develdefault point into devel Install (choose Install as required, also can install all), Next and next (time is longer), complete;

3, verify Cygwin Installation success: Open Cygwin, input related commands such as, gcc-v,make–v;

4. Download the Android NDK from https://developer.android.com/tools/sdk/ndk/index.html and store it in D:\ProgramFiles\Android\ after decompression Under the ANDROID-SDK\ANDROID-NDK-R9;

5. Open the. bash_profile file under the D:\ProgramFiles\cygwin64\home\Spring folder, and at the end of it, add: android_ndk_root=/cygdrive/d/programfiles/ Android/android-sdk/android-ndk-r9

path=/cygdrive/d/programfiles/android/android-sdk/android-ndk-r9:/cygdrive/d/programfiles/android/android-sdk/ android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin:/cygdrive/d/soft/java/eclipse/ Plugins/org.apache.ant_1.8.2.v20110505-1300/bin: $PATH

Export Android_ndk_root PATH

6, open Cygwin, enter the command CD $ANDROID _ndk_root, if the display/CYGDRIVE/D/PROGRAMFILES/ANDROID/ANDROID-SDK/ANDROID-NDK-R9, indicating the success of the configuration;

7, modeled http://blog.csdn.net/fengbingchun/article/details/11580983 a new androidapplication Project:

Mainactivity.java:

Package Com.cygwinjni.android;import Android.os.bundle;import Android.app.activity;import android.view.Menu;import Android.widget.textview;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate);    TextView TV = new TextView (this);      Tv.settext (Stringfromjni ());      Setcontentview (TV);  } Public native String Stringfromjni (); Static{system.loadlibrary ("Hello-jni");}}

ANDROID.MK:

Local_path: = $ (call My-dir) include $ (clear_vars) local_module    : = hello-jnilocal_src_files: = Com_cygwinjni_ Android_mainactivity.cppinclude $ (build_shared_library)

Com_cygwinjni_android_mainactivity.cpp:

#include <string.h> #include <jni.h> #include "com_cygwinjni_android_mainactivity.h" #ifdef __ Cplusplusextern "C" {#endifJNIEXPORT jstring jnicall java_com_cygwinjni_android_mainactivity_stringfromjni  ( JNIENV * env, jobject thiz) {     return Env->newstringutf ("Hello from JNI!");} #ifdef __cplusplus} #endif

The Com_cygwinjni_android_mainactivity.h file is generated by the Javah-classpath command;

8, the Cygwin location to the JNI directory, enter the Ndk-build command, will generate the corresponding. So library.

If there is a write operation, you need to: Open Androidmainfest.xml, select Permissions->add->usespermission->name: Android.permission.WRITE_EXTERNAL_STORAGE.

Cygwin installation and simple use examples in Android JNI

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.