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

Create an Android build #459

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 17 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ jobs:
name: Linux-x64-clang
- runner: ubuntu-latest
preset: linux-cross-arm64
cc: gcc
cxx: g++++
name: Linux-cross-arm64
- runner: ubuntu-latest
name: android
build_type:
- Debug
- Release
Expand Down Expand Up @@ -102,32 +102,38 @@ jobs:
with:
vcpkgJsonGlob: vcpkg.json

- name: Configure cross-compiled build
if: ${{ matrix.os.preset == 'linux-cross-arm64' }}
run: |
cmake --preset linux
ninja -f build-${{ matrix.build_type }}.ninja -C builds/linux/ HogMaker
cmake --preset linux-cross-arm64 -DHogMaker_DIR=$PWD/builds/linux/ -DBUILD_TESTING=OFF -DENABLE_LOGGER=ON -DFORCE_PORTABLE_INSTALL=ON -DBUILD_EDITOR=OFF -DUSE_EXTERNAL_PLOG=ON
- uses: actions/setup-java@v4
if: ${{ matrix.os.name == 'android' }}
with:
java-version: '17'
distribution: 'temurin'

- name: Build APK
if: ${{ matrix.os.name == 'android' }}
run: ./gradlew build

- name: Configure CMake
if: ${{ matrix.os.preset != 'linux-cross-arm64' }}
if: ${{ matrix.os.name != 'android' }}
env:
CC: ${{ matrix.os.cc }}
CXX: ${{ matrix.os.cxx }}
run: cmake --preset ${{ matrix.os.preset }} -DBUILD_TESTING=ON -DENABLE_LOGGER=ON -DFORCE_PORTABLE_INSTALL=ON -DBUILD_EDITOR=ON -DUSE_EXTERNAL_PLOG=ON
run: cmake --preset ${{ matrix.os.preset }} -DENABLE_LOGGER=ON -DFORCE_PORTABLE_INSTALL=ON -DUSE_EXTERNAL_PLOG=ON -DBUILD_EDITOR=ON -DBUILD_TESTING=${{ matrix.os.preset == 'linux-cross-arm64' && 'OFF' || 'ON' }}

- name: Build ${{ matrix.build_type }}
if: ${{ matrix.os.name != 'android' }}
run: cmake --build --preset ${{ matrix.os.preset }} --config ${{ matrix.build_type }} --verbose

- name: Run ${{ matrix.build_type }} Unittests
if: ${{ matrix.os.preset != 'linux-cross-arm64' }}
if: ${{ matrix.os.preset != 'linux-cross-arm64' && matrix.os.name != 'android' }}
run: ctest --preset ${{ matrix.os.preset }} -C ${{ matrix.build_type }}

- name: Local install
if: ${{ matrix.os.name != 'android' }}
# There no cmake install presets so install in traditional way
run: cmake --install builds/${{ matrix.os.preset }}/ --config ${{ matrix.build_type }}

- name: Upload Artifacts
if: ${{ matrix.os.name != 'android' }}
uses: actions/upload-artifact@v4
with:
name: Descent3_${{ matrix.build_type }}_${{ matrix.os.name }}
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,10 @@ build[s]

# Ignore autogenerated git-hash.txt file, generated for packaging purposes
git-hash.txt

