Skip to content

Commit

Permalink
Add Gradle build for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
tophyr committed Jun 26, 2024
1 parent 8207755 commit dc01dfb
Show file tree
Hide file tree
Showing 30 changed files with 6,182 additions and 0 deletions.
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
@@ -1,5 +1,21 @@
cmake_minimum_required(VERSION 3.20) # For using CMAKE_<LANG>_BYTE_ORDER

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 (NOT DEFINED ENV{VCPKG_ROOT})
message(FATAL_ERROR "
Please set an environment variable VCPKG_ROOT
Expand Down
63 changes: 63 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apply plugin: 'com.android.application'

def hostBuildDir = new File(rootProject.buildDir, "host")
task configureHostTools(type: Exec) {
workingDir ".."
commandLine "cmake", "-B", hostBuildDir, "-G", "Ninja Multi-Config", "-DHOST_TOOLS_ONLY=1"
// intentionally do not track inputs/outputs - let cmake figure that out.
}
["Debug", "RelWithDebInfo"].each { buildConfig ->
def buildHostToolsTask = tasks.register('buildHostTools' + buildConfig, Exec) {
workingDir ".."
commandLine "cmake", "--build", hostBuildDir, "--target", "HogMaker", "--config", buildConfig
dependsOn configureHostTools
// intentionally do not track inputs/outputs - let cmake figure that out.
}
preBuild.dependsOn buildHostToolsTask
}

android {
namespace "com.descent3.droid"
compileSdkVersion 32
defaultConfig {
minSdkVersion 32
targetSdkVersion 32
versionCode 1
versionName "1.0"
externalNativeBuild {
cmake {
arguments "-DANDROID_APP_PLATFORM=android-19", "-DANDROID_STL=c++_static", "-DHogMaker_DIR=" + hostBuildDir
// 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')
}
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 *;
#}
86 changes: 86 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?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:versionCode="1"
android:versionName="devel"
android:installLocation="auto">

<!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" />

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

<!-- 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:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="true"
android:theme="@style/AppTheme"
android:hardwareAccelerated="true" >

<!-- 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:label="@string/app_name"
android:alwaysRetainTaskState="true"
android:launchMode="singleInstance"
android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
android:preferMinimalPostProcessing="true"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- 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>
</activity>
</application>

</manifest>
18 changes: 18 additions & 0 deletions android/src/main/java/com/descent3/droid/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.descent3.droid;

import org.libsdl.app.SDLActivity;

public class MainActivity extends SDLActivity {
@Override
protected String[] getLibraries() {
return new String[] {
"SDL2",
"Descent3",
};
}

@Override
protected String[] getArguments() {
return super.getArguments();
}
}
22 changes: 22 additions & 0 deletions android/src/main/java/org/libsdl/app/HIDDevice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.libsdl.app;

import android.hardware.usb.UsbDevice;

interface HIDDevice
{
public int getId();
public int getVendorId();
public int getProductId();
public String getSerialNumber();
public int getVersion();
public String getManufacturerName();
public String getProductName();
public UsbDevice getDevice();
public boolean open();
public int sendFeatureReport(byte[] report);
public int sendOutputReport(byte[] report);
public boolean getFeatureReport(byte[] report);
public void setFrozen(boolean frozen);
public void close();
public void shutdown();
}
Loading

0 comments on commit dc01dfb

Please sign in to comment.