Skip to content

Commit

Permalink
Android port
Browse files Browse the repository at this point in the history
Fixed compiler errors for Android NDK clang compiler
Added drop in replacement for std::jthread for Android NDK clang compiler
Added a gradle sub project in the androidplugin directory. This integrates the Java part of the Tilt Five SDK for Android.
In TileFiveXRInterface test the Android platform and load the platform context from the Java plugin
Handle pause and resume notifications from Android
Added Android export in plugin.gd to gather .arr files
Enabled Android build in SConstruct
Shell out new gradle build in SConstruct
Update github CI to assemble zip file with the new Android files.
Added Linux build
  • Loading branch information
patrickdown committed Mar 23, 2024
1 parent a0207ea commit f20188e
Show file tree
Hide file tree
Showing 32 changed files with 1,192 additions and 85 deletions.
116 changes: 86 additions & 30 deletions .github/workflows/build-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@ jobs:
matrix:
include:
# Unsupported platforms are commented out.
#- name: 🐧 Linux (GCC)
# os: ubuntu-20.04
# platform: linux
# artifact-name: gdtiltfive.linux
# artifact-path: build/bin/libgdtiltfive.linux.*
- name: 🐧 Linux (GCC)
os: ubuntu-20.04
platform: linux
artifact-name: gdtiltfive.linux
artifact-path: |
build/bin/linux/x86_64/libgdtiltfive.linux.template_debug.x86_64.dll
build/bin/linux/x86_64/libgdtiltfive.linux.template_release.x86_64.dll
extension/TiltFiveNDK/lib/linux/x86_64/libTiltFiveNative.so
- name: 🏁 Windows (x86_64, MSVC)
os: windows-2019
platform: windows
artifact-name: gdtiltfive.windows
artifact-path: |
build/bin/libgdtiltfive.windows.template_debug.x86_64.dll
build/bin/libgdtiltfive.windows.template_release.x86_64.dll
extension/TiltFiveNDK/lib/win/x86_64/TiltFiveNative.dll
build/bin/windows/x86_64/libgdtiltfive.windows.template_debug.x86_64.dll
build/bin/windows/x86_64/libgdtiltfive.windows.template_release.x86_64.dll
extension/TiltFiveNDK/lib/win/x86_64/TiltFiveNative.dll
#- name: 🍎 macOS (universal)
# os: macos-11
Expand All @@ -39,12 +42,14 @@ jobs:
# artifact-name: gdtiltfive.macos
# artifact-path: build/bin/libgdtiltfive.macos.*

#- name: 🤖 Android (arm64)
# os: ubuntu-20.04
# platform: android
# flags: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME arch=arm64
# artifact-name: gdtiltfive.android
# artifact-path: build/bin/libgdtiltfive.android.*
- name: 🤖 Android (arm64)
os: ubuntu-20.04
platform: android
#flags: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME arch=arm64
artifact-name: gdtiltfive.android
artifact-path: |
build/bin/android/arm64/libgdtiltfive.android.*
androidplugin/plugin/build/outputs/aar/gdtiltfive*
#- name: 🍏 iOS (arm64)
# os: macos-11
Expand Down Expand Up @@ -72,17 +77,52 @@ jobs:
sudo apt-get update -qq
sudo apt-get install -qqq build-essential pkg-config
- name: Set up GCC
if: ${{ matrix.platform == 'linux' }}
uses: egor-tensin/setup-gcc@v1
with:
version: 11
platform: x64

- name: Android dependencies
if: ${{ matrix.platform == 'android' }}
uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r26c
add-to-path: false

- name: Install scons
run: |
python -m pip install scons==4.0.0
python -m pip install scons==4.0.0
- name: Build debug build
run: |
scons platform=${{ matrix.platform }} target=template_debug ${{ matrix.flags }}
scons platform=${{ matrix.platform }} target=template_debug ${{ matrix.flags }} --no-gradle
env:
ANDROID_NDK_ROOT: ${{ steps.setup-ndk.outputs.ndk-path }}

- name: Build release build
run: |
scons platform=${{ matrix.platform }} target=template_release ${{ matrix.flags }}
scons platform=${{ matrix.platform }} target=template_release ${{ matrix.flags }} --no-gradle
env:
ANDROID_NDK_ROOT: ${{ steps.setup-ndk.outputs.ndk-path }}

