Unsupported Downloads · android/ndk Wiki · GitHub
window 10 下安装 Ubuntu 22.04 使用 NDK r24 编译FFmpeg 5.1 - 简书 (jianshu.com)
下载完ndk r24后,编写build.sh,执行
#!/bin/bash
BASEPATH=../
NDKPATH=/home/sunsy/ndk/android-ndk-r24
#NDKPATH=/d/androidsdk/ndk/21.0.6113669/
CMAKEPATH=/usr/bin
#CMAKEPATH=/d/androidsdk/cmake/3.22.1/bin
PLATFORM=arm64-v8a
#BUILDTYPE=Debug
# -DCMAKE_BUILD_TYPE=${BUILDTYPE} \
${CMAKEPATH}/cmake \
-DCMAKE_TOOLCHAIN_FILE=${NDKPATH}/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=${PLATFORM} \
-DANDROID_NDK=${NDKPATH} \
-DANDROID_NATIVE_API_LEVEL=31 \
-DANDROID_PLATFORM=android-31 \
-DANDROID_STL=c++_shared \
-DNDK_PATH=${NDKPATH} \
-DANDROID_TOOLCHAIN=clang \
-DCMAKE_INSTALL_PREFIX=${BASEPATH}/out/ \
${BASEPATH}
#make
#make VERBOSE=1
#make install
然后,make 编译出来的就是arm 可执行程序.
参考链接
MSM8916 海信M9模块学习记录四:ubuntu16.04 64位下配置NDK-r16b_tudouniS的博客-CSDN博客
(676条消息) android .vsh文件是什么,在Android9下用ndk编译vSomeIP和CommonAPI以及使用例子_小小牵牛星的博客-CSDN博客
官网下载ndkr16b
Unsupported Downloads · android/ndk Wiki · GitHub
解压完以后放到/opt目录下
vim /etc/profile
export NDK_HOME=/opt/android-ndk-r16b #(就是解压出来之后的文件夹路径,这里是要改的)
export PATH=$PATH:$NDK_HOME
source /etc/profile
ndk-build -v
https://www.cnblogs.com/guanglun/p/9340079.html
export PATH=/opt/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH
arm-linux-androideabi-gcc -pie -fPIE --sysroot=/home/guanglun/workspace/rk3399/android-ndk-r13b/platforms/android-24/arch-arm -o hello hello.c
执行失败
先生产工具链cd /opt/android-ndk-r16b
# build/tools/make-standalone-toolchain.sh --toolchain=arm-linux-androideabi-4.9 --platform=android-21 --install-dir=../android-toolchain-r16b/android-armv7 --arch=arm
HOST_OS=linux
HOST_EXE=
HOST_ARCH=x86_64
HOST_TAG=linux-x86_64
HOST_NUM_CPUS=3
BUILD_NUM_CPUS=6
Toolchain installed to ../android-toolchain-r16b/android-armv7.
root@deyi-virtual-machine:/opt/android-ndk-r16b#
cd /opt/android-toolchain-r16b/android-armv7
export PATH=/opt/android-toolchain-r16b/android-armv7/bin:$PATH
export SYSROOT=/opt/android-toolchain-r16b/android-armv7/sysroot
arm-linux-androideabi-gcc -pie -fPIE --sysroot=$SYSROOT -o hello hello.c
编译成功
参考例子
GitHub - MingHuang1024/CrossCompileForAndroid: 使用独立工具链交叉编译可在android系统中运行的so包
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
# Android 5.0 以上需要在此处设置 PIE
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")
# 配置使用 NDK Standalone Toolchain 编译
set(NDK_STANDALONE_TOOLCHAIN /tmp/ndk-hm/arm-linux-androideabi)
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 21)
set(CMAKE_C_COMPILER ${NDK_STANDALONE_TOOLCHAIN}/bin/clang)
set(CMAKE_CXX_COMPILER ${NDK_STANDALONE_TOOLCHAIN}/bin/clang++)
set(CMAKE_FIND_ROOT_PATH ${NDK_STANDALONE_TOOLCHAIN})
# 使用 NDK 提供的头文件
add_definitions("--sysroot=${NDK_STANDALONE_TOOLCHAIN}/sysroot")
add_library(myso SHARED CTest.c)
set_target_properties(myso
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/lib")
include_directories(/home/hm/JDK/jdk1.8.0_151/include /home/hm/JDK/jdk1.8.0_151/include/linux)
target_link_libraries(myso
log)
NDK/build/tools/make-standalone-toolchain.sh --platform=android-23 --arch=arm64 --ndk-dir=/home/chengli/SoftWare/NDK/android-ndk-r12b --install-dir=/home/name/SoftWare/NDK/android-ndk-r12b/tmp/toolchain