Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework for Android builds/workflows #2485

Draft
wants to merge 151 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
865264c
Add workflow_dispatch to android workflows
MatusGuy Apr 29, 2023
6f8f45e
Android clone most dependencies
MatusGuy May 2, 2023
d8628e6
WIP android cmake script
MatusGuy May 2, 2023
eac44f7
fix android clone deps
MatusGuy May 2, 2023
8535bbc
Give permission to run clone deps script
MatusGuy May 3, 2023
cad2004
set script permissions for android workflows
MatusGuy Apr 29, 2023
6d2f92a
Merge 6f8f45e34
MatusGuy May 2, 2023
c18ad63
WIP android cmake script
MatusGuy May 2, 2023
470be66
Give permission to run clone deps script
MatusGuy May 3, 2023
394cafe
Merge branch 'SuperTux:master' into master
MatusGuy May 3, 2023
29f883b
Merge branch 'SuperTux:master' into android-workflows
MatusGuy May 3, 2023
0c1fb47
Finishing up merge conflict fixes
MatusGuy May 3, 2023
20f5d79
fix invalid path for android workflow
MatusGuy May 3, 2023
9ec49c0
fix working directory
MatusGuy May 3, 2023
9b288f6
clone dep script must be 1 line
MatusGuy May 3, 2023
36a80b5
fix sdl image version
MatusGuy May 3, 2023
be2d006
Remove the second copy cmake script step
MatusGuy May 3, 2023
a1f977f
more android specific stuff
MatusGuy May 3, 2023
f843590
supertux android specific files
MatusGuy May 3, 2023
e35594a
fix jdk setup on android
MatusGuy May 3, 2023
415f838
Set android ndk version
MatusGuy May 3, 2023
2c18bbc
change app icon to default icon android
MatusGuy May 3, 2023
d6aeab5
oops forgot to set android sdk version here
MatusGuy May 3, 2023
525f0e9
not supported by sdk 24 apparently
MatusGuy May 3, 2023
4c729e0
Move android java files
MatusGuy May 4, 2023
a3e4d45
change android sdk version
MatusGuy May 4, 2023
3bae05f
add supertux to android build
MatusGuy May 4, 2023
092a46e
upload generated apk
MatusGuy May 4, 2023
7d460b8
remove workingdirectory in android workflow upload
MatusGuy May 4, 2023
3462e24
change android build folder
MatusGuy May 4, 2023
3e5f428
android package name fix on main activity
MatusGuy May 4, 2023
964a6cb
added gradle namespace for android
MatusGuy May 5, 2023
6d7bee7
do not show gradle daemon status
MatusGuy May 5, 2023
2587a72
hm is this needed on workflow_dispatch?
MatusGuy May 6, 2023
7106103
cmake print added dependency
MatusGuy May 6, 2023
2218c08
add subdirectories manually
MatusGuy May 6, 2023
3e00f89
hopeless cmake tests
MatusGuy May 6, 2023
8f9031a
Merge branch 'SuperTux:master' into master
MatusGuy May 6, 2023
773cac9
manually specify libraries
MatusGuy May 6, 2023
7b8c498
specify cmake version for android builds
MatusGuy May 7, 2023
c158099
specified cmake version somewhere else
MatusGuy May 7, 2023
39ae0f0
added quotes in cmake version
MatusGuy May 7, 2023
b7576a9
make sdl available to android dependencies
MatusGuy May 7, 2023
ac107c1
last commit fix
MatusGuy May 7, 2023
13975fe
android use original sdl_ttf instead of fork
MatusGuy May 7, 2023
cb18f0d
WIP make provide scripts compatible with android
MatusGuy May 10, 2023
05d3dd9
fixed all configuration errors?
MatusGuy May 11, 2023
88f9cff
fixed 90% of include errors regarding android
MatusGuy May 20, 2023
5a72cc3
it's already at linking stage! rn i'm temp disabling curl
MatusGuy May 24, 2023
0d6dd95
Merge branch 'master' of https://github.com/MatusGuy/supertux
MatusGuy May 24, 2023
adfeb03
ability to not build addon support
MatusGuy May 26, 2023
e193679
i am happy to remove boost from dependencies
MatusGuy May 26, 2023
657933c
remove boost from android workflows
MatusGuy May 26, 2023
af1f21e
trying to fix curl disabling
MatusGuy May 27, 2023
201897d
i guess disabling curl doesnt really make sense
MatusGuy May 27, 2023
8e8ad62
Attempt to fix openssl
MatusGuy May 29, 2023
94c7a9a
Everything should configure, generate, build, link.
MatusGuy Jun 3, 2023
da35e81
finally!! openssl on android!
MatusGuy Jun 4, 2023
3296231
Android sets up data dir
MatusGuy Jun 4, 2023
21bb269
fixed aspect ratio on android
MatusGuy Jun 4, 2023
6f5a155
android workflows zip data folder
MatusGuy Jun 4, 2023
7131cf1
app icon and name
MatusGuy Jun 4, 2023
8ed098c
fix android workflows assets zip
MatusGuy Jun 4, 2023
b8f55b2
set gradle version
MatusGuy Jun 4, 2023
8d60865
Merge branch 'SuperTux:master' into android-workflows
MatusGuy Jun 4, 2023
194e446
clarified linking in root cmakelists
MatusGuy Jun 5, 2023
ebbf6e9
Merge branch 'SuperTux:master' into android-workflows
MatusGuy Jun 5, 2023
9d2b3bf
detect touchscreens and show mobile controls if so
MatusGuy Jun 5, 2023
20f7e3d
set jdk version to 20
MatusGuy Jun 5, 2023
6287916
added fixme for android link libraries at root cmakelists
MatusGuy Jun 5, 2023
56b88f1
sign apk
MatusGuy Jun 6, 2023
c881cb4
Merge branch 'android-workflows' of https://github.com/MatusGuy/super…
MatusGuy Jun 6, 2023
0109d5f
disable building tests
MatusGuy Jun 6, 2023
9f04c62
set apksigner path
MatusGuy Jun 6, 2023
c9ecd5a
fixed signing keys in android workflows
MatusGuy Jun 6, 2023
831f565
android save data directory in external storage
MatusGuy Jun 6, 2023
9150986
fix spelling of antartica in android workflows
MatusGuy Jun 6, 2023
45c9982
try to remove big build logs
MatusGuy Jun 6, 2023
67cb18d
indentation and remove comment
MatusGuy Jun 6, 2023
4bb5269
add back quit button for mobile devices
MatusGuy Jun 6, 2023
671a2ba
putting this back on
MatusGuy Jun 7, 2023
6239df5
made mobile controls bigger
MatusGuy Jun 7, 2023
8b66c82
Use actions/checkout for cloning sdl
MatusGuy Jun 7, 2023
7f3c703
attempt to fix android workflow not finding sdl
MatusGuy Jun 8, 2023
87e450e
Merge branch 'SuperTux:master' into android-workflows
MatusGuy Jun 11, 2023
2e73f4b
i don't actually know how to use actions/checkout
MatusGuy Jun 20, 2023
5f880bf
whoops, script permissions in wrong order
MatusGuy Jun 22, 2023
6d0362b
Merge branch 'SuperTux:master' into android-workflows
MatusGuy Jun 22, 2023
38a1a61
Download addons (with ssl verification off)
MatusGuy Jun 26, 2023
11df433
Merge branch 'master' into android-workflows
MatusGuy Jun 26, 2023
b53b194
Merge branch 'master' into android-workflows
MatusGuy Jun 26, 2023
1e36b2d
final tweaks to merge conflict fix
MatusGuy Jun 27, 2023
326e450
tweak merge conflict fix
MatusGuy Jun 28, 2023
997b503
auto locale via jni
MatusGuy Jun 28, 2023
7713451
android screen keyboard support for textfields
MatusGuy Jun 29, 2023
79de9a9
indentation
MatusGuy Jun 29, 2023
e62d68e
Preparing for a 48h github workflow debugging session.
MatusGuy Jun 29, 2023
695c76a
debug apks are always signed
MatusGuy Jun 29, 2023
6a4924f
forgot to change java file in mk and only changed it in local :(
MatusGuy Jun 29, 2023
f3fbffc
man i sure hope it works
MatusGuy Jun 29, 2023
f7fa62b
workflow upload data zip
MatusGuy Jun 30, 2023
c720bf6
Merge branch 'SuperTux:master' into android-workflows
MatusGuy Jul 1, 2023
00ee564
Merge branch 'SuperTux:master' into android-workflows
MatusGuy Jul 6, 2023
5548a57
Merge branch 'SuperTux:master' into android-workflows
MatusGuy Aug 1, 2023
2f1db58
Move clone_dependency.sh to .ci_scripts
MatusGuy Aug 1, 2023
bbc3a3a
Merge branch 'android-workflows' of https://github.com/MatusGuy/super…
MatusGuy Aug 1, 2023
f735803
Crap!
MatusGuy Aug 1, 2023
5cb96c0
How did that get through...? [ci skip]
MatusGuy Aug 1, 2023
95be7d9
wip menu.stl fix for android
MatusGuy Aug 8, 2023
09df9d9
Package menu.stl and move zip step from yml to cmake
MatusGuy Aug 16, 2023
a5d6016
Merge branch 'master' into android-workflows
MatusGuy Aug 16, 2023
366566b
Create assets folder before zipping data
MatusGuy Aug 16, 2023
b2ff43d
Merge branch 'android-workflows' of https://github.com/MatusGuy/super…
MatusGuy Aug 16, 2023
10b2371
Remove ; from function declaration.
MatusGuy Aug 16, 2023
beacbc2
Change project src dir to cmake source dir (windows fix attempt)
MatusGuy Aug 16, 2023
adfcc2e
Add this back for other workflows to detect SDL
MatusGuy Aug 16, 2023
ee72b8c
change null to nullptr
MatusGuy Aug 16, 2023
efa5f8a
I wonder what will happen if...
MatusGuy Aug 17, 2023
1e11313
Instant regret.
MatusGuy Aug 17, 2023
cb4f5e6
remove iconv include from findlocale
MatusGuy Aug 17, 2023
f61b1b1
Merge branch 'SuperTux:master' into android-workflows
MatusGuy Aug 17, 2023
2673fb6
try split workflow into different architectures
MatusGuy Aug 21, 2023
002c406
tweak
MatusGuy Aug 21, 2023
a25412b
try fix android workflow not running
MatusGuy Aug 21, 2023
10f5e08
again
MatusGuy Aug 21, 2023
18761cd
this should be it?
MatusGuy Aug 21, 2023
f6392c6
toarray
MatusGuy Aug 21, 2023
221152f
asarray
MatusGuy Aug 21, 2023
9fad39f
use project properties
MatusGuy Aug 21, 2023
c5f45a2
wip caching
MatusGuy Aug 21, 2023
1728a3e
fix symlink
MatusGuy Aug 21, 2023
45cdf59
fix fix symlink
MatusGuy Aug 21, 2023
e7ba0c8
changed names
MatusGuy Aug 22, 2023
50dc71a
forgot to change key here
MatusGuy Aug 22, 2023
067a017
tempfix for aspect ratio
MatusGuy Aug 23, 2023
bca6c4d
Merge branch 'master' into android-workflows
MatusGuy Jan 9, 2024
d395da8
data.zip is made by cmake
MatusGuy Jan 9, 2024
7a22aa2
no more caching
MatusGuy Jan 9, 2024
d6b9300
Merge master
MatusGuy Jul 8, 2024
bd9976b
fix ssq
MatusGuy Jul 8, 2024
8319a4c
wip vcpkg
MatusGuy Jul 9, 2024
d27d4e3
DAMN!!!
MatusGuy Jul 17, 2024
6bef500
went a bit freaky with that one
MatusGuy Aug 14, 2024
5e41243
This is the stablest it can go. Also I fixed ssl?
MatusGuy Sep 5, 2024
508cc47
enable ssl hwoops
MatusGuy Sep 6, 2024
0ad4b81
Fix video system not giving correct resolution
MatusGuy Sep 6, 2024
91f45cd
remove custom cursor by default
MatusGuy Sep 6, 2024
9528f5d
ahfhath
MatusGuy Sep 11, 2024
7e2fe2b
ficks
MatusGuy Sep 11, 2024
42386a0
ficks 2
MatusGuy Sep 11, 2024
0162c9f
ficks 1.5
MatusGuy Sep 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .ci_scripts/clone_dependency.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash
# Script used by GitHub workflows (mainly android)
# to clone a git repository

git clone "https://github.com/$1" --recurse-submodules --branch $2 --depth 1
194 changes: 88 additions & 106 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,134 +17,116 @@

name: Android
on:
workflow_dispatch:
inputs: {}
push:
branches:
- master
- android-workflows
tags:
- '*'
pull_request: {}
pull_request: {2485}

jobs:
build-android:
env:
# Revision of https://github.com/pelya/commandergenius.git - SDL2 repo is a submodule
# We check out a specific stable revision, so the build won't break if I modify my SDL repo
SDL_ANDROID_REV: 798fd0f5e167aa6ecce33623dbf88ebc6cd647ea
# It takes 35 minutes per one architecture to build SuperTux, of which 20 minutes are for building Boost and ICU libraries
# Enable additional architectures when we have these libraries inside the cache, or create a separate Android script for each architecture
ARCH_LIST: armeabi-v7a arm64-v8a x86 x86_64

android:
strategy:
fail-fast: false
matrix:
arch: [arm64-v8a, armeabi-v7a, x86, x86_64]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- uses: actions/checkout@v3

- name: Clone SDL Android repo
run: |
git clone --depth=100 https://github.com/pelya/commandergenius.git build.android
git -C build.android checkout ${SDL_ANDROID_REV}
- name: Set script permissions
run: chmod +x ./.ci_scripts/*.sh

- name: Clone SDL Android repo submodules
# There are many more submodules in this repo, we don't need them all
working-directory: build.android
run: >
git submodule update --init --recursive --depth=1
project/jni/boost/src project/jni/iconv/src
project/jni/sdl2 project/jni/sdl2_image
project/jni/sdl2_mixer project/jni/sdl2_ttf
- name: Use cached dependencies
id: use-dependencies
uses: actions/cache/restore@v3
with:
path: ./build.android/app/jni/
key: Android-${{ matrix.arch }}-dependencies-${{ hashFiles('.github/workflows/android.yml') }}

- name: Symlink the application dir
- name: Prepare SDL Android project
if: steps.use-dependencies.outputs.cache-hit != 'true'
run: |
rm -rf build.android/project/jni/application/supertux/supertux
ln -s `pwd` build.android/project/jni/application/supertux/supertux
ln -s supertux build.android/project/jni/application/src
./.ci_scripts/clone_dependency.sh libsdl-org/SDL release-2.26.5
mv ./SDL/android-project/ ./build.android
mv ./SDL/ ./build.android/app/jni/SDL

- name: Set architectures list and version
working-directory: build.android
- name: Clone dependencies
working-directory: build.android/app/jni
if: steps.use-dependencies.outputs.cache-hit != 'true'
run: |
VERSION_NAME="$(git -C .. describe --tags | cut -f 1,2 -d "-" | sed 's/[^0-9\\.\\-]//g' | sed 's/-/./g')"
VERSION_CODE="$(printf "%02d%02d%02d%04d\n" "$(echo $VERSION_NAME | cut -d . -f 1)" "$(echo $VERSION_NAME | cut -d . -f 2)" "$(echo $VERSION_NAME | cut -d . -f 3)" "$(echo $VERSION_NAME | cut -d . -f 4)")"
echo "Version name: $VERSION_NAME"
echo "Version code: $VERSION_CODE"
sed -i "s/MultiABI=.*/MultiABI='${ARCH_LIST}'/g" project/jni/application/supertux/AndroidAppSettings.cfg
sed -i "s/AppVersionName.*/AppVersionName="$VERSION_NAME"/g" project/jni/application/supertux/AndroidAppSettings.cfg
sed -i "s/AppVersionCode.*/AppVersionCode=$VERSION_CODE/g" project/jni/application/supertux/AndroidAppSettings.cfg

- name: Copy precompiled libraries from cache
uses: actions/cache@v2
id: cache
../../../.ci_scripts/clone_dependency.sh libsdl-org/SDL_image release-2.6.3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe work with pushd / popd here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the script clones into current directory

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay.

../../../.ci_scripts/clone_dependency.sh libsdl-org/SDL_ttf release-2.20.2
../../../.ci_scripts/clone_dependency.sh curl/curl curl-8_0_1
../../../.ci_scripts/clone_dependency.sh glennrp/libpng v1.6.39
../../../.ci_scripts/clone_dependency.sh janbar/openssl-cmake master
../../../.ci_scripts/clone_dependency.sh kcat/openal-soft 1.23.1
../../../.ci_scripts/clone_dependency.sh fmtlib/fmt 9.1.0
../../../.ci_scripts/clone_dependency.sh g-truc/glm 0.9.9.8
../../../.ci_scripts/clone_dependency.sh xiph/vorbis v1.3.7
../../../.ci_scripts/clone_dependency.sh xiph/ogg v1.3.5
ln -s ../../../ supertux

- name: Cache dependencies
id: cache-dependencies
uses: actions/cache/save@v3
with:
# The same SDL revision will produce the same libraries
key: ${{env.SDL_ANDROID_REV}}
path: |
build.android/project/jni/boost/include
build.android/project/jni/boost/lib
build.android/project/jni/iconv/include
build.android/project/jni/iconv/lib
build.android/project/jni/icuuc/include
build.android/project/jni/icuuc/lib
build.android/project/jni/openssl/include
build.android/project/jni/openssl/lib

- name: Touch cached file timestamps
if: steps.cache.outputs.cache-hit == 'true'
working-directory: build.android
run: >
touch
project/jni/boost/lib/*/*
project/jni/iconv/lib/*/*
project/jni/icuuc/lib/*/*
project/jni/openssl/lib/*/*
|| true

- name: Build Boost, ICU, and OpenSSL
working-directory: build.android
run: |
export PATH=$ANDROID_NDK_LATEST_HOME:$PATH
./changeAppSettings.sh
path: ./build.android/app/jni/
key: Android-${{ matrix.arch }}-dependencies-${{ hashFiles('.github/workflows/android.yml') }}

- name: Set up Gradle and Android SDK licenses
working-directory: build.android/project
run: |
yes | sudo $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --licenses
./gradlew assembleRelease || true
yes | sudo $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --licenses --sdk_root=`pwd`
mkdir -p $HOME/.android
keytool -genkey -v -keystore $HOME/.android/debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000 -dname "CN=Debug, OU=Debug, O=Debug, L=Debug, ST=Debug, C=Debug"
echo "sdk.dir=$ANDROID_SDK_ROOT" > local.properties
echo "proguard.config=proguard.cfg;proguard-local.cfg" >> local.properties

- name: Build
working-directory: build.android
- name: Copy SuperTux Android project files
run: |
export PATH=$ANDROID_NDK_LATEST_HOME:$ANDROID_SDK_ROOT/build-tools/31.0.0:$PATH
./build.sh
cp -r -f ./mk/android/* ./build.android/

- name: Set up JDK 20
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 20
cache: 'gradle'

- name: Setup Android enviroment
uses: android-actions/setup-android@v2
with:
packages: |
platforms;android-33
ndk;25.2.9519653
build-tools;33.0.2

- name: Package
- name: Build APK
working-directory: build.android
run: |
export PATH=$ANDROID_NDK_LATEST_HOME:$ANDROID_SDK_ROOT/build-tools/31.0.0:$PATH
mkdir -p upload/apk/ upload/aab/
cd project
./gradlew bundleReleaseWithDebugInfo
mv app/build/outputs/bundle/releaseWithDebugInfo/app-releaseWithDebugInfo.aab ../upload/aab/SuperTux.aab
cd jni/application/supertux
./create-apk-with-data.sh
cd ../../../..
mv SuperTux*.apk upload/apk/
cd ..

- uses: actions/upload-artifact@v4
chmod +x ./gradlew
./gradlew assembleRelease -Pcpuarch="${{ matrix.arch }}" --info

- name: Upload unsigned APK
uses: actions/upload-artifact@v3
with:
name: "SuperTux-android-aab"
path: build.android/upload/aab
if-no-files-found: error
name: "Unsigned APK ${{ matrix.arch }}"
path: "build.android/app/build/outputs/apk/release/app-release-unsigned.apk"

- name: Sign APK
working-directory: build.android/app/build/outputs/apk/release
run: |
# removing possible confusion
cp ./app-release-unsigned.apk ./app-release.apk

keytool -genkey -v \
-keystore supertux.keystore -alias supertux \
-storepass supertux \
-dname "cn=MatusGuy, ou=Contributor, O=SuperTux Team, L=Antarctica, ST=Antarctica, C=aq" \
-keyalg RSA -keysize 2048 -validity 10000

$ANDROID_SDK_ROOT/build-tools/33.0.2/apksigner sign \
--ks supertux.keystore --ks-pass pass:supertux \
./app-release.apk

- uses: actions/upload-artifact@v4
- name: Upload signed APK
uses: actions/upload-artifact@v3
with:
name: "SuperTux-android-apk"
path: build.android/upload/apk
if-no-files-found: error
name: "Signed APK ${{ matrix.arch }}"
path: "build.android/app/build/outputs/apk/release/app-release.apk"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build/
build.*/
**/CMakeFiles/
**/CMakeCache.txt
supertux2
./supertux2

# Ubuntu Touch (clickable) build files
.clickable/
Expand Down
43 changes: 41 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ if(EMSCRIPTEN)
endif()

# TODO: Add " OR ANDROID OR IOS" to this
if(EMSCRIPTEN OR UBUNTU_TOUCH OR ANDROID)
if(EMSCRIPTEN)
option(REMOVE_QUIT_BUTTON "Remove the option to quit the game (useful on mobile devices)" ON)
else()
option(REMOVE_QUIT_BUTTON "Remove the option to quit the game (useful on mobile devices)" OFF)
Expand Down Expand Up @@ -163,6 +163,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_definitions(-DMACOSX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
endif()

Expand Down Expand Up @@ -230,6 +231,8 @@ target_include_directories(supertux2_lib PUBLIC ${CMAKE_BINARY_DIR} src/)
if(WIN32)
add_executable(supertux2 WIN32 src/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.rc)
target_link_libraries(supertux2 LibSDL2main)
elseif(ANDROID)
add_library(supertux2 src/main.cpp)
else()
add_executable(supertux2 src/main.cpp)
endif()
Expand Down Expand Up @@ -263,6 +266,9 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc.*")
endif()

## Link supertux binary with squirrel and other libraries
if(NOT EMSCRIPTEN)
target_link_libraries(supertux2_lib PUBLIC LibSDL2 LibSDL2_image)
endif()

target_link_libraries(supertux2_lib PUBLIC LibSimpleSquirrel)
target_link_libraries(supertux2_lib PUBLIC LibTinygettext)
Expand All @@ -273,7 +279,6 @@ target_link_libraries(supertux2_lib PUBLIC LibOpenAL)
target_link_libraries(supertux2_lib PUBLIC LibGlm)
target_link_libraries(supertux2_lib PUBLIC LibFmt)
target_link_libraries(supertux2_lib PUBLIC LibPhysfs)

if(NOT EMSCRIPTEN)
target_link_libraries(supertux2_lib PUBLIC LibSDL2_ttf)
target_link_libraries(supertux2_lib PUBLIC LibSDL2 LibSDL2_image)
Expand All @@ -289,12 +294,46 @@ if(ENABLE_DISCORD)
target_link_libraries(supertux2_lib PUBLIC LibDiscord)
endif()

# FIXME: Very janky development enviroment!
if(ANDROID)
target_link_libraries(supertux2_lib PUBLIC physfs)
target_link_libraries(supertux2_lib PUBLIC libcurl)
target_link_libraries(supertux2_lib PUBLIC OpenAL)
target_link_libraries(supertux2_lib PUBLIC ogg)
target_link_libraries(supertux2_lib PUBLIC vorbis)
target_link_libraries(supertux2_lib PUBLIC vorbisfile)
target_link_libraries(supertux2_lib PUBLIC glm)
target_link_libraries(supertux2_lib PUBLIC png)

# This is fine, though.
find_library(log-lib log)
target_link_libraries(supertux2_lib PUBLIC ${log-lib})
endif()

## Install stuff
include(SuperTux/BuildInstall)

## Create config.h now that INSTALL_SUBDIR_* have been set.
configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h )

# Make android data.zip
if(ANDROID)
get_filename_component(DATADIR ${PROJECT_SOURCE_DIR}/data REALPATH)
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/build.android/app/src/main/assets)
file(MAKE_DIRECTORY ${PROJECT_SOURCE_DIR}/build.android/app/src/main/assets)
endif()
file(GLOB DATA_CONTENTS RELATIVE ${DATADIR} ${DATADIR}/*)
message("DATA: ${DATA_CONTENTS}")
#file(ARCHIVE_CREATE OUTPUT ${PROJECT_SOURCE_DIR}/build.android/app/src/main/assets/data.zip PATHS ${DATA_CONTENTS} FORMAT zip)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar "cfv"
"${PROJECT_SOURCE_DIR}/build.android/app/src/main/assets/data.zip"
--format=zip
${DATA_CONTENTS}

WORKING_DIRECTORY ${DATADIR}
)
endif()

## Build tests
include(SuperTux/BuildTests)

Expand Down
36 changes: 36 additions & 0 deletions external/findlocale/findlocale.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,42 @@ FL_FindLocale(FL_Locale **locale) {
}
}
}
#elif defined(__ANDROID__)
// normal method will always give default guess
// use JNI instead
JNIEnv* env = (JNIEnv*) SDL_AndroidGetJNIEnv();
jclass cls = (*env)->FindClass(env, "org/lethargik/supertux2/MainActivity");
if (cls != NULL) {
jmethodID getlang = (*env)->GetStaticMethodID(env, cls, "getLang", "()[C");
jmethodID getcountry = (*env)->GetStaticMethodID(env, cls, "getCountry", "()[C");

jcharArray langchararr = (*env)->CallStaticObjectMethod(env, cls, getlang);
jcharArray countrychararr = (*env)->CallStaticObjectMethod(env, cls, getcountry);

int langc = (*env)->GetArrayLength(env, langchararr);
int countryc = (*env)->GetArrayLength(env, countrychararr);

jchar* jnilang = (*env)->GetCharArrayElements(env, langchararr, 0);
jchar* jnicountry = (*env)->GetCharArrayElements(env, countrychararr, 0);

char* lang = SDL_iconv_string("UTF-8", "UTF-16", (const char *) jnilang, langc*2);
char* country = SDL_iconv_string("UTF-8", "UTF-16", (const char *) jnicountry, countryc*2);

char* variant = malloc(sizeof("UTF-8")+1);
strcpy(variant, "UTF-8");

rtn->lang = lang;
rtn->country = country;
rtn->variant = variant;

(*env)->ReleaseCharArrayElements(env, langchararr, jnilang, 0);
(*env)->ReleaseCharArrayElements(env, countrychararr, jnicountry, 0);

success = FL_CONFIDENT;
} else {
success = FL_FAILED;
}

#else
/* assume unixoid */
{
Expand Down
9 changes: 9 additions & 0 deletions external/findlocale/findlocale.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#ifndef __findlocale_h_
#define __findlocale_h_

#ifdef __ANDROID__
#include <jni.h>

// SDL headers not recognized, forward declaring

void* SDL_AndroidGetJNIEnv();
char* SDL_iconv_string(const char*, const char*, const char*, size_t);
#endif

typedef const char* FL_Lang;
typedef const char* FL_Country;
typedef const char* FL_Variant;
Expand Down
Loading
Loading