ndk-build

news/2024/7/2 23:50:38

目录

    • 一、运行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.mk

APP_ABI := armeabi-v7a x86 arm64-v8a x86_64
APP_PLATFORM := android-16

APP_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++_shared

APP_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-id

NDK_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-capture

LOCAL_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.mk
  cmd-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)

http://lihuaxi.xjx100.cn/news/2215480.html

相关文章

QUIC 和 TCP: 深入解析为什么 QUIC 更胜一筹

引言 在过去的三十年里&#xff0c;HTTP&#xff08;超文本传输协议&#xff09;一直是互联网的支柱。我们可以通过 HTTP 浏览网页、下载文件、流式传输电影等。这一协议随着时间的推移已经得到了重大改进。 HTTP 协议是一个应用层协议&#xff0c;它基于 TCP&#xff08;传输…

我主编的电子技术实验手册(07)——串联电路

本专栏是笔者主编教材&#xff08;图0所示&#xff09;的电子版&#xff0c;依托简易的元器件和仪表安排了30多个实验&#xff0c;主要面向经费不太充足的中高职院校。每个实验都安排了必不可少的【预习知识】&#xff0c;精心设计的【实验步骤】&#xff0c;全面丰富的【思考习…

如何实现TA Encrypted的?

我们先进行一些思考&#xff1a; TA encrypted是什么意思&#xff1f;加密是什么意思&#xff1f;仅仅是把TA明文变成TA密文吗&#xff1f;不同的机器&#xff0c;加密的密钥都是一样的吗&#xff1f;可以做到一机一密吗编译阶段就要对TA Biarny进行加密了&#xff0c;TA被加载…

星期六-本周的学习内容全面复习和总结!

本周共学习以下的基础内容&#xff1a; 样本空间和事件的集合表示&#xff1b; 数列极限的定义 随机事件的概率 对于本周的学习内容进行全面复习和总结是一个重要的学习过程&#xff0c;这有助于巩固记忆和提高理解能力。以下是一些步骤和建议&#xff1a; 收集资料&#x…

Non-zero exit code pycharm

目录 windows 设置conda代理&#xff1a; linux Conda 使用代理 4. 修改 Conda SSL 验证 pycharm 报错 exceted command pip 设置代理 Non-zero exit code 科学上网后&#xff0c;pip安装时警告报错 WARNING: Retrying (Retry(total0, connectNone, readNone, redirectNo…

使用Selenium进行Web自动化:详细操作指南

使用Selenium进行Web自动化:详细操作指南 引言 Selenium是一个广泛使用的开源工具,用于自动化Web浏览器的操作。无论你是进行自动化测试,还是需要抓取网页数据,Selenium都是一个非常有用的工具。本文将详细介绍Selenium的一些常见用法,包括输入框设置值、文件上传、单选…

运算符分为哪几类?哪些运算符常用作判断?简述运算符的优先级

运算符包含6大类&#xff1a;算术运算符、赋值运算符、比较运算符、逻辑运算符、位运算符、三元&#xff08;目&#xff09;运算符。 逻辑运算符常用作布尔判断 typeof 运算符: typeof 运算符用于确定变量或表达式的数据类型&#xff0c;并返回一个表示类型的字符串。 typeof …

今日的英语行程安排和学习

让我想一想&#xff0c;现在开始复盘自己要开始做的事情: (01)解决自己的问题 (a).中文的语言结构和英文的语言结构有什么不同? (b).为什么恐惧心理会没办法能够让你好好学习? (c).为什么上课的时候会走神? (b).自己听完了一节课&#xff0c;感觉自己获取的知识十分有限…