Cygwin installation and simple use examples in Android jni, androidjni
Cygwin is a UNIX-like simulated environment running on windows platforms and a free software developed by cygnussolutions. Cygwin is a collection of many free software. Cygwin aims to re-compile and port the software on the POSIX system to Windows. Cygwin includes a set of libraries that implement POSIX system calling APIs on win32 systems, as well as a set of GNU development tools (such as GCC and GDB ), in this way, you can perform simple software development and some common programs in UNIX systems. Cygwin does not support Unicode. In fact, except for the current windows system and OEM codepages, Cygwin does not support other character sets.
1. Download setup-x86_64.exe from http://cygwin.com/install.html;
2. Save it to the D:/soft/cygwinfolder, run setup-x86_64.exe,-> next-> Install from Internet, next-> RootDirectory: D: \ ProgramFiles \ cygwin64, next-> Local PackageDirectory, next-> Direct Connection, next-> http://mirrors.kernel.org, next-> DevelDefault point to Devel Install (depending on your needs, you can also Install all), next-> next (longer time) -> complete;
3. Verify if Cygwin is successfully installed: Open Cygwin and enter the relevant commands such as gcc-v and make-v;
4. Download Android NDK from https://developer.android.com/tools/sdk/ndk/index.html, decompress it and save it to D: \ ProgramFiles \ android \ Android-sdk \ android-ndk-r9;
5. Open the Directory D: \ ProgramFiles \ cygwin64 \ home \ Spring. bash_profile file, add to its end: 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 and enter the command cd $ ANDROID_NDK_ROOT. If/cygdrive/d/ProgramFiles/Android/android-sdk/android-ndk-r9 is displayed, the configuration is successful;
7. Create an androidapplication Project following http://blog.csdn.net/fengbingchun/article/details/11580983:
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. Locate Cygwin to the jni directory and enter the ndk-build command to 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.
In android, when I use cygwin to compile an opencv program, the following error occurs:
Here, deopencv. mk, you need to see where you put it ,.. /includeOpenCV. mk is the same level of engineering, so you should enter the project rather than jni...
How to call android classes in JNI
You can wrap android classes and methods in custom classes to a layer...