Skip to content

Commit 29f6372

Browse files
committed
feat: add android for ci
1 parent ea01003 commit 29f6372

File tree

6 files changed

+97
-10
lines changed

6 files changed

+97
-10
lines changed

.github/workflows/build.yml

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

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ if(WITH_WIN32_CONTROLLER AND NOT WIN32)
4949
message(STATUS "Not on Windows, disable WITH_WIN32_CONTROLLER")
5050
set(WITH_WIN32_CONTROLLER OFF)
5151
endif()
52-
if(WITH_THRIFT_CONTROLLER AND MAA_CROSSCOMPILE)
52+
if(WITH_THRIFT_CONTROLLER AND MAA_CROSSCOMPILING)
5353
message(STATUS "Cross-compiling, disable WITH_THRIFT_CONTROLLER")
5454
set(WITH_THRIFT_CONTROLLER OFF)
5555
endif()

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ endif()
5252
set(MAADEPS_TARGET_TOOLS ${MAA_DEPS_DIR}/vcpkg/installed/${MAADEPS_TRIPLET}/tools)
5353

5454
if(maa-${MAADEPS_HOST_TRIPLET} STREQUAL ${MAADEPS_TRIPLET})
55-
set(MAA_CROSSCOMPILE OFF)
55+
set(MAA_CROSSCOMPILING OFF)
56+
list(PREPEND CMAKE_PREFIX_PATH "${MAA_DEPS_DIR}/vcpkg/installed/${MAADEPS_TRIPLET}")
5657
else()
57-
set(MAA_CROSSCOMPILE ON)
58+
set(MAA_CROSSCOMPILING 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)