Skip to content

Commit 9f0e343

Browse files
authored
Problem: Missing android build (fix #199) (#200)
* Problem: Missing android build (fix #199) Close: - #199 Solution: - Add android-build.yml - Update Makefile to support armv7-linux-androideabi, aarch64-linux-android, i686-linux-android, and x86_64-linux-android builds. * Add missing target * Prepare sdk * Add missming release * Add env TARGET in yml * Use ndk r25 * Move comments * Add android action * Update Makefile to check 21 or non-21 * Move android action to actions * Add missing using and steps * Add missing shell * Add missing NDK_VERSION * Use 25.1.8937393 * Update CHANGELOG
1 parent d09396e commit 9f0e343

File tree

8 files changed

+248
-2
lines changed

8 files changed

+248
-2
lines changed

.github/actions/android/action.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: 'Android Build CI'
2+
description: 'Build play-cpp-sdk for android'
3+
inputs:
4+
ndk_version:
5+
description: 'Set this to your ndk version'
6+
required: true
7+
default: 21.4.7075529
8+
target:
9+
description: 'Set this to your target'
10+
required: true
11+
default: aarch64-linux-android
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Install Android NDK
16+
shell: bash
17+
env:
18+
NDK_VERSION: ${{ inputs.ndk_version }}
19+
run: |
20+
ANDROID_HOME=$HOME/Library/Android/sdk
21+
SDKMANAGER=$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager
22+
echo y | $SDKMANAGER "ndk;$NDK_VERSION"
23+
- name: Build play-cpp-sdk library
24+
shell: bash
25+
env:
26+
TARGET: ${{ inputs.target }}
27+
NDK_VERSION: ${{ inputs.ndk_version }}
28+
run: make ${{ inputs.target }}
29+
- name: Pack binaries and bindings
30+
shell: bash
31+
run: |
32+
PLATFORM="${{ inputs.target }}-${{ inputs.ndk_version }}"
33+
BUILD_TYPE="tarball"
34+
mkdir -p install
35+
cp -r demo/sdk install
36+
cp ./LICENSE install/sdk
37+
cp ./CHANGELOG.md install/sdk
38+
cd install
39+
tar zcvf ../play_cpp_sdk_${PLATFORM}.tar.gz *
40+
cd ..
41+
shasum -a 256 *.tar.gz > "checksums-$PLATFORM.txt"
42+
echo "release_file=play_cpp_sdk_$PLATFORM.tar.gz" >> $GITHUB_ENV
43+
echo "checksum_file=checksums-$PLATFORM.txt" >> $GITHUB_ENV
44+
cat $GITHUB_ENV
45+
- name: Upload binaries and bindings to Release
46+
uses: softprops/action-gh-release@v1
47+
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
48+
with:
49+
draft: true
50+
files: |
51+
${{ env.release_file }}
52+
${{ env.checksum_file }}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Android Build CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- README.md
9+
tags:
10+
- "v*.*.*"
11+
pull_request:
12+
paths-ignore:
13+
- README.md
14+
jobs:
15+
armv7-linux-androideabi:
16+
runs-on: macos-11
17+
steps:
18+
- uses: actions/checkout@v2
19+
with:
20+
submodules: recursive
21+
- uses: ./.github/actions/android
22+
with:
23+
ndk_version: 25.1.8937393
24+
target: armv7-linux-androideabi
25+
26+
aarch64-linux-android:
27+
runs-on: macos-11
28+
steps:
29+
- uses: actions/checkout@v2
30+
with:
31+
submodules: recursive
32+
- uses: ./.github/actions/android
33+
with:
34+
ndk_version: 25.1.8937393
35+
target: aarch64-linux-android
36+
37+
i686-linux-android:
38+
runs-on: macos-11
39+
steps:
40+
- uses: actions/checkout@v2
41+
with:
42+
submodules: recursive
43+
- uses: ./.github/actions/android
44+
with:
45+
ndk_version: 25.1.8937393
46+
target: i686-linux-android
47+
48+
x86_64-linux-android:
49+
runs-on: macos-11
50+
steps:
51+
- uses: actions/checkout@v2
52+
with:
53+
submodules: recursive
54+
- uses: ./.github/actions/android
55+
with:
56+
ndk_version: 25.1.8937393
57+
target: x86_64-linux-android
58+
59+
armv7-linux-androideabi-unreal:
60+
runs-on: macos-11
61+
steps:
62+
- uses: actions/checkout@v2
63+
with:
64+
submodules: recursive
65+
- uses: ./.github/actions/android
66+
with:
67+
ndk_version: 21.4.7075529
68+
target: armv7-linux-androideabi
69+
70+
aarch64-linux-android-unreal:
71+
runs-on: macos-11
72+
steps:
73+
- uses: actions/checkout@v2
74+
with:
75+
submodules: recursive
76+
- uses: ./.github/actions/android
77+
with:
78+
ndk_version: 21.4.7075529
79+
target: aarch64-linux-android
80+
81+
i686-linux-android-unreal:
82+
runs-on: macos-11
83+
steps:
84+
- uses: actions/checkout@v2
85+
with:
86+
submodules: recursive
87+
- uses: ./.github/actions/android
88+
with:
89+
ndk_version: 21.4.7075529
90+
target: i686-linux-android
91+
92+
x86_64-linux-android-unreal:
93+
runs-on: macos-11
94+
steps:
95+
- uses: actions/checkout@v2
96+
with:
97+
submodules: recursive
98+
- uses: ./.github/actions/android
99+
with:
100+
ndk_version: 21.4.7075529
101+
target: x86_64-linux-android

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22
## [Unreleased]
33

4+
## [v0.0.6-alpha] - 2020-08-24
5+
- Add android builds
6+
47
## [v0.0.6-alpha] - 2020-08-17
58
- Add checksum for linux libc++ release
69
- Add qrcode api

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,41 @@ else
1515
CXXFLAGS += $(DEFAULT_CXXFLAGS)
1616
endif
1717

18+
# Comment out to set your ndk version
19+
# NDK_VERSION=21.4.7075529 # r21e, for unreal 4.27 and 5
20+
# NDK_VERSION=25.1.8937393 # the newest ndk version
21+
22+
# The ndk requirement for unreal, please check
23+
# https://docs.unrealengine.com/4.27/en-US/SharingAndReleasing/Mobile/Android/AndroidSDKRequirements/
24+
# https://docs.unrealengine.com/5.0/en-US/android-development-requirements-for-unreal-engine/
25+
#
26+
# NDK releases >= 23 beta3 no longer include libgcc which rust's pre-built
27+
# standard libraries depend on. As a workaround for newer NDKs we redirect
28+
# libgcc to libunwind.
29+
# See https://github.com/rust-lang/rust/pull/85806
30+
# TODO Here we only check 21 or non-21
31+
ifneq (,$(findstring 21,$(NDK_VERSION)))
32+
RUSTFLAGS +=
33+
else
34+
RUSTFLAGS +="-L$(shell pwd)/env/android"
35+
endif
36+
37+
# RUSTFLAGS +=
38+
ifeq ($(UNAME), Darwin)
39+
# Please install NDK via Android Studio
40+
NDK_HOME=$(HOME)/Library/Android/sdk/ndk/$(NDK_VERSION)
41+
TOOLCHAIN=$(NDK_HOME)/toolchains/llvm/prebuilt/darwin-x86_64
42+
endif
43+
44+
ifeq ($(UNAME), Linux)
45+
# Change NDK_HOME if necessary
46+
NDK_HOME=/usr/local/lib/android/sdk/ndk/$(NDK_VERSION)
47+
TOOLCHAIN=$(NDK_HOME)/toolchains/llvm/prebuilt/linux-x86_64
48+
endif
49+
50+
# Set this to your minSdkVersion.
51+
API=21
52+
1853
all: build_cpp
1954

2055
clone:
@@ -40,6 +75,54 @@ build_extra-cpp-bindings:
4075
build_cpp: build_play-cpp-sdk
4176
MACOSX_DEPLOYMENT_TARGET=10.15 && cd demo && make build
4277

78+
armv7-linux-androideabi: TARGET=armv7-linux-androideabi
79+
armv7-linux-androideabi: android_armv7
80+
cd demo && TARGET=$(TARGET) make android_build
81+
82+
aarch64-linux-android: TARGET=aarch64-linux-android
83+
aarch64-linux-android: android_aarch64
84+
cd demo && TARGET=$(TARGET) make android_build
85+
86+
i686-linux-android: TARGET=i686-linux-android
87+
i686-linux-android: android_i686
88+
cd demo && TARGET=$(TARGET) make android_build
89+
90+
x86_64-linux-android: TARGET=x86_64-linux-android
91+
x86_64-linux-android: android_x86_64
92+
cd demo && TARGET=$(TARGET) make android_build
93+
94+
android_armv7:
95+
rustup target add $(TARGET)
96+
TARGET_CC=$(TOOLCHAIN)/bin/armv7a-linux-androideabi$(API)-clang \
97+
CXX=$(TOOLCHAIN)/bin/armv7a-linux-androideabi$(API)-clang++ \
98+
TARGET_AR=$(TOOLCHAIN)/bin/llvm-ar \
99+
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=$(TOOLCHAIN)/bin/armv7a-linux-androideabi$(API)-clang \
100+
RUSTFLAGS=$(RUSTFLAGS) cargo build --target=$(TARGET) --package play-cpp-sdk --release
101+
102+
android_aarch64:
103+
rustup target add $(TARGET)
104+
TARGET_CC=$(TOOLCHAIN)/bin/$(TARGET)$(API)-clang \
105+
CXX=$(TOOLCHAIN)/bin/$(TARGET)$(API)-clang++ \
106+
TARGET_AR=$(TOOLCHAIN)/bin/llvm-ar \
107+
CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$(TOOLCHAIN)/bin/$(TARGET)$(API)-clang \
108+
RUSTFLAGS=$(RUSTFLAGS) cargo build --target=$(TARGET) --package play-cpp-sdk --release
109+
110+
android_i686:
111+
rustup target add $(TARGET)
112+
TARGET_CC=$(TOOLCHAIN)/bin/$(TARGET)$(API)-clang \
113+
CXX=$(TOOLCHAIN)/bin/$(TARGET)$(API)-clang++ \
114+
TARGET_AR=$(TOOLCHAIN)/bin/llvm-ar \
115+
CARGO_TARGET_I686_LINUX_ANDROID_LINKER=$(TOOLCHAIN)/bin/$(TARGET)$(API)-clang \
116+
RUSTFLAGS=$(RUSTFLAGS) cargo build --target=$(TARGET) --package play-cpp-sdk --release
117+
118+
android_x86_64:
119+
rustup target add $(TARGET)
120+
TARGET_CC=$(TOOLCHAIN)/bin/$(TARGET)$(API)-clang \
121+
CXX=$(TOOLCHAIN)/bin/$(TARGET)$(API)-clang++ \
122+
TARGET_AR=$(TOOLCHAIN)/bin/llvm-ar \
123+
CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=$(TOOLCHAIN)/bin/$(TARGET)$(API)-clang \
124+
RUSTFLAGS=$(RUSTFLAGS) cargo build --target=$(TARGET) --package play-cpp-sdk --release
125+
43126
cpp: build_cpp
44127
# 1. In order to use crypto pay api, you need to Generate Keys in
45128
# https://merchant.crypto.com/developers/api_keys first

demo/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ all: clean clone build
3939
build: prepare static dynamic cmake
4040
run: run_static run_dynamic run_examples
4141

42+
# TARGET is specified in ../Makefile
43+
# for example,
44+
# Run `make aarch64-linux-android`, `TARGET` is `aarch64-linux-android`
45+
android_build: TARGET_DIR=../target/$(TARGET)/release
46+
android_build: prepare
47+
4248
clone:
4349
git submodule update --init --recursive
4450

env/android/libgcc.a

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INPUT(-lunwind)

play-cpp-sdk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "play-cpp-sdk"
3-
version = "0.0.6-alpha"
3+
version = "0.0.7-alpha"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

0 commit comments

Comments
 (0)