mirror of https://github.com/ppy/SDL3-CS.git
Merge pull request #24 from hwsmm/android
Add an Android bindings project
This commit is contained in:
commit
98f308f03d
|
|
@ -165,3 +165,70 @@ jobs:
|
|||
path: 'SDL3-CS'
|
||||
env:
|
||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
|
||||
|
||||
build-android:
|
||||
name: android
|
||||
runs-on: ubuntu-20.04
|
||||
env:
|
||||
NDK_VER: 23.1.7779620
|
||||
PLATFORM_VER: android-34
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: 'libsdl-org/SDL'
|
||||
ref: 'main'
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
path: 'SDL3-CS'
|
||||
|
||||
- name: Setup JDK
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: microsoft
|
||||
java-version: |
|
||||
11
|
||||
17
|
||||
|
||||
- name: Install Android SDK Manager
|
||||
uses: android-actions/setup-android@v3
|
||||
with:
|
||||
packages: ''
|
||||
|
||||
- name: Install Android SDK
|
||||
run: |
|
||||
sdkmanager --install "platform-tools" "platforms;$PLATFORM_VER"
|
||||
sdkmanager --install "ndk;$NDK_VER" --channel=3
|
||||
|
||||
- name: Build (Android)
|
||||
run: |
|
||||
export PATH=$ANDROID_HOME/ndk/$NDK_VER:$PATH
|
||||
export OUTPUT=$PWD/SDL3-CS/native/android
|
||||
rm -rf $OUTPUT && mkdir -p $OUTPUT
|
||||
|
||||
# Build SDL3
|
||||
sed -i 's/abi=.*/abi="armeabi-v7a arm64-v8a x86 x86_64"/g' ./build-scripts/androidbuildlibs.sh
|
||||
./build-scripts/androidbuildlibs.sh NDK_LIBS_OUT="$OUTPUT"
|
||||
|
||||
- name: Build SDL3 Android Java
|
||||
run: |
|
||||
export JAVA_HOME=$JAVA_HOME_11_X64
|
||||
export PATH=$JAVA_HOME_11_X64/bin:$PATH
|
||||
export OUTPUT=$PWD/SDL3-CS/SDL3-CS-Android/Jars/
|
||||
rm -rf $OUTPUT && mkdir -p $OUTPUT
|
||||
|
||||
# Build SDL3 Android Java part
|
||||
cd android-project/app/src/main/java
|
||||
javac -cp $ANDROID_HOME/platforms/$PLATFORM_VER/android.jar -encoding utf8 org/libsdl/app/*.java
|
||||
jar cvf $OUTPUT/SDL3AndroidBridge.jar org/libsdl/app/*.class
|
||||
|
||||
- name: Create pull request
|
||||
uses: peter-evans/create-pull-request@v6
|
||||
with:
|
||||
commit-message: Update Android SDL binaries
|
||||
title: Update Android SDL binaries
|
||||
body: This PR has been auto-generated to update the Android SDL binaries
|
||||
branch: update-android-binaries
|
||||
path: 'SDL3-CS'
|
||||
env:
|
||||
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
Additions allow you to add arbitrary C# to the generated classes
|
||||
before they are compiled. This can be helpful for providing convenience
|
||||
methods or adding pure C# classes.
|
||||
|
||||
== Adding Methods to Generated Classes ==
|
||||
|
||||
Let's say the library being bound has a Rectangle class with a constructor
|
||||
that takes an x and y position, and a width and length size. It will look like
|
||||
this:
|
||||
|
||||
public partial class Rectangle
|
||||
{
|
||||
public Rectangle (int x, int y, int width, int height)
|
||||
{
|
||||
// JNI bindings
|
||||
}
|
||||
}
|
||||
|
||||
Imagine we want to add a constructor to this class that takes a Point and
|
||||
Size structure instead of 4 ints. We can add a new file called Rectangle.cs
|
||||
with a partial class containing our new method:
|
||||
|
||||
public partial class Rectangle
|
||||
{
|
||||
public Rectangle (Point location, Size size) :
|
||||
this (location.X, location.Y, size.Width, size.Height)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
At compile time, the additions class will be added to the generated class
|
||||
and the final assembly will a Rectangle class with both constructors.
|
||||
|
||||
|
||||
== Adding C# Classes ==
|
||||
|
||||
Another thing that can be done is adding fully C# managed classes to the
|
||||
generated library. In the above example, let's assume that there isn't a
|
||||
Point class available in Java or our library. The one we create doesn't need
|
||||
to interact with Java, so we'll create it like a normal class in C#.
|
||||
|
||||
By adding a Point.cs file with this class, it will end up in the binding library:
|
||||
|
||||
public class Point
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-android</TargetFramework>
|
||||
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
|
||||
<RootNamespace>SDL3_CS_Android</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedJar Include="Jars\SDL3AndroidBridge.jar" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedNativeLibrary Include="..\native\android\armeabi-v7a\libSDL3.so" />
|
||||
<EmbeddedNativeLibrary Include="..\native\android\arm64-v8a\libSDL3.so" />
|
||||
<EmbeddedNativeLibrary Include="..\native\android\x86\libSDL3.so" />
|
||||
<EmbeddedNativeLibrary Include="..\native\android\x86_64\libSDL3.so" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<enum-field-mappings>
|
||||
<!--
|
||||
This example converts the constants Fragment_id, Fragment_name,
|
||||
and Fragment_tag from android.support.v4.app.FragmentActivity.FragmentTag
|
||||
to an enum called Android.Support.V4.App.FragmentTagType with values
|
||||
Id, Name, and Tag.
|
||||
|
||||
<mapping jni-class="android/support/v4/app/FragmentActivity$FragmentTag" clr-enum-type="Android.Support.V4.App.FragmentTagType">
|
||||
<field jni-name="Fragment_name" clr-name="Name" value="0" />
|
||||
<field jni-name="Fragment_id" clr-name="Id" value="1" />
|
||||
<field jni-name="Fragment_tag" clr-name="Tag" value="2" />
|
||||
</mapping>
|
||||
-->
|
||||
</enum-field-mappings>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<enum-method-mappings>
|
||||
<!--
|
||||
This example changes the Java method:
|
||||
android.support.v4.app.Fragment.SavedState.writeToParcel (int flags)
|
||||
to be:
|
||||
android.support.v4.app.Fragment.SavedState.writeToParcel (Android.OS.ParcelableWriteFlags flags)
|
||||
when bound in C#.
|
||||
|
||||
<mapping jni-class="android/support/v4/app/Fragment.SavedState">
|
||||
<method jni-name="writeToParcel" parameter="flags" clr-enum-type="Android.OS.ParcelableWriteFlags" />
|
||||
</mapping>
|
||||
-->
|
||||
</enum-method-mappings>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<metadata>
|
||||
<remove-node
|
||||
path="/api/package[@name='org.libsdl.app']/class[@name='SDLActivity']/field[@name='mClipboardHandler']"/>
|
||||
<remove-node
|
||||
path="/api/package[@name='org.libsdl.app']/class[@name='SDLActivity']/field[@name='mMotionListener']"/>
|
||||
<remove-node
|
||||
path="/api/package[@name='org.libsdl.app']/class[@name='SDLActivity']/field[@name='mTextEdit']"/>
|
||||
<remove-node
|
||||
path="/api/package[@name='org.libsdl.app']/class[@name='SDLActivity']/method[@name='getMotionListener' and count(parameter)=0]"/>
|
||||
<remove-node
|
||||
path="/api/package[@name='org.libsdl.app']/class[@name='SDLControllerManager']/field[@name='mHapticHandler']"/>
|
||||
<remove-node
|
||||
path="/api/package[@name='org.libsdl.app']/class[@name='SDLControllerManager']/field[@name='mJoystickHandler']"/>
|
||||
</metadata>
|
||||
25
SDL3-CS.sln
25
SDL3-CS.sln
|
|
@ -6,27 +6,26 @@ MinimumVisualStudioVersion = 10.0.40219.1
|
|||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{18C20490-AA42-464A-BBC4-7B6CF63B91DE}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.editorconfig = .editorconfig
|
||||
.gitignore = .gitignore
|
||||
.globalconfig = .globalconfig
|
||||
Directory.Build.props = Directory.Build.props
|
||||
global.json = global.json
|
||||
.config\dotnet-tools.json = .config\dotnet-tools.json
|
||||
.gitignore = .gitignore
|
||||
global.json = global.json
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDL3-CS", "SDL3-CS\SDL3-CS.csproj", "{3AEE5979-6974-4BD6-9BB1-1409B0BB469B}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL3-CS", "SDL3-CS\SDL3-CS.csproj", "{3AEE5979-6974-4BD6-9BB1-1409B0BB469B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDL3-CS.SourceGeneration", "SDL3-CS.SourceGeneration\SDL3-CS.SourceGeneration.csproj", "{432C86D0-D371-4D01-BFFE-01D2CDCCA7B8}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL3-CS.SourceGeneration", "SDL3-CS.SourceGeneration\SDL3-CS.SourceGeneration.csproj", "{432C86D0-D371-4D01-BFFE-01D2CDCCA7B8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDL3-CS.Tests", "SDL3-CS.Tests\SDL3-CS.Tests.csproj", "{CF980481-8227-4BED-970E-6433C83F64CB}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL3-CS.Tests", "SDL3-CS.Tests\SDL3-CS.Tests.csproj", "{CF980481-8227-4BED-970E-6433C83F64CB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDL3-CS-Android", "SDL3-CS-Android\SDL3-CS-Android.csproj", "{CA28F49C-D0BE-47D6-9E82-7A0B8C380B8B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{3AEE5979-6974-4BD6-9BB1-1409B0BB469B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3AEE5979-6974-4BD6-9BB1-1409B0BB469B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
|
|
@ -40,5 +39,15 @@ Global
|
|||
{CF980481-8227-4BED-970E-6433C83F64CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CF980481-8227-4BED-970E-6433C83F64CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CF980481-8227-4BED-970E-6433C83F64CB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CA28F49C-D0BE-47D6-9E82-7A0B8C380B8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CA28F49C-D0BE-47D6-9E82-7A0B8C380B8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CA28F49C-D0BE-47D6-9E82-7A0B8C380B8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CA28F49C-D0BE-47D6-9E82-7A0B8C380B8B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {19F716B7-F795-4152-A923-B8750DDBAB4E}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
namespace SDL
|
||||
{
|
||||
public partial class SDL3
|
||||
{
|
||||
[Macro]
|
||||
public static unsafe bool SDL_QuitRequested()
|
||||
{
|
||||
SDL_PumpEvents();
|
||||
return SDL_PeepEvents(null, 0, SDL_eventaction.SDL_PEEKEVENT, SDL_EventType.SDL_EVENT_QUIT, SDL_EventType.SDL_EVENT_QUIT) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -112,7 +112,6 @@ headers = [
|
|||
add("SDL3/SDL_platform.h"),
|
||||
add("SDL3/SDL_power.h"),
|
||||
add("SDL3/SDL_properties.h"),
|
||||
add("SDL3/SDL_quit.h"),
|
||||
add("SDL3/SDL_rect.h"),
|
||||
add("SDL3/SDL_render.h"),
|
||||
add("SDL3/SDL_revision.h"),
|
||||
|
|
|
|||
Loading…
Reference in New Issue