Skip to content

Commit

Permalink
Add Android support
Browse files Browse the repository at this point in the history
  • Loading branch information
tophyr committed Dec 31, 2024
1 parent 0c8df07 commit b0b5b3a
Show file tree
Hide file tree
Showing 38 changed files with 17,260 additions and 1 deletion.
18 changes: 17 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
cc: gcc
cxx: g++++
name: Linux-cross-arm64
- runner: ubuntu-latest
name: android
build_type:
- Debug
- Release
Expand Down Expand Up @@ -102,29 +104,43 @@ jobs:
with:
vcpkgJsonGlob: vcpkg.json

- 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 cross-compiled build
if: ${{ matrix.os.preset == 'linux-cross-arm64' }}
run: |
cmake --preset linux-cross-arm64 -DBUILD_TESTING=OFF -DENABLE_LOGGER=ON -DFORCE_PORTABLE_INSTALL=ON -DBUILD_EDITOR=OFF -DUSE_EXTERNAL_PLOG=ON
- name: Configure CMake
if: ${{ matrix.os.name != 'android' }}
env:
CC: ${{ matrix.os.cc }}
CXX: ${{ matrix.os.cxx }}
run: cmake --preset ${{ matrix.os.preset }} -DENABLE_LOGGER=ON -DFORCE_PORTABLE_INSTALL=ON -DUSE_EXTERNAL_PLOG=ON -DBUILD_EDITOR=${{ matrix.os.preset == "linux-cross-arm64" && "OFF" || "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
16 changes: 16 additions & 0 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
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:

# 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 *;
#}
93 changes: 93 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?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"
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.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: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">

<!-- 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>
<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

0 comments on commit b0b5b3a

Please sign in to comment.