Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Foldable devices with .NET MAUI #956

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ed27864
Foldable initial content
conceptdev Sep 30, 2022
6f22b1a
fix OPS warnings
conceptdev Sep 30, 2022
f3e8fc6
fix OPS warning
conceptdev Sep 30, 2022
714ca39
Foldable add graphic
conceptdev Sep 30, 2022
52b735d
Typo fix - update to GraphicsView article (#994)
mahab339 Oct 12, 2022
083b809
Update code. (#998)
davidbritch Oct 13, 2022
1d7128c
Foldable content move in TOC
conceptdev Oct 14, 2022
81e46b6
Foldable update image syntax
conceptdev Oct 14, 2022
bc7e96d
Merge branch 'net7' into conceptdev-605-foldable
conceptdev Oct 14, 2022
de7137a
"Files should end with a single newline character"
conceptdev Oct 14, 2022
91f8a19
Merge branch 'conceptdev-605-foldable' of https://github.com/dotnet/d…
conceptdev Oct 14, 2022
34994ea
Foldable links to dual-screen docs
conceptdev Oct 14, 2022
770c37e
First pass at some more in-depth articles on publishing win/android (…
adegeo Oct 14, 2022
84582de
Typo fix - update to geometries article (#1005)
mahab339 Oct 15, 2022
45665a5
Add warning about null return value. (#1009)
davidbritch Oct 17, 2022
bf7d6ad
Typo fix - update to shapes article (#1008)
mahab339 Oct 17, 2022
1d80c3e
Typo fix - update to path markup syntax article (#1007)
mahab339 Oct 17, 2022
d7dd182
Fix to error produced from example - update to image article (#1006)
mahab339 Oct 17, 2022
cc0220b
Add checking for emulator updates to troubleshooting (#1003)
adegeo Oct 17, 2022
4868c57
Update image.md (#1014)
tiwahu Oct 21, 2022
19b3aad
versionName is in the manifest node (#1028)
davidbritch Oct 24, 2022
07c93dc
iOS 11 min requirement using Xcode 14 (#1029)
davidbritch Oct 24, 2022
38d1fe0
Remove limitations because OpenGLView doesn't exist in .NET MAUI (#1032)
davidbritch Oct 25, 2022
0b5f83e
Add Mac instructions. (#1034)
davidbritch Oct 25, 2022
ebf612e
VSMac instructions for live visual tree (#1035)
davidbritch Oct 25, 2022
3ef32d5
Add .NET header (#1039)
davidbritch Oct 26, 2022
4840576
Typo fix - update to editor article (#1040)
mahab339 Oct 28, 2022
e378bb0
Update blazorwebview.md (#1046)
joel-heath Oct 31, 2022
3152248
Add necessary overrides in MainActivity (#1051)
sigged Nov 3, 2022
8a08967
What's new for Oct (#1054)
davidbritch Nov 3, 2022
cfd15a7
oops remove Xamarin.Forms mention
conceptdev Nov 3, 2022
8592793
Merge branch 'main' into conceptdev-605-foldable
conceptdev Nov 3, 2022
957a608
Revert "Update image.md (#1014)"
conceptdev Nov 3, 2022
61d4c74
Revert "versionName is in the manifest node (#1028)"
conceptdev Nov 3, 2022
4fd1501
Revert "iOS 11 min requirement using Xcode 14 (#1029)"
conceptdev Nov 3, 2022
d4f66e4
Revert "Remove limitations because OpenGLView doesn't exist in .NET M…
conceptdev Nov 3, 2022
cccca47
Revert "Add Mac instructions. (#1034)"
conceptdev Nov 3, 2022
4bf2432
Revert "VSMac instructions for live visual tree (#1035)"
conceptdev Nov 3, 2022
3eb2cdb
Revert "Add .NET header (#1039)"
conceptdev Nov 3, 2022
8cb7e6c
Revert "Typo fix - update to editor article (#1040)"
conceptdev Nov 3, 2022
5223cdf
Revert "Update blazorwebview.md (#1046)"
conceptdev Nov 3, 2022
7f8e68f
Revert "Add necessary overrides in MainActivity (#1051)"
conceptdev Nov 3, 2022
8310e20
Revert "What's new for Oct (#1054)"
conceptdev Nov 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions docs/TOC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@
href: user-interface/controls/tableview.md
- name: ContentView
href: user-interface/controls/contentview.md
- name: TwoPaneView
href: user-interface/controls/twopaneview.md
- name: Display pop-ups
href: user-interface/pop-ups.md
- name: Display tooltips
Expand Down Expand Up @@ -630,7 +632,11 @@
- name: Publish
items:
- name: Android
href: android/deployment/overview.md
items:
- name: Overview
href: android/deployment/overview.md
- name: Publish with the .NET CLI
href: android/deployment/publish-cli.md
- name: iOS
items:
- name: Publish an iOS app
Expand All @@ -642,6 +648,12 @@
- name: macOS
href: macos/deployment/overview.md
- name: Windows
href: windows/deployment/overview.md
items:
- name: Overview
href: windows/deployment/overview.md
- name: Publish with the .NET CLI
href: windows/deployment/publish-cli.md
- name: Publish with Visual Studio to a folder
href: windows/deployment/publish-visual-studio-folder.md
- name: Troubleshooting
href: troubleshooting.md
363 changes: 363 additions & 0 deletions docs/android/deployment/media/overview/build-and-deploy-steps.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
143 changes: 32 additions & 111 deletions docs/android/deployment/overview.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Publish a .NET MAUI app for Android"
description: "Learn how to package and publish an Android .NET MAUI app."
ms.date: 03/17/2022
ms.date: 10/07/2022
---

# Publish a .NET MAUI app for Android
Expand All @@ -13,133 +13,54 @@ ms.date: 03/17/2022
> - [Publish for macOS](../../macos/deployment/overview.md)
> - [Publish for Windows](../../windows/deployment/overview.md)

When distributing your .NET Multi-platform App UI (.NET MAUI) app for Android, you generate an _apk_ (Android Package) or an _aab_ (Android App Bundle) file. The _apk_ is used for installing your app to an Android device, and the _aab_ is used to publish your app to an Android store.
The final step in the development of a .NET MAUI app is to publish it. Publishing is the process of creating a package that contains the app and is ready for users to install on their devices. Packaging and deployment involve two essential tasks:

With just a few configuration changes to your project, your app can be packaged for distribution.
- **Preparing for publication**

## Validate package settings
A release version of the app is created that can be deployed to Android devices.

Every Android app specifies a unique package identifier and a version. These identifiers are generally set in the Android app manifest file, which is located in your project folder at _.\\Platforms\\Android\\AndroidManifest.xml_. However, these specific settings are provided by the project file itself. When a .NET MAUI app is built, the final _AndroidManifest.xml_ file is automatically generated using the project file and the original _AndroidManifest.xml_ file.
- **Distribution**

Your project file must declare `<ApplicationId>` and `<ApplicationVersion>` within a `<PropertyGroup>` node. These items should have been generated for you when the project was created. Just validate that they exist and are set to valid values:
The release version of an app is made available through one or more of the various distribution channels.

```xml
<Project Sdk="Microsoft.NET.Sdk">
The following diagram illustrates the steps involved with publishing a .NET MAUI app:

<!-- other settings -->
:::image type="content" source="media/overview/build-and-deploy-steps.svg" alt-text="Build and deploy flowchart":::

<PropertyGroup>
<ApplicationId>com.companyname.myproject</ApplicationId>
<ApplicationVersion>1</ApplicationVersion>
</PropertyGroup>
As can be seen by the diagram above, the preparation is the same regardless of the distribution method that is used. There are several ways that an Android app may be released to users:

</Project>
```
- **Via a website** &ndash; A .NET MAUI app can be made available for download on a website, from which users may then install the app by clicking on a link.
- **Via a file share** &ndash; Similar to a website, as long as the app package is available to the user, they can side-load it on their device.
- **Through a market** &ndash; There are several Android marketplaces that exist for distribution, such as [Google Play](https://play.google.com/) or [Amazon App Store for Android](https://www.amazon.com/mobile-apps/b?ie=UTF8&node=2350149011).

> [!TIP]
> Some settings are available in the **Project Properties** editor in Visual Studio to change values. Right-click on the project in the **Solution Explorer** pane and choose **Properties**. For more information, see [Project configuration in .NET MAUI](../../deployment/visual-studio-properties.md).
Using an established marketplace is the most common way to publish an app as it provides the broadest market reach and the greatest control over distribution. However, publishing an app through a marketplace requires extra effort.

The following table describes how each project setting maps to the manifest file:
Multiple channels can distribute a .NET MAUI app simultaneously. For example, an app could be published on Google Play, the Amazon App Store for Android, and also be downloaded from a web server.

| Project setting | Manifest setting |
| --- | --- |
| `ApplicationId` | The `package` attribute of the `<manifest>` node: `<manifest ... package="com.companyname.myproject>"`. |
| `ApplicationVersion` | The `android:versionCode` attribute of the `<manifest>` node: `<manifest ... android:versionCode="1">`. |
Making your app available for direct download is most useful for a controlled subset of users, such as an enterprise environment or an app that is only meant for a small or well-specified set of users. Server and email distribution are also simpler publishing models, requiring less preparation to publish an app, though apps may be blocked as an email attachment.

Here's an example of an automatically generated manifest file with the package and version information specified:
The Amazon Mobile App Distribution Program enables mobile app developers to distribute and sell their applications on Amazon. Users can discover and shop for apps on their Android devices by using the Amazon App Store application.

```xml
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
package="com.hi.companyname.myproject"
android:versionName="1.0.0">
<!-- other settings -->
</manifest>
```
Google Play is arguably the most comprehensive and popular marketplace for Android applications. Google Play allows users to discover, download, rate, and pay for applications by clicking a single icon either on their device or on their computer. Google Play also provides tools to help in the analysis of sales and market trends and to control which devices and users may download an application.

For more information about the manifest, see [Google Android App Manifest Overview](https://developer.android.com/guide/topics/manifest/manifest-intro).

## Create a keystore file

Your app package should be signed. You use a keystore file to sign your package. The Java/Android SDKs includes the tools you need to generate a keystore. After generating a keystore file, you'll add it to your project and configure your project file to reference it. The Java SDK should be in your system path so that you can run the _keytool_ tool.

Perform the following steps to create a keystore file:

01. Open a terminal and navigate to the folder of your project.

> [!TIP]
> If Visual Studio is open, use the **View** > **Terminal** menu to open a terminal at the location of the solution or project. Navigate to the project folder.

01. Run the _keytool_ tool with the following parameters:

```console
keytool -genkey -v -keystore myapp.keystore -alias key -keyalg RSA -keysize 2048 -validity 10000
```

You'll be prompted to provide and confirm a password, followed by other settings.

The tool generates a _myapp.keystore_ file, which should be located in the same folder as your project.

## Add a reference to the keystore file

There are project-level settings you must set to sign your Android app with the keystore file. These settings are configured in a `<PropertyGroup>` node:

- `<AndroidKeyStore>` &ndash; Set to `True` to sign the app.
- `<AndroidSigningKeyStore>` &ndash; The keystore file created in the previous section: **myapp.keystore**.
- `<AndroidSigningKeyAlias>` &ndash; The `-alias` parameter value passed to the _keytool_ tool: **key**.
- `<AndroidSigningKeyPass>` &ndash; The password you provided when creating the keystore file.
- `<AndroidSigningStorePass>` &ndash; The password you provided when creating the keystore file.

For security reasons, you don't want to supply a value for `<AndroidSigningKeyPass>` and `<AndroidSigningStorePass>` in the project file. You can provide these values on the command line when you publish the app. An example of providing the password is in the [Publish section](#publish).

```xml
<PropertyGroup Condition="$(TargetFramework.Contains('-android')) and '$(Configuration)' == 'Release'">
<AndroidKeyStore>True</AndroidKeyStore>
<AndroidSigningKeyStore>myapp.keystore</AndroidSigningKeyStore>
<AndroidSigningKeyAlias>key</AndroidSigningKeyAlias>
<AndroidSigningKeyPass></AndroidSigningKeyPass>
<AndroidSigningStorePass></AndroidSigningStorePass>
</PropertyGroup>
```

The example `<PropertyGroup>` above adds a condition check, preventing those settings from being processed unless the condition check passes. The condition check looks for two things:

01. The target framework is set to something containing the text `-android`.
01. The build configuration is set to `Release`.

If either of those conditions fail, the settings aren't processed. More importantly, the `<AndroidKeyStore>` setting isn't set, preventing the app from being signed.

## Publish

At this time, publishing is only supported through the .NET command line interface.

To publish your app, open a terminal and navigate to the folder for your .NET MAUI app project. Run the `dotnet publish` command, providing the following parameters:

| Parameter | Value |
|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| `-f` or `--framework` | The target framework, which is `net6.0-android`. |
| `-c` or `--configuration` | The build configuration, which is `Release`. |
| `/p:AndroidSigningKeyPass` | This is the value used for the `<AndroidSigningKeyPass>` project setting, the password you provided when you created the keystore file. |
| `/p:AndroidSigningStorePass` | This is the value used for the `<AndroidSigningStorePass>` project setting, the password you provided when you created the keystore file. |

> [!WARNING]
> Attempting to publish a .NET MAUI solution will result in the `dotnet publish` command attempting to publish each project in the solution individually, which can cause issues when you've added other project types to your solution. Therefore, the `dotnet publish` command should be scoped to your .NET MAUI app project.

For example:
## See also

```console
dotnet publish -f:net6.0-android -c:Release /p:AndroidSigningKeyPass=mypassword /p:AndroidSigningStorePass=mypassword
```
This section links to articles that may help in publishing an app to an app store such as Google Play.

Publishing builds the app, and then copies the _aab_ and _apk_ files to the _bin\\Release\\net6.0-android\\publish_ folder. There are two _aab_ files, one unsigned and another signed. The signed variant has **-signed** in the file name.
<!--
- [Build Process](~/android/deploy-test/building-apps/build-process.md)
- [Linking](~/android/deploy-test/linker.md)
- [Obtaining A Google Maps API Key](~/android/platform/maps-and-location/maps/obtaining-a-google-maps-api-key.md)
- [Deploy via Visual Studio App Center](/appcenter/distribution/stores/googleplay)
- [Application Signing](https://source.android.com/security/apksigning/)
-->

For more information about the `dotnet publish` command, see [dotnet publish](/dotnet/core/tools/dotnet-publish).
### Google Play app store

To learn how to upload a signed Android App Bundle to the Google Play Store, see [Upload your app to the Play Console](https://developer.android.com/studio/publish/upload-bundle).
- [Publishing on Google Play](https://developer.android.com/distribute/googleplay/publish/index.html)
- [Google Application Licensing](https://developer.android.com/guide/google/play/licensing/index.html)

## See also
### Amazon app store

- [GitHub discussion and feedback: .NET MAUI Android target publishing/archiving](https://github.com/dotnet/maui/issues/4377)
- [Android Developers: About Android App Bundles](https://developer.android.com/guide/app-bundle)
- [Android Developers: Meet Google Play's target API level requirement](https://developer.android.com/google/play/requirements/target-sdk)
- [Mobile App Distribution Portal](https://developer.amazon.com/welcome.html)
- [Amazon Mobile App Distribution FAQ](https://developer.amazon.com/help/faq.html)
Loading