• Android NDK开发二:Android NDK 101


    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

     

     

    Android NDK的结构:

    ndk-build: This shell script is the starting point of the Android NDK build

    system. 

    ndk-gdb: This shell script allows debugging native components using the GNU Debugger. 

    ndk-stack: This shell script helps facilitate analyzing the stack traces that are produced when native components crash. 

    build: This directory contains the modules of the entire Android NDK build system. 

    platforms: This directory contains header files and libraries for each supported Android target version. These files are used automatically by the Android NDK build system based on the specified target version.

    samples: This directory contains sample applications to demonstrate the capabilities provided by the Android NDK. These sample projects are very useful for learning how to use the features provided by the Android NDK.

    sources: This directory contains shared modules that developers can import into their existing Android NDK projects.

    toolchains: This directory contains cross-compilers for different target machine architectures that the Android NDK currently supports. Android NDK currently supports ARM, x86, and MIPS machine architectures. The Android NDK build system uses the cross-compiler based on the selected machine architecture.

     

    从命令行编译Hello-JNI:
    1、cd到Hello-JNI的目录运行:ndk-build

    2、Android SDK build system 基于 Apache ANT,所以要生成Apache ANT build files:

    android update project -p . --target 1

    3、安装:ant debug install

    4、启动Hello-JNI:

    $ adb shell

    # am start -a android.intent.action.MAIN -n com.example.hellojni/

    com.example.hellojni.HelloJni

     

    Android NDK涉及到的tools:

    1、adb shell

    ADB shell is a real Linux shell embedded in ADB client. Although not all standard commands

    are available, classical commands, such as ls, cd, pwd, cat, chmod, ps, and so on are

    executable. A few specific commands are also provided such as:

    logcat To :display device log messages

    dumpsys :To dump system state 

    dmesg: To dump kernel messages 

     

    2、am

    Activity Manager. Command am allows to start Android activities,

    services or sending intents (that is, inter-activity messages) from command line.

     

    3、ant

    a Java-based build automation utility。

    Compile, package, and install the final HelloJni APK (an Android application package). All these steps can be performed in one command, thanks to Ant build automation tool. Among other things, Ant runs javac to compile Java code, AAPT to package the application with its resources, and finally ADB to deploy it on the development device. 

    4、ndk-build

    Build libhello-jni native library with ndk-build, which is a wrapper Bash script around Make. Command ndk-build sets up the compilation toolchain for native C/C++ code and calls automatically GCC version featured with the NDK.

    5、AAPT(Android asset packaging tool)

     

     

    Android NDK Project的目录结构:

    1、jni:

    包含native的源码和Android.mk

     

    2、 libs:

    这个目录在build的时候由 Android NDK build system创建。为不同machine architecture包含不同的独立的子目录例如 ARM的是armeabi

     

     3、obj:

    包含了编译后产生的object files

     

    Android.mk:

     Android.mk 是一个 GNU Makefile 为 Android NDK build system描述了 the NDK project  Android NDK build system.

    LOCAL_PATH := $(call my-dir)//指定native source code的目录,my-dir是当前目录
    include $(CLEAR_VARS)
    LOCAL_MODULE := hello-jni //文件名,将产生一个名为libhello-jni.so的库文件
    
    LOCAL_SRC_FILES := hello-jni.c //指定所有的源码文件
    include $(BUILD_SHARED_LIBRARY)//BUILD_SHARED_LIBRARY指定了 build-shared-library.mk的位置,为了生成动态链接库,静态库可用                                    include $(BUILD_STATIC_LIBRARY)
    
    

     

     

     

     

    tips:

    1、设置Android NDK 的location Eclipse-》Preference-》Android-》NDK-》NDK location

  • 相关阅读:
    js动态获取地址栏后的参数
    html页面保存数的两种方式
    微信开发之八 页面获取周围beacon设备
    【摄影】田子坊
    最好的时光在路上,最美的风景在远方
    【前端统计图】echarts实现简单柱状图
    js实现计时功能
    luogu 电车
    cogs luogu 砍树
    cogs 通往奥格瑞玛的道路 WD
  • 原文地址:https://www.cnblogs.com/shangdahao/p/3053146.html
Copyright © 2020-2023  润新知