question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.NET MAUI Android target publishing/archiving

See original GitHub issue

TL;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

Also See

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:29 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
jonathanpepperscommented, Jan 31, 2022

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:

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <AndroidKeyStore>True</AndroidKeyStore>
    <AndroidSigningKeyStore>filename.keystore</AndroidSigningKeyStore>
    <AndroidSigningStorePass>keystore.filename password</AndroidSigningStorePass>
    <AndroidSigningKeyAlias>keystore.alias</AndroidSigningKeyAlias>
    <AndroidSigningKeyPass>keystore.alias password</AndroidSigningKeyPass>
</PropertyGroup

Then you just dotnet build -c Release and use the .aab file that pops out?

Read more comments on GitHub >

github_iconTop Results From Across the Web

NET MAUI Android target publishing/archiving
NET Multi-platform App UI, a framework for building native device applications spanning ... NET MAUI Android target publishing/archiving · dotnet/maui@9e46f20.
Read more >
Unable to Archive .NET MAUi app - Microsoft Q&A
I am trying to Publish both iOS and Android but during the Archive I ma getting this error. 0 votes
Read more >
Create a Signed and Publishable .NET MAUI Android App in ...
NET MAUI Repo Android Publishing/Archiving Issue: ... NET MAUI Android App 00:18 - What is a Keystore File?! 02:15 - Creating a Keystore ......
Read more >
Publish an Android app using the command line - .NET MAUI
Learn how to publish and sign a .NET MAUI Android app using the command line.
Read more >
NET MAUI Evaluation
NET MAUI iOS target publishing/archiving” at https://github.com/dotnet/maui/issues/4397; The issue around the trouble setting up Apple ID in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found