Android set up for Stride 4.1.0.1822 #1657
Krysthalez
started this conversation in
Contributors
Replies: 3 comments 5 replies
-
This is really helpful, thanks! |
Beta Was this translation helpful? Give feedback.
1 reply
-
Shall this be included in Manual? |
Beta Was this translation helpful? Give feedback.
4 replies
-
Just for a reference. An issues was created in the Stride Docs stride3d/stride-docs#107 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Before you start: Please keep in mind that this is the barebones of what is needed to get this to work. In no way is this perfect code or a finished approach. It simply shows you what you have to do, to get Stride(4.1.0.1822) to build for and run on the current Android platform. I just code for a hobby and lack knowledge and skills. You could say I don't know what the heck I am doing, so don't expect this code to be free of mistakes. 😆
That being said, I will try to answer any questions and try to help anyone to the best of my ability. If you need help or have feedback, feel free to ping me in Discord in #troubleshooting (My server profile is Miki).
1. Make sure you have installed all prerequisites
1.1 - You can find more info about those here: https://doc.stride3d.net/4.1/en/manual/requirements/
Although there it says "Visual Studio 2019", I installed VS2022.
1.2 - As well as info on how to install the Xamarin requirements for Android projects.
Here is the link: https://learn.microsoft.com/en-us/xamarin/get-started/installation/?view=vs-2022&pivots=windows-vs2022
1.3 - One thing that confused me quite a bit is, it seems you need to run a "dotnet workload", to install the Android workload. You need to find out your precise net6 version. Go to "C:\Program Files\dotnet\sdk" and find the 6.x.xxx folder. For me it is "6.0.405". Open CMD and run "dotnet workload install android --sdk-version 6.0.405", replacing the version number with the one you have installed.
Note: For me it always tried to install the workload for net7, even with the --sdk-version keyword, so I just went to "C:\Program Files\dotnet\sdk" and deleted all folders, except the "6.0.405" one, then I ran "dotnet workload install android" in CMD and it finally installed it for net6. You can either do this and reinstall the deleted SDKs or you move those folders temporarily, install the workload and then move them back.
Besides that, I also had a little chaos of installations, so I uninstalled Visual Studio 2019, 2022 and the building tools and reinstalled Visual Studio 2022 only. The building tools are meant to install dependencies and frameworks without installing VS and I have had issues with that installation.
Also, make sure to mark Xamarin for installation, just like in Microsoft's documentation; it is not installed by default (anymore).
2. Install Stride (4.1.0.1822)
2.1 - 4.1.0.1822 is the version I have currently installed and I got Android to run the app with. Just for reference, if you ever find yourself having issues with other 4.1.X.XXXX versions.
2.2 - Open Stride
and install the Visual Studio extension (for VS2022). I don't know if this is required, but I did this, so I am including it here.Simba said: "[...] I believe the Stride extension for VS2022 is just for the shader language support. Still handy but not crucial as far as I know."3. Create a "New game" project
3.1 - Start Stride from the Stride Launcher. (Big red button that says "Start 4.1.0.1822")
3.2 - In the "Project selection" window, that opened, click on "New project" or "General".
3.3 - Choose "New game", obviously give it a location and a name and create it. For this documentation I will call the project "AndroidFix".
3.4 - In the now open window "Create a game..." tick the box for "Android", so it is included as a platform for this project
Of course you can choose more platforms here, these instructions are about how to get Stride to build for and run on Android.
3.5 - You can leave everything else as it is, but I personally chose "Direct3D 9.1 / OpenGL ES 2.0" for rendering, to have the lowest possible hardware requirements and of course you can choose your screen orientation here.
3.6 - Click "OK" to create the project.
At this step, there should NOT be any errors! It should run through a few things (only white text, no red text) and open up Stride's editor.
4. Disable the splash screen
4.1 - Within Stride you should find a "Solution explorer". Find the Folder "AndroidFix/Assets" and click on it.
4.2 - Now right next to it, there should be the "Asset view". In there, click on the file named "GameSettings".
4.3 - In the "Property grid" on the top right, you should now have various options, one of which is "Splash screen". Here you find a variable named "Texture". Under its corresponding name, there is one little hand symbol and one little eraser symbol. Click the eraser to clear the reference (deactivate the splash screen).
4.4 - Save (or press CTRL + S) and build the project within Stride (or press F6).
5. Implement Android runtime permission checking and requesting
5.1 - Open the projects folder and open up "AndroidFix.sln" in VS2022 (or you know, click the "Open IDE" button in Stride 😆)
5.2 - In the Solution Explorer, find "AndroidFix.Android/AndroidFixActivity.cs" and open it.
5.3 - Add this private static int to your "public class AndroidFixActivity":
Apparently Android uses a "Request Code", to be able to match requests later on and it seems that you have to use one. That is why I just always use the same number. I think in this case it might be fine, but you might have to id your requests eventually, for more complicated use cases.
5.4 - Add this void method to your "public class AndroidFixActivity":
There is different ways to close an application in C#, this is just what I know and it seems to work fine. I think for Android specifically you could also use this instead:
5.5 - Install the NuGet package "Xamarin.AndroidX.Core" (or use IntelliSense) and add this overwrite method to your "public class AndroidFixActivity":
Now, in theory this override is optional at this time. It is pretty useful though and eventually it might be necessary for certain logic.
5.6 - Also add this overwrite method to your "public class AndroidFixActivity":
Here you have to add all the permissions, that you need to request for your app.
5.7 - Again in the Solution Explorer, find "AndroidFix.Android/AndroidManifest.xml" and open it.
5.8 - Just replace or complete the content of the Android manifest with the following:
Again, here you have to make sure to add the permissions that you need to request. You should be able to recognize the 4 permissions we are checking and requesting at runtime in the "protected override void OnCreate". Be sure that your manifest and code request the same permissions.
6. Build and deploy the app
This is all that is needed to get a freshly created Stride project to run.
Now you should be able select the "AndroidFix.Android" project as startup project in the debugging toolbar, select a physical device and start. Emulated phones don't seem to work. VS should now build and deploy the app! 🥳
The finished "AndroidFix" project, that I created for this little tutorial, can be cloned from here:
http://server.actualcommunity.net:48249/Bonobo.Git.Server/AndroidFix.git
Here is an article on how to add a physical phone for debugging: https://learn.microsoft.com/en-us/dotnet/maui/android/device/setup?view=net-maui-7.0
If there is an error about a file already being used by another process, switch the Release/Debug mode a couple of times and it should work.
Unfortunately I don't know if there is a fix for this, but sometimes it just happens; that is all I know. Sometimes it also worked to close VS and open it again. Simba said: "This happens to me if I try to run the game from the Gamestudio after I had previously run it from VS2022, the solution for me is to only run from VS2022."
Beta Was this translation helpful? Give feedback.
All reactions