diff options
author | Lassi Pulkkinen <lassi@pulk.fi> | 2024-10-31 03:11:21 +0200 |
---|---|---|
committer | Lassi Pulkkinen <lassi@pulk.fi> | 2024-10-31 03:51:35 +0200 |
commit | ae44478b30d890fe0fb04022f44d474dcdcc3f9d (patch) | |
tree | 5f462459ae4b47d22114eed717d1382d08cf4dfe /android |
Diffstat (limited to 'android')
-rw-r--r-- | android/build.gradle | 43 | ||||
-rw-r--r-- | android/jni/CMakeLists.txt | 35 | ||||
-rwxr-xr-x | android/jni/as | 11 | ||||
-rw-r--r-- | android/jni/dummy.c | 1 | ||||
-rw-r--r-- | android/jni/main.c | 7 | ||||
-rw-r--r-- | android/settings.gradle | 13 | ||||
-rw-r--r-- | android/src/main/AndroidManifest.xml | 64 | ||||
-rw-r--r-- | android/src/main/java/fi/pulk/hacraft/MainActivity.java | 5 | ||||
-rw-r--r-- | android/src/main/res/values/colors.xml | 6 | ||||
-rw-r--r-- | android/src/main/res/values/strings.xml | 3 | ||||
-rw-r--r-- | android/src/main/res/values/styles.xml | 8 |
11 files changed, 196 insertions, 0 deletions
diff --git a/android/build.gradle b/android/build.gradle new file mode 100644 index 0000000..2eb9c79 --- /dev/null +++ b/android/build.gradle @@ -0,0 +1,43 @@ +plugins { + id 'com.android.application' version '8.1.0' +} + +android { + namespace 'fi.pulk.hacraft' + compileSdk 33 + + defaultConfig { + applicationId 'fi.pulk.hacraft' + versionCode 1 + versionName '1.0' + minSdk 19 + targetSdk 28 + + externalNativeBuild { + cmake { + arguments '-DSDL_ROOT=' + project.property('sdlRoot') + abiFilters 'arm64-v8a', 'x86_64' + } + } + } + + externalNativeBuild { + cmake { + path 'jni/CMakeLists.txt' + } + } + + sourceSets { + main { + java.srcDir project.property('sdlRoot') \ + + '/android-project/app/src/main/java' + } + } + + lintOptions { + // SDL's java shim has unaddressed linter warnings, and this is + // how they deal with them, apparently. *shrug* + // (Based on android-project/app/build.gradle, anyway.) + abortOnError false + } +} diff --git a/android/jni/CMakeLists.txt b/android/jni/CMakeLists.txt new file mode 100644 index 0000000..e291b2d --- /dev/null +++ b/android/jni/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.6) + +project(HACRAFT) + +add_subdirectory(${SDL_ROOT} SDL) + +if(${ANDROID_ABI} STREQUAL arm64-v8a) + set(HARE_TARGET aarch64) +elseif(${ANDROID_ABI} STREQUAL x86_64) + set(HARE_TARGET x86_64) +endif() + +set(LIBMAIN_SO ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libmain.so) + +add_custom_target(compile_main + CC=${CMAKE_C_COMPILER} AS=${CMAKE_CURRENT_SOURCE_DIR}/as + LDFLAGS=--target=${CMAKE_C_COMPILER_TARGET}\ -shared\ ${CMAKE_CURRENT_SOURCE_DIR}/main.c + ASFLAGS=${CMAKE_C_COMPILER}\ ${CMAKE_C_COMPILER_TARGET} + HARECACHE=${CMAKE_CURRENT_BINARY_DIR}/hare + hare build -a ${HARE_TARGET} -T +android + -L${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + -o ${LIBMAIN_SO} + -lc -lSDL2 -v + DEPENDS SDL2 + BYPRODUCTS ${LIBMAIN_SO} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../.. + USES_TERMINAL) + +add_library(main SHARED IMPORTED GLOBAL) +set_target_properties(main PROPERTIES IMPORTED_LOCATION ${LIBMAIN_SO}) +add_dependencies(main compile_main) + +add_library(dummy SHARED) +target_sources(dummy PRIVATE dummy.c) +target_link_libraries(dummy main) diff --git a/android/jni/as b/android/jni/as new file mode 100755 index 0000000..00963ee --- /dev/null +++ b/android/jni/as @@ -0,0 +1,11 @@ +#!/bin/sh + +cc="$1" +target="$2" +out="$4" +shift 4 +( + for f in "$@"; do + cat "$f" + done +) | "$cc" --target="$target" -c -o "$out" -x assembler - diff --git a/android/jni/dummy.c b/android/jni/dummy.c new file mode 100644 index 0000000..698ef4b --- /dev/null +++ b/android/jni/dummy.c @@ -0,0 +1 @@ +/* nothing to C here */ diff --git a/android/jni/main.c b/android/jni/main.c new file mode 100644 index 0000000..606ef7f --- /dev/null +++ b/android/jni/main.c @@ -0,0 +1,7 @@ +void android_main(); + +int +SDL_main(int argc, char **argv) { + android_main(); + return 0; +} diff --git a/android/settings.gradle b/android/settings.gradle new file mode 100644 index 0000000..e8d169c --- /dev/null +++ b/android/settings.gradle @@ -0,0 +1,13 @@ +pluginManagement { + repositories { + mavenCentral() + google() + } +} + +dependencyResolutionManagement { + repositories { + mavenCentral() + google() + } +} diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..5df0531 --- /dev/null +++ b/android/src/main/AndroidManifest.xml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + android:versionCode="1" + android:versionName="1.0" + android:installLocation="auto"> + + <!-- OpenGL ES 3.2 --> + <uses-feature android:glEsVersion="0x00030002"/> + <!-- 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"/> + + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="22"/> + <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30"/> + <uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/> + <uses-permission android:name="android.permission.VIBRATE"/> + <uses-permission android:name="android.permission.INTERNET"/> + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> + + <application android:label="@string/app_name" + android:allowBackup="true" + android:theme="@android:style/Theme.NoTitleBar.Fullscreen" + android:hardwareAccelerated="true"> + <!-- android:icon="@mipmap/ic_launcher" + (2024 note): I removed the icon files since they were + just the default ones that come with SDL. --> + + <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> + <intent-filter> + <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/> + </intent-filter> + + </activity> + + </application> + +</manifest> diff --git a/android/src/main/java/fi/pulk/hacraft/MainActivity.java b/android/src/main/java/fi/pulk/hacraft/MainActivity.java new file mode 100644 index 0000000..f349c9c --- /dev/null +++ b/android/src/main/java/fi/pulk/hacraft/MainActivity.java @@ -0,0 +1,5 @@ +package fi.pulk.hacraft; + +import org.libsdl.app.SDLActivity; + +public class MainActivity extends SDLActivity {} diff --git a/android/src/main/res/values/colors.xml b/android/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/android/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="colorPrimary">#3F51B5</color> + <color name="colorPrimaryDark">#303F9F</color> + <color name="colorAccent">#FF4081</color> +</resources> diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml new file mode 100644 index 0000000..ab79533 --- /dev/null +++ b/android/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ +<resources> + <string name="app_name">Game</string> +</resources> diff --git a/android/src/main/res/values/styles.xml b/android/src/main/res/values/styles.xml new file mode 100644 index 0000000..ff6c9d2 --- /dev/null +++ b/android/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ +<resources> + + <!-- Base application theme. --> + <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> + <!-- Customize your theme here. --> + </style> + +</resources> |