# Android build bits
.gradle/*
android/.cxx/*
android/build/*
build/*
local.properties
36 changes: 32 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ endif()
set(USE_VCPKG "DEFAULT" CACHE STRING "Use vcpkg for dependency management. DEFAULT defers to existence of $VCPKG_ROOT environment variable.")
set_property(CACHE USE_VCPKG PROPERTY STRINGS "DEFAULT" "ON" "OFF")

if (CMAKE_SYSTEM_NAME STREQUAL "Android")
if (ANDROID_ABI MATCHES "arm64-v8a")
set(VCPKG_TARGET_TRIPLET "arm64-android" CACHE STRING "" FORCE)
elseif(ANDROID_ABI MATCHES "armeabi-v7a")
set(VCPKG_TARGET_TRIPLET "arm-android" CACHE STRING "" FORCE)
elseif(ANDROID_ABI MATCHES "x86_64")
set(VCPKG_TARGET_TRIPLET "x64-android" CACHE STRING "" FORCE)
elseif(ANDROID_ABI MATCHES "x86")
set(VCPKG_TARGET_TRIPLET "x86-android" CACHE STRING "" FORCE)
else()
message(FATAL_ERROR "ANDROID_ABI not set or not recognized")
endif()

set(ENV{ANDROID_NDK_HOME} ${CMAKE_ANDROID_NDK})
endif()

if(USE_VCPKG)
if(DEFINED ENV{VCPKG_ROOT})
if (CMAKE_TOOLCHAIN_FILE)
Expand Down Expand Up @@ -128,6 +144,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(HOG_NAME "osx")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(HOG_NAME "win")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(HOG_NAME "android")
endif()

# rebuild d3_version.h every time
Expand Down Expand Up @@ -170,6 +188,10 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
message("Building for MAC OSX")
add_compile_definitions(POSIX MACOSX=1 _USE_OGL_ACTIVE_TEXTURES PRIMARY_HOG=\"d3-osx.hog\")
set(PLATFORM_INCLUDES "lib/linux" ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS})
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
message("Building for Android")
add_compile_definitions(POSIX ANDROID _USE_OGL_ACTIVE_TEXTURES PRIMARY_HOG=\"d3-android.hog\")
set(PLATFORM_INCLUDES "lib/linux" ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS})
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
# Windows.h defines to avoid as many issues as possible.
add_compile_definitions(WIN32_LEAN_AND_MEAN NOMINMAX NODRAWTEXT NOBITMAP NOMCX NOSERVICE PRIMARY_HOG=\"d3-win.hog\"
Expand Down Expand Up @@ -275,11 +297,17 @@ endif()

add_subdirectory(Descent3)

if (CMAKE_CROSSCOMPILING)
find_package(HogMaker REQUIRED)
else()
add_subdirectory(tools)
# Always build HogMaker natively. Build it as external project,
include(ExternalProject)
ExternalProject_Add(HogMaker
SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools
BINARY_DIR ${CMAKE_BINARY_DIR}/tools
INSTALL_COMMAND ""
)
if (DEFINED CMAKE_CONFIGURATION_TYPES)
set(HogMakerBin_ConfigDir "$<CONFIG>/")
endif()
set(HogMakerBin ${CMAKE_BINARY_DIR}/tools/${HogMakerBin_ConfigDir}HogMaker)

add_subdirectory(netcon)
add_subdirectory(netgames)
Expand Down
9 changes: 7 additions & 2 deletions Descent3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,13 @@ endif()

file(GLOB_RECURSE INCS "../lib/*.h")

add_executable(Descent3 WIN32 MACOSX_BUNDLE ${D3Icon} ${HEADERS} ${CPPS} ${INCS} ${MANIFEST} ${RC_FILE})
if(ANDROID)
add_library(Descent3 MODULE ${HEADERS} ${CPPS} ${INCS}
)
else()
add_executable(Descent3 WIN32 MACOSX_BUNDLE ${D3Icon} ${HEADERS} ${CPPS} ${INCS} ${MANIFEST} ${RC_FILE})
install(TARGETS Descent3 RUNTIME BUNDLE DESTINATION .)
endif()
target_link_libraries(Descent3 PRIVATE
SDL2::SDL2
2dlib
Expand Down Expand Up @@ -362,7 +368,6 @@ add_dependencies(Descent3
tanarchy
)

install(TARGETS Descent3 RUNTIME BUNDLE DESTINATION .)
if(MSVC)
install(FILES $<TARGET_PDB_FILE:Descent3> DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
Expand Down
52 changes: 52 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apply plugin: 'com.android.application'

repositories {
mavenCentral()
}

android {
namespace "com.descent3.droid"
compileSdk 34
defaultConfig {
minSdkVersion 32
targetSdkVersion 34
versionCode 1
versionName "1.0"
externalNativeBuild {
cmake {
arguments "-DANDROID_APP_PLATFORM=android-19", "-DANDROID_STL=c++_static", "-DENABLE_LOGGER=ON"
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
abiFilters 'arm64-v8a'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
applicationVariants.all { variant ->
tasks["merge${variant.name.capitalize()}Assets"]
.dependsOn("externalNativeBuild${variant.name.capitalize()}")
}
sourceSets {
main {
jniLibs.srcDir 'libs'
java.srcDirs = ['src/main/java']
}
}
externalNativeBuild {
cmake {
path '../CMakeLists.txt'
}
}
lint {
abortOnError false
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'org.nanohttpd:nanohttpd:2.2.0'
}
17 changes: 17 additions & 0 deletions android/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in [sdk]/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:
tophyr marked this conversation as resolved.
Show resolved Hide resolved

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
97 changes: 97 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?><!-- Replace com.test.game with the identifier of your game below, e.g.
com.gamemaker.game
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto"
android:versionCode="1"
android:versionName="devel">

<!-- OpenGL ES 3.2 -->
<uses-feature
android:glEsVersion="0x00030002"
android:required="true" />

<!-- Touchscreen support -->
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />

<!-- Game controller support -->
<uses-feature
android:name="android.hardware.bluetooth"
android:required="false" />
<uses-feature
android:name="android.hardware.gamepad"
android:required="false" />
<uses-feature
android:name="android.hardware.usb.host"
android:required="false" />

<!-- External mouse input events -->
<uses-feature
android:name="android.hardware.type.pc"
android:required="false" />

<!-- Audio recording support -->
<!-- if you want to capture audio, uncomment this. -->
<!-- <uses-feature
android:name="android.hardware.microphone"
android:required="false" /> -->
<!-- <uses-permission android:name="android.permission.RECORD_AUDIO" /> -->

<!-- Allow access to Bluetooth devices -->
<!-- Currently this is just for Steam Controller support and requires setting SDL_HINT_JOYSTICK_HIDAPI_STEAM -->
<!-- <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" /> -->
<!-- <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> -->

<!-- Allow access to the vibrator -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />

<!-- Create a Java class extending SDLActivity and place it in a
directory under app/src/main/java matching the package, e.g. app/src/main/java/com/gamemaker/game/MyGame.java

then replace "SDLActivity" with the name of your class (e.g. "MyGame")
in the XML below.

An example Java class can be found in README-android.md
-->
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

<!-- Example of setting SDL hints from AndroidManifest.xml:
<meta-data android:name="SDL_ENV.SDL_ACCELEROMETER_AS_JOYSTICK" android:value="0"/>
-->

<activity
android:name="MainActivity"
android:alwaysRetainTaskState="true"
android:screenOrientation="sensorLandscape"
android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:preferMinimalPostProcessing="true"
tools:ignore="DiscouragedApi">

<!-- Let Android know that we can handle some USB devices and should receive this event -->
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.descent3.droid.GameDataUploadActivity"
android:exported="true" />
</application>

</manifest>
10 changes: 10 additions & 0 deletions android/src/main/assets/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.title {
font-size: 24pt;
text-align: center;
}
.dir_select {
margin: 12pt;
border: 2pt solid black;
padding: 12pt;
text-align: center;
}
7 changes: 7 additions & 0 deletions android/src/main/assets/errors/400_no_d3hog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head><title>Not Found</title></head>
<body>
<h1 style="text-align: center;">Bad Request</h1>
<h3 style="text-align: center;">d3.hog not found in upload</h3>
</body>
</html>
6 changes: 6 additions & 0 deletions android/src/main/assets/errors/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<head><title>Not Found</title></head>
<body>
<h1 style="text-align: center;">Not Found</h1>
</body>
</html>
6 changes: 6 additions & 0 deletions android/src/main/assets/errors/405.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<head><title>Method Not Allowed</title></head>
<body>
<h1 style="text-align: center;">Method Not Allowed</h1>
</body>
</html>
6 changes: 6 additions & 0 deletions android/src/main/assets/errors/501.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<head><title>Not Implemented</title></head>
<body>
<h1 style="text-align: center;">Not Implemented</h1>
</body>
</html>
16 changes: 16 additions & 0 deletions android/src/main/assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html>
<head>
<link href="css/style.css" rel="stylesheet"/>
<script src="js/jquery-3.7.1.js" type="text/javascript"></script>
tophyr marked this conversation as resolved.
Show resolved Hide resolved
<script src="js/main.js" type="text/javascript"></script>
<title>Upload Game Data</title>
</head>
<body>
<div class="title">Upload Game Data</div>
<form action="" class="dir_select" enctype="multipart/form-data" method="post">
Upload Descent 3 Game Data:
<input id="file" mozdirectory name="file" type="file" webkitdirectory/>
<input id="submit" type="submit"/>
</form>
</body>
</html>
Loading
Loading