.NET MAUI Android target publishing/archiving
See original GitHub issueTL;DR
- Archiving and publishing a .NET MAUI Android app (both .NET MAUI and .NET MAUI Blazor) to an aab works. See the steps below.
- I have been able to upload it to the Google Play Store and then download it to test the app. The regular .NET MAUI app works without doing anything special, for .NET MAUI Blazor you need to follow the instructions in this comment. I think for the next preview this should be fixed and working out-of-the-box.
- This is all through the command-line, UI support in Visual Studio is not there (yet)
Description
I have been trying to see if publishing an Android app through .NET MAUI works at the moment. This description assumes that you have basic knowledge of publishing to the Google Play Store.
1. Prerequisites
- All the required tools and bits are installed to create and run .NET MAUI Android apps successfully
- Make sure that your
AndroidManifest.xml
file contains a valid version number and package identifier (i.e.com.mycompany.app
)
2. Create keystore file
This process is no different between Xamarin, Xamarin.Forms, .NET MAUI or even a native app. Run the following command to create a new keystore file. If you already have an existing keystore file, you can skip this step.
Make sure you know where you’re running this command from so you know where the keystore is created. Alternatively, provide a full path for the -keystore
option.
keytool -genkey -v -keystore key.keystore -alias key -keyalg RSA -keysize 2048 -validity 10000
Note: make sure the validity is a high number (number is in days). The Google Play Store will not accept low numbers and if the keystore is expired, you will not be able to upload updates for your app anymore. Also don’t lose your keystore file, you will need that for any updates to your app. Without it, you cannot upload updates to your app.
Make note of the value in -alias
this can be anything, but you will need it later. You will also need to provide a password. Needless to say, you will need that one and need to remember it as well. For detailed instructions, see this existing Docs page.
3. Update your csproj file
We need to add the information we got from above into our csproj file. If you have an existing app, you can potentially copy this from your Android csproj file. The information will look like this, and needs to be contained within the <Project></Project>
node.
<PropertyGroup Condition="$(TargetFramework.Contains('-android')) and '$(Configuration)' == 'Release'">
<AndroidKeyStore>True</AndroidKeyStore>
<AndroidSigningKeyStore>filename.keystore</AndroidSigningKeyStore>
<AndroidSigningStorePass>filename.keystore password</AndroidSigningStorePass>
<AndroidSigningKeyAlias>keystore.alias</AndroidSigningKeyAlias>
<AndroidSigningKeyPass>keystore.alias password</AndroidSigningKeyPass>
</PropertyGroup>
This information will only be added if you are building the Android target and building the release configuration. Tweak this as needed.
I think all the info speaks for itself, add the path to your keystore file along with the alias and corresponding passwords.
4. Build your .NET MAUI Android app
Navigate to the folder that holds the source for your .NET MAUI Android app and execute the following command:
dotnet publish -f:net6.0-android -c:Release
This will create a couple of files under the bin\Release\net6.0-android\publish
folder. There should be a file that will have the name of your package identifier and that mentions “-Signed”. For example, look for: com.mycompany.app-Signed.aab
.
For the Google Play Store you will need the aab file, for other purposes you can use the apk file that is also in there.
Notes
- Instead of specifying all the options in the csproj file, they can also be added to the
dotnet publish
command. E.g.<AndroidSigningKeyPass>mypassword</AndroidSigningKeyPass>
would become/p:AndroidSigningKeyPass=mypassword
.
Related Resources
- https://docs.microsoft.com/xamarin/android/deploy-test/signing/manually-signing-the-apk
- https://stackoverflow.com/questions/70437037/net-6-publishing-android-application
- https://github.com/dotnet/maui/issues/2246#issuecomment-1022662057
Also See
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:29 (14 by maintainers)
I’m curious, why do you need to run
zipalign
& sign yourself at all?We have MSBuild properties for configuring signing:
https://docs.microsoft.com/en-us/xamarin/android/deploy-test/building-apps/build-process#signing-properties
These are the same in Xamarin.Android and .NET 6.
It seems like you could just use:
Then you just
dotnet build -c Release
and use the.aab
file that pops out?https://github.com/xamarin/xamarin-android/issues/6933