How do I publish an Android app in VS2022? I've started with the "Android Application (Preview)" template. It all runs fine in emulator. When clicking publish on the project only a *.nupgk is created. When clicking "View archives..." solution shows up but the only text is "No archive builds available" and I don't see any option to create one.
Edit: By publish I mean create *.apk that could be installed. I have no need to publish to Google Play or any other store.
CodePudding user response:
As pointed out in the comments, I have been playing with this and I always got all the things complete and create some content, but not quite yet.
First; this is not possible at the time or writing from the UI. Of course this will be before .NET MAUI will be released, but for the time being you'll need the command-line, specifically dotnet publish
.
You've already figured out that this command typically is used to create a nupkg, but to unify all the things, this is now also going to be used to publish your .NET MAUI apps.
The problem is that we now have a single-project that can be used for all kinds of targets: iOS, Android, Windows, macOs, so how do we know what dotnet publish
should publish?
You'll need to specify the target framework. For Android that brings us to this:
dotnet publish -f:net6.0-android -c:Release
This should produce an APK that you can use. The one thing I'm not sure about yet is how to add your keystore file in the mix and actually sign it properly for use in the Play Store.
To make things complete, for iOS the command and process is a bit more complicated. The command, from Windows, would look more like this:
dotnet publish -f:net6.0-ios -c:Release /p:ServerAddress=192.168.1.77 /p:ServerUser=jfversluis /p:TcpPort=58181 /p:ArchiveOnBuild=true /p:_DotNetRootRemoteDirectory=/Users/{your username}/Library/Caches/Xamarin/XMA/SDKs/dotnet/
There are a couple of parameters that are only needed when you build from Windows: /p:ServerAddress={Mac build host IP address} /p:ServerUser={Mac username} /p:TcpPort=58181
if you have never connected to this build host you should also add /p:ServerPassword={your password}
. However, you could just go into Visual Studio, connect to the build host from there once and you'll know the connection works and the omit the password parameter. More on the Mac build host functionalities is here.
But we're not there yet! In the csproj
file we need to add a little piece to add the RuntimeIdentifier
and a couple of things to make the signing of the IPA file work.
<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
<CodesignEntitlement>Entitlements.plist</CodesignEntitlement>
<CodesignKey>Apple Development: Gerald Versluis (BLABLAID)</CodesignKey>
<CodesignProvision>VS: WildCard Development</CodesignProvision>
</PropertyGroup>
The Entitlements.plist
file is not part of the default templates (yet) so just take one from a Xamarin.Forms project, it can be the default one or, of course, configure it if you actually need it, but it seems you need it to be there either way.
The values for the code signing you need to get from the Apple certificates stuff. This is the part I'm not completely clear on yet as well. More info on code signing and provisioning is here, that might help get you further.
For the iOS command, also have a look at the backstory here. As seen in this link, you might also need to delete the LaunchScreen.xib
file from the Platforms/iOS/Resources
folder and potentially include the /p:EnableAssemblyILStripping=false
flag to the publish command to work around some bugs. Both of them are fixed but not yet released.
Disclaimer: I haven't published anything to a store yet so there might be gaps here, feel free to add some comments with your findings.