Native Android with VS Code and .NET6
The .NET 6 team has done another step in the direction of uniforming the processes and tools of writing code for different platforms. Now it is possible to install the stack to compile applications for Android and work with it only via dotnet cli.
Why
Developing cross-platform mobile apps can be done with a large variety of frameworks and tools, but, for native applications (or close-to-native performance), the selection is limited. Xamarin is one of the frameworks that is considered native, and it has evolved a lot over time to stay updated with the latest improvements and features of the mobile OSes.
Up until recently, Xamarin could only be developed with ease in the Visual Studio IDE. The downside is that someone might consider it limiting when it comes to license. On the other hand, VS Code is more widely used by a large group of developers.
The latest version of .NET 6 brought Xamarin inside the dotnet tooling in the form of workload and it’s now possible to get a fully functional development environment, that requires only the dotnet SDK.
What changes
Now it is possible to target Android in a C# project file using the standard SDK project. Here is an example file:
1 | <Project Sdk="Microsoft.NET.Sdk"> |
VS Code setup
- Have VS Code ready
- Install dotnet SDK
- Add dotnet workload for Android
1
dotnet workload install android-aot
- Open the sample project
- Install the extensions
- Start the emulator from the task
Running
- Start the build task
- Select the target
Run
- Wait until the emulator is loaded with the app and it’s showing a white screen
- Attach the debugger to start the application
And more
Another area with huge improvements is binding libraries. Just change <OutputType>Library</OutputType>
and add the jar
or aar
. Add Metadata.xml
if needed. That’s it.
For more information, have a look here.