Android development environment Build record 201408

Source: Internet
Author: User

The goal is to use the Android + NDK (JNI) to compile a library of OPENCV related functions using C/S + + compilation.

The default JDK is already installed, Java_home, CLASSPATH, and path is set. There are two types of IDE developed by Android, Eclipse and Android Studio (http://developer.android.com/sdk/installing/studio.html), which uses gradle tools that don't know about it and don't try it for the time being.

1. Eclipse CDT + Cygwin environment

Eclipse-C + + development environment, you can choose to download the Eclipse CDT version, or the Eclipse + CDT plugin.

A compilation toolset/Toolchain is also required, either directly using Visual C + + command-line tools cl.exe, etc., or using the GNU compiler tool Cygwin or MinGW under Windows. The difference between the two is that MinGW uses the Win32 API directly, and Cygwin needs to rely on a separate DLL for translation, each with its pros and cons.

Here choose Cygwin64, installation of mirror select Edu site, generally have IPV6 address, so much faster. The following tutorial is very good:

Cygwin & MinGW (for Windows) how to Install and Get Started

It is important to note that the Devel (development) directory of GCC, g++, GDB, make, four are not in the default option when downloading. In addition, after the compiler encountered a problem, but also choose to install a few of the MinGW compiler tools.

There are several places in the Eclipse C/s + + project properties where you can set compiled environment variable Include/library/path and so on, and these are not dependent on the system environment variable settings. This means that if you do not compile with the command line frequently, you can set the system environment variable.

    • The first is the choice of toolchain. If you do not have the Microsoft Visual C + + option, you will need to install the CDT Visual C + + support plugin.

There are two ways to install this plugin, the first one via Eclispe help, install New software-Juno-http://download.eclipse.org/releases/juno Pro gramming Languages->CDT Visual C + + support.

The second is now the official eclipse of the CDT plugin package, which contains the plugin, in fact, Org.eclipse.cdt.msw.build_1.0.0.201406111759.jar and so on.

    • It is important to note that the Discovery options option is checked automate Discovery of paths and symbols by default. This feature automatically sets the relevant environment variables when you select different toolchain on the tool Chain Eidtor page. This feature simplifies the setting of environment variables and is useful. Also, be aware that different configurations (debug/release) Use separate settings, including Toolchain.

    • The first one is C + + Build, envrironment. Different toolchain environment can be set manually.

    • The second is C + + Build, Settings

    • The third place is Paths and Symbols

Note that if you include a space in the path, you should enclose it in double quotation marks, or you may get an error (like program errors).

    • VC + + 2010 environment variable Settings/MSVC setting

Include=
C:\Program Files (x86) \microsoft Visual Studio 10.0\vc\include
C:\Program Files (x86) \microsoft Sdks\windows\v7.0a\include

Lib/libpath =
C:\Program files (x86) \microsoft Visual Studio 10.0\vc\lib or C:\Program Files (x86) \microsoft Visual Studio 10.0\vc\lib\a Md64
C:\Program files (x86) \microsoft Sdks\windows\v7.0a\lib or C:\Program Files (x86) \microsoft Sdks\windows\v7.0a\lib\x64

Path=

C:\Program files (x86) \microsoft Visual Studio 10.0\vc\bin or C:\Program Files (x86) \microsoft Visual Studio 10.0\vc\bin\a Md64

C:\Program Files (x86) \microsoft Visual Studio 10.0\Common7\IDE

A path mapping problem at debug time, this problem causes debug to fail to find the source file, thus debug fails

ECLIPSE+CYGWIN+CDT Building A/C + + development environment

2. JNI-related

Java docs has a Java Native Interface specification, you can learn about. JNI is a two-way interface, and Java calls C + + programs to run Java code by creating JVM instances through JNI.

JNI main or C, C + + is only on the basis of C language characteristics of the packaging. JNI is implemented within the JVM.

The most troublesome part of JNI programming lies in the correspondence and transformations of Java and C + + data types, such as Java.lang.string-jstring-char.

Learn the following tutorial, very long.

Java programming Tutorial Java Native Interface (JNI)

    • The output order of the Java/c++ code is garbled (manually calling Fflush (stdout) after printf, the C language problem)
    • Jni.h's Location:%java_home%\include
    • Gcc-4 No compile option Mno-cygwin workaround

Error hints suggest using the MINGW compilation tool--yes, only this method. Use Cygwin to download and install X86_64-W64-MINGW32-GCC, x86_64-w64-mingw32-g++, etc.

Compile command makefile:

Java_home = C:\Java\jdk1.7. 0_51all:hello.dll MYJNI.DLLHELLO.DLL:HELLOJNI.O x86_64-w64-mingw32-GCC-WL,--add-stdcall-alias-shared-o [email protected] $<hellojni.o:hellojni.c com_zzfei_test_hellojni.h x86_64-w64-mingw32-GCC-D __int64="Long Long"-I."$ (java_home) \include"-I."$ (java_home) \include\win32"-O [email protected]-C $<myjni.dll:myjni.o# x86_64-w64-mingw32-g++-wl,--add-stdcall-alias-shared-static-libstdc++-static-libgcc-o [email protected] $<x86_64-w64-mingw32-g++-wl,--add-stdcall-alias-shared-o [email protected] $<Myjni.o:myjni.CPPcom_zzfei_test_myjni.h x86_64-w64-mingw32-g++-D __int64="Long Long"-I."$ (java_home) \include"-I."$ (java_home) \include\win32"-O [email protected]-C $<Clean :RMhello.dll hellojni.o Myjni.dll myjni.o# Visual C++Compile command#-LD Create. dll#-MD link with MSVCRT. lib#-fe<file> Name Executablefile#cl Myjni.CPP-I."%java_home%\include"-I."%java_home%\include\win32"-FEMYJNI.DLL-MD-LD#CL hellojni.c-I."%java_home%\include"-I."%java_home%\include\win32"-fehello.dll-md-ld

Makefile related rules: GCC and make compiling, linking and Building C + + Applications

The last two lines of comments are compiled with VC + + 2010 command, in the Start menu select Visual Studio x64 Win64 command prompt into the command line can be automatically set environment variables.

    • Add the Javah tool button in eclipse

The parameters are as follows

-v-classpath "${project_loc}/bin"-D "${project_loc}/jni"-jni ${java_type_name}

Some errors can be added by forcing type conversions.

3. Android Development environment

Android SDK Components

SDK Tools
Http://developer.android.com/tools/sdk/tools-notes.html

Platform Tools
Http://developer.android.com/tools/help/index.html

ADT Plugin (including Ndk Plugin, CDT)?
Http://developer.android.com/tools/sdk/eclipse-adt.html
Http://developer.android.com/tools/help/adt.html

Build Tools
Http://developer.android.com/tools/revisions/build-tools.html

Ndk

Starting with R7, Google has provided a ndk-build script that can be compiled directly without the need to use Cygwin.

The eclipse in ADT Bundle:adt-bundle-windows-x86_64-20140702.zip does not have the NDK path option set, the workaround:

Download the separate ADT Plugin plugin adt-23.0.2.zip and install it, or copy the Com.android.ide.eclipse.ndk_23.0.2.1259578.jar (NDK plugin) to eclipse\ Plugins folder.

4. QQQ

    • ABI (Application Binary Interface)
    • Modified UTF-8 and JNI Chinese code
    • (*env), env->
    • DLL size MINGW CL & DLL related (EXPORT ...)
    • PE, Elf
    • X86 calling convention
    • C-Language function entry main
    • The relationship between NDK and JNI
    • Android Architecture & App Workflow
    • ...

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.