Skip to content

Commit dc01dfb

Browse files
committed
Add Gradle build for Android
1 parent 8207755 commit dc01dfb

30 files changed

+6182
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,10 @@ build[s]
408408

409409
# Ignore autogenerated git-hash.txt file, generated for packaging purposes
410410
git-hash.txt
411+
412+
# Android build bits
413+
.gradle/*
414+
android/.cxx/*
415+
android/build/*
416+
build/*
417+
local.properties

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
cmake_minimum_required(VERSION 3.20) # For using CMAKE_<LANG>_BYTE_ORDER
22

3+
if (CMAKE_SYSTEM_NAME STREQUAL "Android")
4+
if (ANDROID_ABI MATCHES "arm64-v8a")
5+
set(VCPKG_TARGET_TRIPLET "arm64-android" CACHE STRING "" FORCE)
6+
elseif(ANDROID_ABI MATCHES "armeabi-v7a")
7+
set(VCPKG_TARGET_TRIPLET "arm-android" CACHE STRING "" FORCE)
8+
elseif(ANDROID_ABI MATCHES "x86_64")
9+
set(VCPKG_TARGET_TRIPLET "x64-android" CACHE STRING "" FORCE)
10+
elseif(ANDROID_ABI MATCHES "x86")
11+
set(VCPKG_TARGET_TRIPLET "x86-android" CACHE STRING "" FORCE)
12+
else()
13+
message(FATAL_ERROR "ANDROID_ABI not set or not recognized")
14+
endif()
15+
16+
set(ENV{ANDROID_NDK_HOME} ${CMAKE_ANDROID_NDK})
17+
endif()
18+
319
if (NOT DEFINED ENV{VCPKG_ROOT})
420
message(FATAL_ERROR "
521
Please set an environment variable VCPKG_ROOT

android/build.gradle

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
apply plugin: 'com.android.application'
2+
3+
def hostBuildDir = new File(rootProject.buildDir, "host")
4+
task configureHostTools(type: Exec) {
5+
workingDir ".."
6+
commandLine "cmake", "-B", hostBuildDir, "-G", "Ninja Multi-Config", "-DHOST_TOOLS_ONLY=1"
7+
// intentionally do not track inputs/outputs - let cmake figure that out.
8+
}
9+
["Debug", "RelWithDebInfo"].each { buildConfig ->
10+
def buildHostToolsTask = tasks.register('buildHostTools' + buildConfig, Exec) {
11+
workingDir ".."
12+
commandLine "cmake", "--build", hostBuildDir, "--target", "HogMaker", "--config", buildConfig
13+
dependsOn configureHostTools
14+
// intentionally do not track inputs/outputs - let cmake figure that out.
15+
}
16+
preBuild.dependsOn buildHostToolsTask
17+
}
18+
19+
android {
20+
namespace "com.descent3.droid"
21+
compileSdkVersion 32
22+
defaultConfig {
23+
minSdkVersion 32
24+
targetSdkVersion 32
25+
versionCode 1
26+
versionName "1.0"
27+
externalNativeBuild {
28+
cmake {
29+
arguments "-DANDROID_APP_PLATFORM=android-19", "-DANDROID_STL=c++_static", "-DHogMaker_DIR=" + hostBuildDir
30+
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
31+
abiFilters 'arm64-v8a'
32+
}
33+
}
34+
}
35+
buildTypes {
36+
release {
37+
minifyEnabled false
38+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
39+
}
40+
}
41+
applicationVariants.all { variant ->
42+
tasks["merge${variant.name.capitalize()}Assets"]
43+
.dependsOn("externalNativeBuild${variant.name.capitalize()}")
44+
}
45+
sourceSets {
46+
main {
47+
jniLibs.srcDir 'libs'
48+
java.srcDirs = ['src/main/java']
49+
}
50+
}
51+
externalNativeBuild {
52+
cmake {
53+
path '../CMakeLists.txt'
54+
}
55+
}
56+
lint {
57+
abortOnError false
58+
}
59+
}
60+
61+
dependencies {
62+
implementation fileTree(include: ['*.jar'], dir: 'libs')
63+
}

android/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in [sdk]/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}

android/src/main/AndroidManifest.xml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Replace com.test.game with the identifier of your game below, e.g.
3+
com.gamemaker.game
4+
-->
5+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
6+
android:versionCode="1"
7+
android:versionName="devel"
8+
android:installLocation="auto">
9+
10+
<!-- OpenGL ES 2.0 -->
11+
<uses-feature android:glEsVersion="0x00020000" />
12+
13+
<!-- Touchscreen support -->
14+
<uses-feature
15+
android:name="android.hardware.touchscreen"
16+
android:required="false" />
17+
18+
<!-- Game controller support -->
19+
<uses-feature
20+
android:name="android.hardware.bluetooth"
21+
android:required="false" />
22+
<uses-feature
23+
android:name="android.hardware.gamepad"
24+
android:required="false" />
25+
<uses-feature
26+
android:name="android.hardware.usb.host"
27+
android:required="false" />
28+
29+
<!-- External mouse input events -->
30+
<uses-feature
31+
android:name="android.hardware.type.pc"
32+
android:required="false" />
33+
34+
<!-- Audio recording support -->
35+
<!-- if you want to capture audio, uncomment this. -->
36+
<!-- <uses-feature
37+
android:name="android.hardware.microphone"
38+
android:required="false" /> -->
39+
<!-- <uses-permission android:name="android.permission.RECORD_AUDIO" /> -->
40+
41+
<!-- Allow access to Bluetooth devices -->
42+
<!-- Currently this is just for Steam Controller support and requires setting SDL_HINT_JOYSTICK_HIDAPI_STEAM -->
43+
<!-- <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" /> -->
44+
<!-- <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> -->
45+
46+
<!-- Allow access to the vibrator -->
47+
<uses-permission android:name="android.permission.VIBRATE" />
48+
49+
<!-- Create a Java class extending SDLActivity and place it in a
50+
directory under app/src/main/java matching the package, e.g. app/src/main/java/com/gamemaker/game/MyGame.java
51+
52+
then replace "SDLActivity" with the name of your class (e.g. "MyGame")
53+
in the XML below.
54+
55+
An example Java class can be found in README-android.md
56+
-->
57+
<application android:label="@string/app_name"
58+
android:icon="@mipmap/ic_launcher"
59+
android:allowBackup="true"
60+
android:theme="@style/AppTheme"
61+
android:hardwareAccelerated="true" >
62+
63+
<!-- Example of setting SDL hints from AndroidManifest.xml:
64+
<meta-data android:name="SDL_ENV.SDL_ACCELEROMETER_AS_JOYSTICK" android:value="0"/>
65+
-->
66+
67+
<activity android:name="MainActivity"
68+
android:label="@string/app_name"
69+
android:alwaysRetainTaskState="true"
70+
android:launchMode="singleInstance"
71+
android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
72+
android:preferMinimalPostProcessing="true"
73+
android:exported="true"
74+
>
75+
<intent-filter>
76+
<action android:name="android.intent.action.MAIN" />
77+
<category android:name="android.intent.category.LAUNCHER" />
78+
</intent-filter>
79+
<!-- Let Android know that we can handle some USB devices and should receive this event -->
80+
<intent-filter>
81+
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
82+
</intent-filter>
83+
</activity>
84+
</application>
85+
86+
</manifest>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.descent3.droid;
2+
3+
import org.libsdl.app.SDLActivity;
4+
5+
public class MainActivity extends SDLActivity {
6+
@Override
7+
protected String[] getLibraries() {
8+
return new String[] {
9+
"SDL2",
10+
"Descent3",
11+
};
12+
}
13+
14+
@Override
15+
protected String[] getArguments() {
16+
return super.getArguments();
17+
}
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.libsdl.app;
2+
3+
import android.hardware.usb.UsbDevice;
4+
5+
interface HIDDevice
6+
{
7+
public int getId();
8+
public int getVendorId();
9+
public int getProductId();
10+
public String getSerialNumber();
11+
public int getVersion();
12+
public String getManufacturerName();
13+
public String getProductName();
14+
public UsbDevice getDevice();
15+
public boolean open();
16+
public int sendFeatureReport(byte[] report);
17+
public int sendOutputReport(byte[] report);
18+
public boolean getFeatureReport(byte[] report);
19+
public void setFrozen(boolean frozen);
20+
public void close();
21+
public void shutdown();
22+
}

0 commit comments

Comments
 (0)