From fb74af14812b9cdc6ac41305e384c8a14fd9dd45 Mon Sep 17 00:00:00 2001 From: hwsmm Date: Mon, 15 Apr 2024 23:01:33 +0900 Subject: [PATCH] Add SDL3-CS-Android and workflow --- .github/workflows/build.yml | 67 ++++++++++++++++++++ SDL3-CS-Android/Additions/AboutAdditions.txt | 48 ++++++++++++++ SDL3-CS-Android/SDL3-CS-Android.csproj | 18 ++++++ SDL3-CS-Android/Transforms/EnumFields.xml | 14 ++++ SDL3-CS-Android/Transforms/EnumMethods.xml | 13 ++++ SDL3-CS-Android/Transforms/Metadata.xml | 14 ++++ SDL3-CS.sln | 25 +++++--- 7 files changed, 191 insertions(+), 8 deletions(-) create mode 100644 SDL3-CS-Android/Additions/AboutAdditions.txt create mode 100644 SDL3-CS-Android/SDL3-CS-Android.csproj create mode 100644 SDL3-CS-Android/Transforms/EnumFields.xml create mode 100644 SDL3-CS-Android/Transforms/EnumMethods.xml create mode 100644 SDL3-CS-Android/Transforms/Metadata.xml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d5c75f6..ddde5b8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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' diff --git a/SDL3-CS-Android/Additions/AboutAdditions.txt b/SDL3-CS-Android/Additions/AboutAdditions.txt new file mode 100644 index 0000000..2775bd3 --- /dev/null +++ b/SDL3-CS-Android/Additions/AboutAdditions.txt @@ -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; } +} \ No newline at end of file diff --git a/SDL3-CS-Android/SDL3-CS-Android.csproj b/SDL3-CS-Android/SDL3-CS-Android.csproj new file mode 100644 index 0000000..c304bdd --- /dev/null +++ b/SDL3-CS-Android/SDL3-CS-Android.csproj @@ -0,0 +1,18 @@ + + + net8.0-android + 21 + SDL3_CS_Android + enable + enable + + + + + + + + + + + \ No newline at end of file diff --git a/SDL3-CS-Android/Transforms/EnumFields.xml b/SDL3-CS-Android/Transforms/EnumFields.xml new file mode 100644 index 0000000..2295995 --- /dev/null +++ b/SDL3-CS-Android/Transforms/EnumFields.xml @@ -0,0 +1,14 @@ + + + \ No newline at end of file diff --git a/SDL3-CS-Android/Transforms/EnumMethods.xml b/SDL3-CS-Android/Transforms/EnumMethods.xml new file mode 100644 index 0000000..49216c6 --- /dev/null +++ b/SDL3-CS-Android/Transforms/EnumMethods.xml @@ -0,0 +1,13 @@ + + + \ No newline at end of file diff --git a/SDL3-CS-Android/Transforms/Metadata.xml b/SDL3-CS-Android/Transforms/Metadata.xml new file mode 100644 index 0000000..6105866 --- /dev/null +++ b/SDL3-CS-Android/Transforms/Metadata.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/SDL3-CS.sln b/SDL3-CS.sln index 98f5ca6..6b4a898 100644 --- a/SDL3-CS.sln +++ b/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