Android NDK主要组成部分

来源:互联网 发布:iphone纪念日软件 编辑:程序博客网 时间:2024/05/28 15:39

You should have an understanding of the following components as you build your app:

  • ndk-build: The ndk-build script launches the build scripts at the heart of the NDK. Thesescripts:
    • Automatically probe your development system and app project file to determine what to build.
    • Generate binaries.
    • Copy the binaries to your app's project path.

    For more information, seendk-build.

  • Java: From your Java source, the Android build process generates.dex(Dalvik EXecutable) files, which are what the Android OS runs in the Dalvik Virtual Machine(“DVM”). Even if your app contains no Java source code at all, the build process still generates a.dex executable file within which the native component runs.

    When developing Java components, use the native keyword to indicate methods implementedas native code. For example, the following function declaration tells the compiler that theimplementation is in a native library:

    public native int add(int  x, int  y);
  • Native shared libraries: The NDK builds these libraries, or.so files, from your nativesource code.

    Note: If two libraries implement respective methods with the samesignature, a link error occurs. In C, "signature" means method name only. In C++, "signature" meansnot only method name, but also its argument names and types.

  • Native static libraries: The NDK can also build static libraries, or.a files, which youcan link against other libraries.
  • Java Native Interface (JNI): The JNI is the interface via which the Java and C++ componentstalk to one another. This guide assumes knowledge of the JNI; for information about it, consult theJava Native Interface Specification.
  • Application Binary Interface (ABI): The ABI defines exactly how your app's machine code isexpected to interact with the system at runtime. The NDK builds.so files against thesedefinitions. Different ABIs correspond to different architectures: The NDK includes ABI support forARMEABI (default), MIPS, and x86. For more information, seeABI Management.
  • Manifest: If you are writing an app with no Java component to it, you must declare theNativeActivity class in themanifest.Native Activities and Applications provides more detail on how to do this, under“Using the native_activity.h interface.”

The following two items are only required for building using thendk-build script,and for debugging using thendk-gdb script.

  • Android.mk:You must create anAndroid.mk configuration file inside your jni folder. Thendk-buildscript looks at this file, which defines the module and its name, the source files to be compiled,build flags and libraries to link.
  • Application.mk: This fileenumerates and describes the modules that your app requires. This information includes:
    • ABIs used to compile for specific platforms.
    • Toolchains.
    • Standard libraries to include (static and dynamic STLport or default system).


0 0