zoukankan      html  css  js  c++  java
  • 1#底层开发基础(3)---NDK提供的组件

    1. The Android NDK is not a single tool; it is a comprehensive set of APIs, cross-compilers, linkers, debuggers, build tools, documentation, and sample applications. The following are some of the key components of Android NDK:
      • ARM, x86, and MIPS cross-compilers
      • Build system
      • Java Native Interface headers 
      • C library
      • Math library 
      • POSIX threads 
      • Minimal C++ library 
      • ZLib compression library 
      • Dynamic linker library 
      • Android logging library 
      • Android pixel buffer library 
      • Android native application APIs
      • OpenGL ES 3D graphics library 
      • OpenSL ES native audio library 
      • OpenMAX AL minimal support

    1.  Build system
      • The primary goal of this build system is to allow developers to only write very short build files to describe their native Android applications; the build system handles many details including the toolchain, platform, CPU,and ABI specifics on behalf of the developer。
      • the Android NDK build system relies on two other files that are expected to be provided by the developer as a part of the NDK project: Android.mk and Application.mk
    2. Android.mk---a makefile用来将本NDK 工程“描述”到Android NDK build system。该文件是由developer提供的,放在工程的jni目录下,Android NDK build system只会从该目录下寻找该文件。
      • build a shared library
        #let android build system to locate the source file;
        #call my-dir是通过调用MACRO来动态获取路径,而不是通过写死(hard-coded)
        LOCAL_PATH := $(call my-dir) 
         
        #删除文件,避免冲突
        include $(CLEAR_VARS)
        #指定生成module的名字,如hello-jni.so
        LOCAL_MODULE    := hello-jni
         
        #指定要生成module而需要进行build的源文件
        #这里只需要一个源文件,当需要多个源文件时,各个文件之间用空格隔开
        LOCAL_SRC_FILES := hello-jni.c
         
        #UILD_SHARED_LIBRARYvariable is set by the Android NDK build system to the location of build-shared-library.mkfile
        include $(BUILD_SHARED_LIBRARY)
      • build multiple shared library
        LOCAL_PATH := $(call my-dir)
        #
        # Module 1
        #
        include $(CLEAR_VARS)
        LOCAL_MODULE := module1
        LOCAL_SRC_FILES := module1.c
        include $(BUILD_SHARED_LIBRARY)
        #
        # Module 2
        #
        include $(CLEAR_VARS)
        LOCAL_MODULE := module2
        LOCAL_SRC_FILES := module2.c
        include $(BUILD_SHARED_LIBRARY)
      • build static library--->Static libraries can be used to build shared libraries. For example, when integrating third party code into an existing native project, instead of including the source code directly, the third party code can be compiled as a static library and then combined into the shared library.
        LOCAL_PATH := $(call my-dir)
        #
        # the 3rd party AVI library
        #
        include $(CLEAR_VARS)
        LOCAL_MODULE := avilib
        LOCAL_SRC_FILES := avilib.c platform_posix.c
        include $(BUILD_STATIC_LIBRARY)
        #
        # Native module
        #
        include $(CLEAR_VARS)
        LOCAL_MODULE := module
        LOCAL_SRC_FILES := module.c
        LOCAL_STATIC_LIBRARIES := avilib
        include $(BUILD_SHARED_LIBRARY)
      •  
    3. Application.mk--->一个可选的makefile,位于jni目录下,用来描述 一个application需要使用哪些modules


        nkd-build script--->位于android ndk安装路径下,但执行时要切换到所要编译的project根目录下。该脚本通过传入一些参数来控制盒维护编译过程。
    1. 常用参数或命令
      • -C :默认情况下,ndk-build script要在project根目录下执行,但可以通过使用“-C”选项,显示地指定NDK project的路径
      • -B :unconditionally make all targets 无条件地编译所有目标,无论是否有源文件被修改
      • -j    :nkd-build是调用make进行build,默认情况下make一次只执行一条命令,在带-j选项时,make可以并行处理多条指令(应该是利用了cpu多核的特性吧)
      • ndk-build clean : 删除build过程中生成的二进制文件。
    2.    
     
     




  • 相关阅读:
    JAVA学习每日日报 7.6
    【刷题-LeetCode】203. Remove Linked List Elements
    【机器学习】树模型
    【刷题-LeetCode】202. Happy Number
    【刷题-LeetCode】201 Bitwise AND of Numbers Range
    【刷题-LeetCode】200 Number of Islands
    【刷题-LeetCode】199 Binary Tree Right Side View
    【刷题-LeetCode】198 House Robber
    从零学python——python的数据类型介绍
    从零学python——python的基本图形绘制以及基本语法
  • 原文地址:https://www.cnblogs.com/wxyllz/p/3377991.html
Copyright © 2011-2022 走看看