Android交叉编译:curl+openssl+Git Submodule + Github Action
文章目录
相关知识点
一、创建项目
1. 添加子项目
1. 添加curl: `git submodule add https://github.com/curl/curl.git`
2. 添加openssl: `git submodule add https://github.com/openssl/openssl.git`
2. 编写执行脚本
简单了解下一些关键字
- GCC
gcc
GNU C语言编译器GNU C Compiler
- LLVM
LLVM (Low Level Virtual Machine,底层虚拟机) - LLVM2.0 - Clang
clang
是LLVM
编译器工具集的前端,输出代码对应的抽象语法。
这里是我编写的脚本 temp_clang.sh
脚本基本通用,大部分都只需进行简单修改,前提是你需要了解一些参数的意义【 MakeFile】
# clang 只支持 armeabi-v7a arm64-v8a x86 x86_64
//for arch in armeabi-v7a arm64-v8a
for arch in armeabi-v7a arm64-v8a
do
chmod +x temp_clang.sh
./temp_clang.sh $arch
done
编译过程中如果有问题,可以查看openssl官方文档
- 文档:https://github.com/openssl/openssl/blob/master/INSTALL.md
- Android:https://github.com/openssl/openssl/blob/master/NOTES-ANDROID.md
设置输出目录(重要):
opensslDir
是输出目录openssl_lib
这是so的输出目录($opensslDir/lib)
为什么要改so的输出目录,因为curl 检测的openssl的都是opensslDir的lib和inlcude,但是openssl-3.0.0默认输出的是lib32
或者lib64
这种,看camke文档它好像是可以检测,但是这里make不行。 不修改的话会导致curl 无法找openssl。
PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH
./Configure android-x86 --release -latomic --libdir=$openssl_lib no-asm shared no-cast no-idea no-camellia no-comp -D__ANDROID_API__=21 --prefix=$opensslDir --openssldir=$opensslDir
make
make install
2. 添加github action
.github/workflows
添加android.yml
name: Android CI
on:
push:
branches: [ master ]
jobs:
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
# 克隆代码
- uses: actions/checkout@v2
# 获取 子模块
- name: Checkout submodules
shell: bash
run: |
git submodule init
git submodule update
# 添加ndk
- name: Setup Android NDK
uses: nttld/setup-ndk@v1.0.6
id: setup-ndk
with:
ndk-version: r21
add-to-path: false
# 添加工具,为make做准备
- name: add autoconf automake libtool
run: brew install autoconf automake libtool
- name: ndk bulid
working-directory:
run: |
chmod +x start_build.sh
echo ${{ steps.setup-ndk.outputs.ndk-path }}
export ANDROID_NDK_ROOT=${{ steps.setup-ndk.outputs.ndk-path }}
./start_build.sh
## 收集产物
- name: Upload a Build Artifact
uses: actions/upload-artifact@v2
with:
name: ndk-openssl-curl-lib
path: |
./android-lib-curl/**/include/
./android-lib-curl/**/lib/
./android-lib-openssl/**/include/
./android-lib-openssl/**/lib/
3. 推送代码到github上触发构建
git基础操作,这里不做描述
4. 总结
- 添加子模块(curl+openssl)
- 编辑构建脚本
- 添加github Action脚本(拉取代码->配置环境->make)
- 推送代码触发脚本
- 构建产物上传
其他
- 子模块是可以更新、删除的,可以网上搜相关资料
- 收集的产物存放在github 是有有效期的,过期失效,不过你可以重新执行脚本
- 功能真香系列:google有提供curl的原始库支持,使用的Android Gradle Plugin 4.0+:prefab功能
案例:google-demo-prefab-curl-ssl - 可以利用GitHub Action通过这种方式构建其他项目,比如ijkplayer
流程:通过git拉取ijkplayer的代码->配置便宜环境->执行构建->保存构建产物