Skip to content

Commit b0b37d5

Browse files
committed
feat: add android build for ci
1 parent ea01003 commit b0b37d5

File tree

5 files changed

+88
-7
lines changed

5 files changed

+88
-7
lines changed

.github/workflows/build.yml

+73-1
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,80 @@ jobs:
276276
name: MAA-macos-${{ matrix.arch }}
277277
path: "install"
278278

279+
android:
280+
needs: meta
281+
runs-on: ubuntu-latest
282+
strategy:
283+
matrix:
284+
include:
285+
- os: ubuntu
286+
arch: armeabi-v7a-android
287+
fail-fast: false
288+
289+
steps:
290+
- uses: actions/checkout@v3
291+
with:
292+
submodules: true
293+
294+
- name: Install Packages
295+
run: |
296+
sudo apt-get update -y
297+
sudo apt-get install -y ninja-build python3-pyelftools elfutils patchelf nasm
298+
299+
- uses: nttld/setup-ndk@v1
300+
id: setup-ndk
301+
with:
302+
ndk-version: r26b
303+
add-to-path: false
304+
305+
- name: Download fmtlib
306+
run: |
307+
sh tools/fetch-fmt.sh
308+
309+
- name: Setup ccache
310+
uses: Chocobo1/setup-ccache-action@v1
311+
with:
312+
remove_stale_cache: false
313+
314+
- name: Bootstrap MaaDeps
315+
env:
316+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
317+
run: |
318+
python3 tools/maadeps-download.py arm64-android
319+
320+
- name: Build MAA
321+
run: |
322+
cmake --preset 'NinjaMulti' \
323+
-DCMAKE_TOOLCHAIN_FILE=${{ steps.setup-ndk.outputs.ndk-path}}/build/cmake/android.toolchain.cmake \
324+
-DANDROID_ABI=armeabi-v7a \
325+
-DANDROID_PLATFORM=android-23 \
326+
-DMAADEPS_TRIPLET='maa-arm64-android' \
327+
-DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}' \
328+
-DWITH_GRPC=OFF
329+
330+
cmake --build build --preset 'NinjaMulti - Release' -j 16
331+
332+
- name: Install
333+
shell: bash
334+
if: always()
335+
run: |
336+
cmake --install build --prefix install
337+
338+
cp -r docs install
339+
cp README*.md install
340+
341+
cp -r sample install
342+
343+
cp -r LICENSE.md install
344+
345+
- uses: actions/upload-artifact@v3
346+
if: always()
347+
with:
348+
name: MAA-android-armeabi-v7a
349+
path: "install"
350+
279351
nuget_pack:
280-
needs: [meta, windows, ubuntu, macos]
352+
needs: [meta, windows, ubuntu, macos, android]
281353
runs-on: ubuntu-latest
282354
env:
283355
NUGET_PACKAGE_ID: Maa.Framework.Runtimes # need ${{ secrets.NuGetAPIKey }}

cmake/config.cmake

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ endif()
3030

3131
if(APPLE)
3232
set(CMAKE_INSTALL_RPATH "@loader_path;@executable_path")
33-
add_compile_definitions(MAA_USE_FMTLIB)
34-
add_compile_options("-Wno-deprecated-declarations") # supress tmpnam
3533
elseif(UNIX)
3634
set(CMAKE_INSTALL_RPATH "$ORIGIN")
3735
endif()
3836

37+
if(ANDROID OR APPLE)
38+
add_compile_definitions(MAA_USE_FMTLIB)
39+
add_compile_options("-Wno-deprecated-declarations") # supress std::codecvt_utf8_utf16
40+
endif()
41+
3942
set(CMAKE_CXX_STANDARD 20)
4043
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4144

cmake/utils.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ set(MAADEPS_TARGET_TOOLS ${MAA_DEPS_DIR}/vcpkg/installed/${MAADEPS_TRIPLET}/tool
5353

5454
if(maa-${MAADEPS_HOST_TRIPLET} STREQUAL ${MAADEPS_TRIPLET})
5555
set(MAA_CROSSCOMPILE OFF)
56+
list(PREPEND CMAKE_PREFIX_PATH "${MAA_DEPS_DIR}/vcpkg/installed/${MAADEPS_TRIPLET}")
5657
else()
5758
set(MAA_CROSSCOMPILE ON)
59+
list(PREPEND CMAKE_FIND_ROOT_PATH "${MAA_DEPS_DIR}/vcpkg/installed/${MAADEPS_TRIPLET}")
5860
endif()

source/include/Utils/Time.hpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#pragma once
22

3-
#ifdef __APPLE__
3+
#if defined(__APPLE__) || defined(__ANDROID__)
4+
#define MAA_USE_POSIX_TIME
5+
#endif
6+
7+
#ifdef MAA_USE_POSIX_TIME
48
#include <fcntl.h>
59
#include <sys/time.h>
610
#include <time.h>
@@ -15,7 +19,7 @@ MAA_NS_BEGIN
1519

1620
inline std::string format_now()
1721
{
18-
#ifndef __APPLE__ // Now Apple's compiler cannot build std::chrono::format. 2023/07/21
22+
#ifndef MAA_USE_POSIX_TIME
1923
return MAA_FMT::format("{}", std::chrono::current_zone()->to_local(
2024
std::chrono::floor<std::chrono::milliseconds>(std::chrono::system_clock::now())));
2125
#else
@@ -30,7 +34,7 @@ inline std::string format_now()
3034

3135
inline std::string format_now_for_filename()
3236
{
33-
#ifndef __APPLE__ // Now Apple's compiler cannot build std::chrono::format. 2023/07/21
37+
#ifndef MAA_USE_POSIX_TIME
3438
return MAA_FMT::format("{:%Y.%m.%d-%H.%M.%S}",
3539
std::chrono::current_zone()->to_local(std::chrono::system_clock::now()));
3640
#else

0 commit comments

Comments
 (0)