当前位置: 首页 > news >正文

ndk-build

目录

    • 一、运行ndk
    • 二、Application.mk
    • 三、Android.mk
      • 3.0、模块名定义
      • 3.1、源码
      • 3.2、头文件搜索
      • 3.3、头文件导出
      • 3.4、编译、链接flags配置
      • 3.5、产物类型
    • 四、模块依赖处理
      • 1、源码模块依赖
      • 2、预编译库依赖

一、运行ndk

  • NDK_APPLICATION_MK:指定Application.mk文件所在位置,每个ndk工程都需要有一个Application.mk文件来配置全局的编译信息。
  • -C:编译开始的目录。
ndk-build NDK_DEBUG=1 NDK_PROJECT_PATH=null NDK_APPLICATION_MK=src/main/jni/Application.mk NDK_OUT=build/out NDK_LIBS_OUT=build/react-ndk/all THIRD_PARTY_NDK_DIR=build/third-party-ndk REACT_COMMON_DIR=../ReactCommon REACT_SRC_DIR=$projectDir/src/main/java/com/facebook/react -C src/main/jni/react/jni

二、Application.mk

  • APP_BUILD_SCRIPT:指定编译脚本
  • APP_ABI:指定编译的CPU架构
  • APP_PLATFORM:指定编译目标Android版本号
  • NDK_MODULE_PATH:ndk编译时搜索模块时要查找的目录
  • APP_STL:编译使用的C++标准库
  • APP_CFLAGS:全局的C编译flags
  • APP_CPPFLAGS:全局的C++编译flags
  • APP_LDFLAGS:全局的链接flags
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.APP_BUILD_SCRIPT := Android.mkAPP_ABI := armeabi-v7a x86 arm64-v8a x86_64
APP_PLATFORM := android-16APP_MK_DIR := $(dir $(lastword $(MAKEFILE_LIST)))# What is NDK_MODULE_PATH?
#   This is comparable to the PATH environment variable in Linux. The purpose
#   of NDK_MODULE_PATH is to provide a list of directories that contain modules
#   we want ndk-build to compile.
#
# What is HOST_DIRSEP?
#   In PATH, the directories are separated by a ':'.
#   In NDK_MODULE_PATH, the directories are separated by $(HOST_DIRSEP).
#
# Where are APP_MK_DIR, THIRD_PARTY_NDK_DIR, etc. defined?
#   The directories inside NDK_MODULE_PATH (ex: APP_MK_DIR, THIRD_PARTY_NDK_DIR,
#   etc.) are defined inside build.gradle.
NDK_MODULE_PATH := $(APP_MK_DIR)$(HOST_DIRSEP)$(THIRD_PARTY_NDK_DIR)$(HOST_DIRSEP)$(REACT_COMMON_DIR)$(HOST_DIRSEP)$(APP_MK_DIR)first-party$(HOST_DIRSEP)$(REACT_SRC_DIR)APP_STL := c++_sharedAPP_CFLAGS := -Wall -Werror -fexceptions -frtti -DWITH_INSPECTOR=1
APP_CPPFLAGS := -std=c++1y
# Make sure every shared lib includes a .note.gnu.build-id header
APP_LDFLAGS := -Wl,--build-idNDK_TOOLCHAIN_VERSION := clang

三、Android.mk

3.0、模块名定义

LOCAL_MODULE

3.1、源码

要参与编译的c、cpp文件,以及so、.a文件都可以做为src文件。
LOCAL_SRC_FILES

3.2、头文件搜索

编译源码时什么哪里搜索文件
LOCAL_C_INCLUDES

3.3、头文件导出

导出头文件给其他模块使用
LOCAL_EXPORT_C_INCLUDES

3.4、编译、链接flags配置

LOCAL_CFLAGSLOCAL_CPPFLAGSLOCL_LDFLAGS

3.5、产物类型

  • 可执行文件
    include $(BUILD_EXECUTABLE)
  • 动态库
    include $(BUILD_SHARED_LIBRARY)
  • 静态库
    include $(BUILD_STATIC_LIBRARY)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)# Include . in the header search path for all source files in this module.
LOCAL_C_INCLUDES := $(LOCAL_PATH)# Include ./../../ in the header search path for modules that depend on
# reactnativejni. This will allow external modules to require this module's
# headers using #include <react/jni/<header>.h>, assuming:
#   .     == jni
#   ./../ == react
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../..LOCAL_CFLAGS += -fexceptions -frtti -Wno-unused-lambda-captureLOCAL_LDLIBS += -landroid# The dynamic libraries (.so files) that this module depends on.
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libglog_init libyoga# The static libraries (.a files) that this module depends on.
LOCAL_STATIC_LIBRARIES := libreactnative libcallinvokerholder# Name of this module.
#
# Other modules can depend on this one by adding libreactnativejni to their
# LOCAL_SHARED_LIBRARIES variable.
LOCAL_MODULE := reactnativejni# Compile all local c++ files.
LOCAL_SRC_FILES := $(wildcard *.cpp)ifeq ($(APP_OPTIM),debug)# Keep symbols by overriding the strip command invoked by ndk-build.# Note that this will apply to all shared libraries,# i.e. shared libraries will NOT be stripped# even though we override it in this Android.mkcmd-strip :=
endif# Build the files in this directory as a shared library
include $(BUILD_SHARED_LIBRARY)# Compile the c++ dependencies required for ReactAndroid
#
# How does the import-module function work?
#   For each $(call import-module,<module-dir>), you search the directories in
#   NDK_MODULE_PATH. (This variable is defined in Application.mk). If you find a
#   <module-dir>/Android.mk you in a directory <dir>, you run:
#   include <dir>/<module-dir>/Android.mk
#
# What does it mean to include an Android.mk file?
#   Whenever you encounter an include <dir>/<module-dir>/Android.mk, you
#   tell andorid-ndk to compile the module in <dir>/<module-dir> according
#   to the specification inside <dir>/<module-dir>/Android.mk.
$(call import-module,folly)
$(call import-module,fb)
$(call import-module,fbjni)
$(call import-module,jsc)
$(call import-module,fbgloginit)
$(call import-module,yogajni)
$(call import-module,cxxreact)
$(call import-module,jsi)
$(call import-module,jsiexecutor)
$(call import-module,callinvoker)
$(call import-module,hermes)include $(REACT_SRC_DIR)/turbomodule/core/jni/Android.mk# TODO(ramanpreet):
#   Why doesn't this import-module call generate a jscexecutor.so file?
# $(call import-module,jscexecutor)include $(REACT_SRC_DIR)/jscexecutor/Android.mk
include $(REACT_SRC_DIR)/../hermes/reactexecutor/Android.mk
include $(REACT_SRC_DIR)/../hermes/instrumentation/Android.mk
include $(REACT_SRC_DIR)/modules/blob/jni/Android.mk