- name: Set up Java
if: ${{ matrix.platform == 'android' }}
uses: actions/setup-java@v4
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '17'

- name: Gradle build
if: ${{ matrix.platform == 'android' }}
run: |
mkdir plugin/libs
cp ../extension/TiltFiveNDK/lib/android/TiltFiveAndroidClient.jar plugin/libs/TiltFiveAndroidClient.jar
chmod +x ./gradlew
./gradlew build
working-directory: ./androidplugin

- name: Upload artifact
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -117,12 +157,20 @@ jobs:
cp source/CONTRIBUTORS.md plugin/addons/tiltfive
cp source/CHANGES.md plugin/addons/tiltfive
mkdir plugin/addons/tiltfive/bin
# cp gdtiltfive.linux/*.so plugin/addons/tiltfive/bin/
cp gdtiltfive.windows/build/bin/*.dll plugin/addons/tiltfive/bin/
cp gdtiltfive.windows/extension/TiltFiveNDK/lib/win/x86_64/*.dll plugin/addons/tiltfive/bin/
# cp gdtiltfive.android/*.so plugin/addons/tiltfive/bin/
# cp gdtiltfive.ios/*.dylib plugin/addons/tiltfive/bin/
# cp -R gdtiltfive.macos/libgdtiltfive.macos.* plugin/addons/tiltfive/bin/
mkdir plugin/addons/tiltfive/bin/linux
mkdir plugin/addons/tiltfive/bin/linux/x86_64
mkdir plugin/addons/tiltfive/bin/windows
mkdir plugin/addons/tiltfive/bin/windows/x86_64
mkdir plugin/addons/tiltfive/bin/android/
mkdir plugin/addons/tiltfive/bin/android/arm64
cp gdtiltfive.linux/build/bin/linux/x86_64/*.so plugin/addons/tiltfive/bin/linux/x86_64/
cp gdtiltfive.linux/extension/TiltFiveNDK/lib/linux/x86_64/*.so plugin/addons/tiltfive/bin/linux/x86_64/
cp gdtiltfive.windows/build/bin/windows/x86_64/*.dll plugin/addons/tiltfive/bin/windows/x86_64/
cp gdtiltfive.windows/extension/TiltFiveNDK/lib/win/x86_64/*.dll plugin/addons/tiltfive/bin/windows/x86_64/
cp gdtiltfive.android/build/bin/android/arm64/*.so plugin/addons/tiltfive/bin/android/arm64/
cp source/extension/TiltFiveNDK/lib/android/arm64-v8a/*.so plugin/addons/tiltfive/bin/android/arm64/
cp gdtiltfive.android/androidplugin/plugin/build/outputs/aar/gdtiltfive-debug.aar plugin/addons/tiltfive/bin/android
cp gdtiltfive.android/androidplugin/plugin/build/outputs/aar/gdtiltfive-release.aar plugin/addons/tiltfive/bin/android
- name: Copy files to destination for csharp
run: |
mkdir plugin_cs
Expand All @@ -132,12 +180,20 @@ jobs:
cp source/CONTRIBUTORS.md plugin_cs/addons/tiltfive
cp source/CHANGES.md plugin_cs/addons/tiltfive
mkdir plugin_cs/addons/tiltfive/bin
# cp gdtiltfive.linux/*.so plugin_cs/addons/tiltfive/bin/
cp gdtiltfive.windows/build/bin/*.dll plugin_cs/addons/tiltfive/bin/
cp gdtiltfive.windows/extension/TiltFiveNDK/lib/win/x86_64/*.dll plugin_cs/addons/tiltfive/bin/
# cp gdtiltfive.android/*.so plugin_cs/addons/tiltfive/bin/
# cp gdtiltfive.ios/*.dylib plugin_cs/addons/tiltfive/bin/
# cp -R gdtiltfive.macos/libgdtiltfive.macos.* plugin_cs/addons/tiltfive/bin/
mkdir plugin_cs/addons/tiltfive/bin/linux
mkdir plugin_cs/addons/tiltfive/bin/linux/x86_64
mkdir plugin_cs/addons/tiltfive/bin/windows
mkdir plugin_cs/addons/tiltfive/bin/windows/x86_64
mkdir plugin_cs/addons/tiltfive/bin/android/
mkdir plugin_cs/addons/tiltfive/bin/android/arm64
cp gdtiltfive.linux/build/bin/linux/x86_64/*.so plugin_cs/addons/tiltfive/bin/linux/x86_64/
cp gdtiltfive.linux/extension/TiltFiveNDK/lib/linux/x86_64/*.so plugin_cs/addons/tiltfive/bin/linux/x86_64/
cp gdtiltfive.windows/build/bin/windows/x86_64/*.dll plugin_cs/addons/tiltfive/bin/windows/x86_64/
cp gdtiltfive.windows/extension/TiltFiveNDK/lib/win/x86_64/*.dll plugin_cs/addons/tiltfive/bin/windows/x86_64/
cp gdtiltfive.android/build/bin/android/arm64/*.so plugin_cs/addons/tiltfive/bin/android/arm64/
cp source/extension/TiltFiveNDK/lib/android/arm64-v8a/*.so plugin_cs/addons/tiltfive/bin/android/arm64/
cp gdtiltfive.android/androidplugin/plugin/build/outputs/aar/gdtiltfive-debug.aar plugin_cs/addons/tiltfive/bin/android
cp gdtiltfive.android/androidplugin/plugin/build/outputs/aar/gdtiltfive-release.aar plugin_cs/addons/tiltfive/bin/android
- name: Calculate GIT short ref
run: |
cd source
Expand Down Expand Up @@ -172,4 +228,4 @@ jobs:
omitBodyDuringUpdate: true
omitPrereleaseDuringUpdate : true
token: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@ build
*.includes
*.idb
*.exp
*.aar

# project specific ignores
!extension/TiltFiveNDK/lib/*/*/*

example.gd/android/
example.gd/export_presets.cfg
example.csharp/android/
example.csharp/export_presets.cfg
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ TiltFiveGodot4 is **GDExtension** for the Godot 4 engine to connect to the [T

| | Renderer</br> Forward+ | Renderer</br> Mobile | Renderer</br> Compatibility |
| - | - | - | - |
| Windows ||| |
| Linux<sup>1</sup> | &checkmark; |&checkmark; | &checkmark; |
| Android | | &#10060; | |
| Windows ||||
| Linux<sup>1</sup> | | | |
| Android<sup>1</sup> |&#10060;| &#10060; | |

1. [Experimental Version](https://github.com/patrickdown/TiltFiveGodot4/releases/tag/1.1.0-linux-experimental3)
1. Experimental Support

## Usage

Expand All @@ -26,15 +26,16 @@ Please refer to this [documentation](https://patrickdown.github.io/godot/tilt-fi

### Prerequisites

This extension requires a C++20 capable compiler.
This extension requires a C++20 capable compiler. To build for Android you will need Java 17 and the Android SDK along with the r26c NDK.

Things you will need to know how to do.
* Use [scons](https://scons.org/)
* [Build GDExtensions](https://docs.godotengine.org/en/stable/tutorials/scripting/gdextension/gdextension_cpp_example.html)
* Install the Android SDK and NDK (For android builds)

### Building the extension

To build the plugin invoke `scons` from the root directory of the project. The build product will in `build\bin`. Invoking `scons example` will build the product and copy the binaries to the `example.gd\addons\tilt-five\bin` and `example.csharp\addons\tilt-five\bin` directories.
To build the plugin invoke `scons` from the root directory of the project. The build product will in `build\bin`. Invoking `scons --assemble` will build the product and copy the binaries to the `example.gd\addons\tilt-five\bin` and `example.csharp\addons\tilt-five\bin` directories.

## Using the build products

Expand Down
101 changes: 78 additions & 23 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,16 +1,56 @@
#!/usr/bin/env python
import os
import sys
from pprint import pprint

env = SConscript('godot-cpp/SConstruct')

AddOption(
'--no-gradle',
dest='no_gradle',
action='store_true',
help='no not spawn gradle to build the android plugin')

AddOption(
'--assemble',
dest='assemble_example',
action='store_true',
help='assemble the plugin files into the example project')

AddOption(
'--gd-install-dir',
dest='gd_install_dir',
type='string',
nargs=1,
action='store',
metavar='DIR',
help='godot project directory to copy the gdscript plugin to')

AddOption(
'--cs-install-dir',
dest='cs_install_dir',
type='string',
nargs=1,
action='store',
metavar='DIR',
help='godot project directory to copy the c# plugin to')

gd_install_dir = GetOption('gd_install_dir')
cs_install_dir = GetOption('cs_install_dir')

assemble_example = GetOption('assemble_example') or gd_install_dir or cs_install_dir

build_aar_library = not GetOption('no_gradle') and env['platform'] == 'android'

VariantDir('build/src','extension/src', duplicate=False)
VariantDir('build/T5Integration','extension/T5Integration', duplicate=False)

env = SConscript('godot-cpp/SConstruct')
tilt_five_headers_path = 'extension/TiltFiveNDK/include'
tilt_five_library_path = 'extension/TiltFiveNDK/lib/' + { 'windows' : 'win/x86_64', 'linux' : 'linux/x86_64', 'android' : 'android/arm64-v8a'}[env["platform"]]
tilt_five_library = {'windows' : 'TiltFiveNative.dll.if', 'linux' : 'libTiltFiveNative.so', 'android' : 'libTiltFiveNative.so'}[env["platform"]]
tilt_five_library = {'windows' : 'TiltFiveNative.dll.if', 'linux' : 'libTiltFiveNative.so', 'android' : 'TiltFiveNative'}[env["platform"]]
tilt_five_jar = 'extension/TiltFiveNDK/lib/android/TiltFiveAndroidClient.jar'

bin_path = "{}/{}".format(env['platform'], env['arch'])

# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
Expand All @@ -25,6 +65,7 @@ env.Append(CPPPATH=['extension/src/','extension/T5Integration/',tilt_five_header
sources = Glob('build/src/*.cpp')
sources += Glob('build/T5Integration/*.cpp')


env.Append(LIBPATH=[tilt_five_library_path])
env.Append(LIBS=[tilt_five_library])

Expand All @@ -33,36 +74,50 @@ if env['platform'] == 'windows':
env['CXXFLAGS'].remove('/std:c++17')
env.Append(CXXFLAGS=['/std:c++20'])
env.Append(CXXFLAGS=['/Zc:__cplusplus'])
library = env.SharedLibrary(
'build/bin/libgdtiltfive{}{}'.format(env['suffix'], env['SHLIBSUFFIX']),
source=sources,
)
elif env['platform'] == 'linux':
env['t5_shared_lib'] = 'libTiltFiveNative.so'
env['CXXFLAGS'].remove('-std=c++17')
env.Append(CXXFLAGS=['-std=c++20'])
env.Append(RPATH=env.Literal('\\$$ORIGIN' ))
library = env.SharedLibrary(
'build/bin/libgdtiltfive{}{}'.format(env['suffix'], env['SHLIBSUFFIX']),
source=sources,
)
elif env['platform'] == 'android':
env['t5_shared_lib'] = 'libTiltFiveNative.so'
env['t5_shared_lib'] = 'lib{}.so'.format(tilt_five_library)
env['CXXFLAGS'].remove('-std=c++17')
env.Append(CXXFLAGS=['-std=c++20'])
env.Append(CXXFLAGS=['-stdlib=libc++'])
env.Append(CCFLAGS=['-fPIC'])
#env.Append(CPPDEFINES = ['ANDROID_CPP'])
env.Append(RPATH=env.Literal('\\$$ORIGIN' ))
library = env.SharedLibrary(
'build/bin/libgdtiltfive{}{}'.format(env['suffix'], env['SHLIBSUFFIX']),
source=sources,
)

f1 = env.Command('example.gd/addons/tiltfive/bin/libgdtiltfive{}{}'.format(env['suffix'], env['SHLIBSUFFIX']), library, Copy('$TARGET', '$SOURCE') )
f2 = env.Command('example.gd/addons/tiltfive/bin/{}'.format(env['t5_shared_lib']), tilt_five_library_path + '/{}'.format(env['t5_shared_lib']), Copy('$TARGET', '$SOURCE') )
f3 = env.Command('example.csharp/addons/tiltfive/bin/libgdtiltfive{}{}'.format(env['suffix'], env['SHLIBSUFFIX']), library, Copy('$TARGET', '$SOURCE') )
f4 = env.Command('example.csharp/addons/tiltfive/bin/{}'.format(env['t5_shared_lib']), tilt_five_library_path + '/{}'.format(env['t5_shared_lib']), Copy('$TARGET', '$SOURCE') )
library = env.SharedLibrary(
'build/bin/{}/libgdtiltfive{}{}'.format(bin_path,env['suffix'], env['SHLIBSUFFIX']),
source=sources,
)

things_to_build = [library]

if build_aar_library:
print("Building Android AAR library...")
Execute(Copy('androidplugin/plugin/libs/TiltFiveAndroidClient.jar', tilt_five_jar))
SConscript('androidplugin/SConstruct', exports="env")

if assemble_example:
f1 = env.Command('example.gd/addons/tiltfive/bin/{}/libgdtiltfive{}{}'.format(bin_path,env['suffix'], env['SHLIBSUFFIX']), library, Copy('$TARGET', '$SOURCE') )
f2 = env.Command('example.gd/addons/tiltfive/bin/{}/{}'.format(bin_path,env['t5_shared_lib']), tilt_five_library_path + '/{}'.format(env['t5_shared_lib']), Copy('$TARGET', '$SOURCE') )
f3 = env.Command('example.csharp/addons/tiltfive/bin/{}/libgdtiltfive{}{}'.format(bin_path,env['suffix'], env['SHLIBSUFFIX']), library, Copy('$TARGET', '$SOURCE') )
f4 = env.Command('example.csharp/addons/tiltfive/bin/{}/{}'.format(bin_path,env['t5_shared_lib']), tilt_five_library_path + '/{}'.format(env['t5_shared_lib']), Copy('$TARGET', '$SOURCE') )
things_to_build += [f1, f2, f3, f4]
if build_aar_library:
f5 = env.Command('example.gd/addons/tiltfive/bin/android/gdtiltfive-debug.aar', 'androidplugin/plugin/build/outputs/aar/gdtiltfive-debug.aar', Copy('$TARGET', '$SOURCE') )
f6 = env.Command('example.gd/addons/tiltfive/bin/android/gdtiltfive-release.aar', 'androidplugin/plugin/build/outputs/aar/gdtiltfive-release.aar', Copy('$TARGET', '$SOURCE') )
f7 = env.Command('example.csharp/addons/tiltfive/bin/android/gdtiltfive-debug.aar', 'androidplugin/plugin/build/outputs/aar/gdtiltfive-debug.aar', Copy('$TARGET', '$SOURCE') )
f8 = env.Command('example.csharp/addons/tiltfive/bin/android/gdtiltfive-release.aar', 'androidplugin/plugin/build/outputs/aar/gdtiltfive-release.aar', Copy('$TARGET', '$SOURCE') )
things_to_build += [f5, f6, f7, f8]

if gd_install_dir:
inst1 = env.Install("{}/addons".format(gd_install_dir) , "example.gd/addons/tiltfive")
things_to_build += [inst1]

if cs_install_dir:
inst2 = env.Install("{}/addons".format(cs_install_dir) , "example.csharp/addons/tiltfive")
things_to_build += [inst2]

env.Alias('example', [f1, f2, f3, f4])
Default(things_to_build)

Default(library)
34 changes: 34 additions & 0 deletions androidplugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Gradle files
.gradle/
build/
libs/

# Local configuration file (sdk path, etc)
local.properties

# Log/OS Files
*.log

# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.apk
output.json

# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml

# Keystore files
*.jks
*.keystore

# Google Services (e.g. APIs or Firebase)
google-services.json

# Android Profiling
*.hprof
5 changes: 5 additions & 0 deletions androidplugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Tilt Five Godot Android ARR

This is a small project that builds the Java parts that are
required by the Tile Five client. It's only callable functions
are used by the c++ parts of the plugin.
Loading

0 comments on commit f20188e

Please sign in to comment.