Skip to content

Add GitHub Actions workflow for iOS build #11

Add GitHub Actions workflow for iOS build

Add GitHub Actions workflow for iOS build #11

Workflow file for this run

name: Build Android App with SDL2
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install required packages
run: |
sudo apt update
sudo apt install -y build-essential git wget unzip
- name: Install Android SDK and NDK
run: |
mkdir -p $HOME/android-sdk/cmdline-tools
wget https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip
unzip commandlinetools-linux-6609375_latest.zip -d $HOME/android-sdk/cmdline-tools
rm commandlinetools-linux-6609375_latest.zip
# Set up environment variables
echo "export ANDROID_HOME=$HOME/android-sdk" >> $GITHUB_ENV
echo "export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH" >> $GITHUB_ENV
- name: Accept licenses
run: |
yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses
- name: Install required SDK packages
run: |
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --sdk_root=$ANDROID_HOME "platforms;android-26" "ndk;21.4.7075529" "platform-tools" "build-tools;30.0.3"
- name: Clone SDL2 for Android
run: |
git clone https://github.com/libsdl-org/SDL.git
cd SDL
git checkout main # Or specify the desired branch/tag
- name: Build SDL2 for Android
run: |
cd SDL/android
./build-sdl.sh
echo "SDL2 built for Android."
- name: Compile the Android app
run: |
mkdir -p build
cd build
$ANDROID_HOME/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang \
-o MyApp.so \
-I$ANDROID_HOME/ndk/21.4.7075529/sources/android/native_app_glue \
-I$ANDROID_HOME/ndk/21.4.7075529/sources/SDL2 \
../main.c \
-lSDL2 \
-target aarch64-linux-android21 \
-fPIC
- name: Build APK
run: |
cd build
echo "Creating Android APK..."
cat <<EOF > Android.mk
LOCAL_PATH := \$(call my-dir)
include \$(CLEAR_VARS)
LOCAL_MODULE := MyApp
LOCAL_SRC_FILES := MyApp.so
include \$(BUILD_SHARED_LIBRARY)
EOF
echo "Creating Application.mk..."
cat <<EOF > Application.mk
APP_ABI := arm64-v8a
APP_PLATFORM := android-26
EOF
cd $ANDROID_HOME/ndk/21.4.7075529/build/outputs/apk
ndk-build NDK_PROJECT_PATH=$ANDROID_HOME/ndk/21.4.7075529/build \
APP_BUILD_SCRIPT=Android.mk \
NDK_APPLICATION_MK=Application.mk
- name: Upload the build artifact
uses: actions/upload-artifact@v3
with:
name: android-app
path: $ANDROID_HOME/ndk/21.4.7075529/build/outputs/apk/*.apk