四、模块依赖处理

1、源码模块依赖

使用LOCAL_SHARED_LIBRARIESLOCAL_STATIC_LIBRARIES进行依赖,但需要使用以下同种方式中的一种,将依赖的模块添加到当前模块。

  • 使用include xxx/Android.mk方式,直接依赖具体的某个mk文件,如include $(REACT_SRC_DIR)/turbomodule/core/jni/Android.mk
  • 使用import-module方式,通过Application.mk文件中,NDK_MODULE_PATH变量配置的路径进行搜索。如$(call import-module, yoga)

2、预编译库依赖

如果预编译库是系统库,可以直接使用LOCAL_LDLIBS引入。对于非系统库,需要做特殊处理:在ndk编译系统里,非系统预编译库需要使用模块(module)方式封闭起来,再按源码模块依赖方式添加到目标模块为其使用。这样做可以将预编译库,及其相关头文件形成一个整体,简化其他模块的引用。预编译库没有源码,只有编译好的.so或.a文件,封装模块时的LOCL_SRC_FILES直接使用编译好的库文件即可。

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= jsc
LOCAL_SRC_FILES := jni/$(TARGET_ARCH_ABI)/libjsc.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_SHARED_LIBRARY)

相关文章:

  • JS读取目录下的所有图片/require动态加载图片/文字高亮
  • MySQL-连接查询
  • 正则表达式规则以及贪婪匹配与非贪婪匹配详解
  • HTML5的未来:掌握最新技术,打造炫酷网页体验
  • 易灸灸的微商模式,新零售全案运营,裂变营销与代理模式
  • 【LinkedList与链表】
  • 基于单片机的太阳能无线 LED 灯设计
  • 2024FIC决赛
  • web安全渗透测试十大常规项(一):web渗透测试之XML和XXE外部实体注入
  • 赛氪网受邀参加上海闵行区翻译协会年会,共探科技翻译创新之路
  • 什么是DMZ?路由器上如何使用DMZ?
  • LabVIEW开发EOL功能测试系统
  • C# —— switch语句
  • 59.WEB渗透测试-信息收集- 端口、目录扫描、源码泄露(7)
  • 【CS.AL】算法核心之贪心算法:从入门到进阶
  • “大数据应用场景”之隔壁老王(连载四)
  • 3.7、@ResponseBody 和 @RestController
  • Angular数据绑定机制
  • CSS3 聊天气泡框以及 inherit、currentColor 关键字
  • JavaScript 是如何工作的:WebRTC 和对等网络的机制!
  • springMvc学习笔记(2)
  • 编写符合Python风格的对象
  • 分享自己折腾多时的一套 vue 组件 --we-vue
  • 基于 Babel 的 npm 包最小化设置
  • 前端攻城师
  • 设计模式 开闭原则
  • 文本多行溢出显示...之最后一行不到行尾的解决
  • 小而合理的前端理论:rscss和rsjs
  • 【运维趟坑回忆录】vpc迁移 - 吃螃蟹之路
  • const的用法,特别是用在函数前面与后面的区别
  • (done) 两个矩阵 “相似” 是什么意思?
  • (js)循环条件满足时终止循环
  • (Note)C++中的继承方式
  • (Redis使用系列) Springboot 实现Redis 同数据源动态切换db 八
  • (附源码)spring boot校园健康监测管理系统 毕业设计 151047
  • (南京观海微电子)——I3C协议介绍
  • (三)docker:Dockerfile构建容器运行jar包
  • (已解决)什么是vue导航守卫
  • *2 echo、printf、mkdir命令的应用
  • .NET 反射的使用
  • .net 简单实现MD5
  • .net 使用ajax控件后如何调用前端脚本
  • .NET/C# 编译期间能确定的相同字符串,在运行期间是相同的实例
  • .NET/C# 中你可以在代码中写多个 Main 函数,然后按需要随时切换
  • .net后端程序发布到nignx上,通过nginx访问
  • .pyc文件是什么?
  • .vimrc 配置项
  • //解决validator验证插件多个name相同只验证第一的问题
  • @selector(..)警告提示
  • @Transactional 详解
  • [ vulhub漏洞复现篇 ] JBOSS AS 4.x以下反序列化远程代码执行漏洞CVE-2017-7504
  • [1525]字符统计2 (哈希)SDUT
  • [22]. 括号生成
  • [3D游戏开发实践] Cocos Cyberpunk 源码解读-高中低端机性能适配策略
  • [C++][数据结构][算法]单链式结构的深拷贝