diff --git a/Documentation/docs-mobile/getting-started/installation/dependencies.md b/Documentation/docs-mobile/getting-started/installation/dependencies.md new file mode 100644 index 00000000000..1ceeba60c49 --- /dev/null +++ b/Documentation/docs-mobile/getting-started/installation/dependencies.md @@ -0,0 +1,106 @@ +--- +title: "Install .NET for Android dependencies" +description: "Learn how to install .NET for Android dependencies so you can create native Android applications." +ms.date: 11/01/2023 +--- +# Install .NET for Android dependencies + +In order to build .NET for Android applications you need to install the Android SDK and the Java SDK. + +## Using "InstallAndroidDependencies" target + +The easiest way to install the required dependencies for your Android application is to run the +[`InstallAndroidDependencies`](../../building-apps/build-targets.md#installandroiddependencies) +MSBuild target. + +This target will examine your application project and install the exact components which are needed. +If you update your project to target a new Android API you will need to run this target again +to make sure you get the required components. + +For example if you are upgrading your project to target API 34 from API 32, you will only have +API 32 installed. Running the `InstallAndroidDependencies` target will install API 34 for you. + +If you do not have the Android SDK installed at all, this target can also handle installing the SDK +on a clean machine. You can change the destination of the installation by setting the +`AndroidSdkDirectory` MSBuild property. It will also install the Java SDK if the `JavaSdkDirectory` +MSBuild property is provided. + +```dotnetcli +dotnet build -t:InstallAndroidDependencies -f net8.0-android -p:AndroidSdkDirectory=c:\work\android-sdk -p:JavaSdkDirectory=c:\work\jdk -p:AcceptAndroidSdkLicenses=True +``` + +Here are all the arguments which the target will use when installing the dependencies: + +* `-p:AndroidSdkDirectory=""` installs or updates Android dependencies to the specified path. + *Note*: You must use an absolute path; Unix developers should not use tilde (`~`), as it is + not expanded when used *within* a command-line argument. + +* `-p:JavaSdkDirectory=""` installs Java to the specified path. + *Note*: You must use an absolute path; Unix developers should not use tilde (`~`), as it is + not expanded when used *within* a command-line argument. + +* `-p:AcceptAndroidSDKLicenses=True` accepts the necessary Android licenses for development. + +> [!NOTE] +> To make development easier try to avoid using paths which contain spaces or non-ASCII characters. + +## Install the Android SDK manually + +You might find it necessary to install the Android SDK manually: + + 1. Go to [Android Studio download](https://developer.android.com/studio#download). + Scroll down to the "Command Line Tools only" section and download the zip file for your operating system. + + 2. Create an `android-sdk` directory somewhere on your hard drive. To make your life easier create it near to the root of the drive. For example `c:\android-sdk`. + + 3. Extract the files from the zip file into this directory. You should end up with a folder structure like + `android-sdk\cmdline-tools` + + 4. Open a terminal or Command Prompt. + + 5. Navigate to the `android-sdk\cmdline-tools\bin` directory within the directory you created. + + 6. Run the `sdkmanager` command to install the desired components. + +For example, to install the latest platform and platform tools, use: + +```console +sdkmanager "platforms;android-34" "platform-tools" "build-tools;34.0.0" "emulator" "system-images;android-34;default;x86_64" "cmdline-tools;11.0" --sdk_root=c:\android-sdk +``` + +Note that double-quotes should be used liberally to enclose the semicolon `;`, which is part of the component names. + +You will be prompted to accept the license, after which the Android SDK will install. + +You can use `sdkmanager` to install additional components. You can use the `--list` argument to get a list of all the available components. You can then look through the list and find the additional components you want. + +```console +sdkmanager --list +``` + +The following component types are useful to know: + + * `platforms;android-XX`: Installs the platform `android-XX` into the sdk. + Replace *XX* with the API Level of your chosen platform. + For example `platforms;android-30` will install Android API 30, while + `platforms;android-21` will install Android API 21. + + * `system-images;android-XX;default;x86_64`: Installs an emulator image for + the specific API level. The `x86_64` can be swapped out for different ABIs + such as `x86`, `arm64-v8a`, and `x86_64`. These reflect the ABI of the image + being installed. This can be useful if you have issues on specific ABI's. + +It is also good practice to set the `ANDROID_HOME` environment variable, as this +allows you to use certain tooling from the command line. + +## Install Microsoft JDK manually + +In order to build .NET for Android applications or libraries you need to have a version of the Java Development Kit installed. +We recommend you use the Microsoft Open JDK, this has been tested against our .NET for Android builds: + + 1. Download [Microsoft OpenJDK 11](/java/openjdk/download#openjdk-11). + + 2. Depending on your platform run the appropriate installer. + + 3. It is also good practice to set the `JAVA_HOME` environment variable. + This will allow you to use the JDK from the Command Prompt or Terminal. diff --git a/Documentation/docs-mobile/getting-started/installation/images/vs-install-installing.png b/Documentation/docs-mobile/getting-started/installation/images/vs-install-installing.png new file mode 100644 index 00000000000..b1d12783f77 Binary files /dev/null and b/Documentation/docs-mobile/getting-started/installation/images/vs-install-installing.png differ diff --git a/Documentation/docs-mobile/getting-started/installation/images/vs-install-select-android-components.png b/Documentation/docs-mobile/getting-started/installation/images/vs-install-select-android-components.png new file mode 100644 index 00000000000..5fed673ee18 Binary files /dev/null and b/Documentation/docs-mobile/getting-started/installation/images/vs-install-select-android-components.png differ diff --git a/Documentation/docs-mobile/getting-started/installation/images/vs-install-select-maui.png b/Documentation/docs-mobile/getting-started/installation/images/vs-install-select-maui.png new file mode 100644 index 00000000000..ddcb46ac12f Binary files /dev/null and b/Documentation/docs-mobile/getting-started/installation/images/vs-install-select-maui.png differ diff --git a/Documentation/docs-mobile/getting-started/installation/images/vs-new-project.png b/Documentation/docs-mobile/getting-started/installation/images/vs-new-project.png new file mode 100644 index 00000000000..37e587d1cd5 Binary files /dev/null and b/Documentation/docs-mobile/getting-started/installation/images/vs-new-project.png differ diff --git a/Documentation/docs-mobile/getting-started/installation/images/vs-select-android-application.png b/Documentation/docs-mobile/getting-started/installation/images/vs-select-android-application.png new file mode 100644 index 00000000000..228e2cd49fc Binary files /dev/null and b/Documentation/docs-mobile/getting-started/installation/images/vs-select-android-application.png differ diff --git a/Documentation/docs-mobile/getting-started/installation/index.md b/Documentation/docs-mobile/getting-started/installation/index.md new file mode 100644 index 00000000000..e300eaeabd9 --- /dev/null +++ b/Documentation/docs-mobile/getting-started/installation/index.md @@ -0,0 +1,14 @@ +--- +title: Installation +description: Install .NET for Android +ms.date: 04/17/2024 +--- + +# Installation overview + +.NET for Android allows writing applications for the +[Android Operating System](https://developer.android.com) using .NET. + +In order to use .NET for Android, you must first +[install .NET for Android](net-android.md), and then you need to +[install dependencies such as the Android SDK](dependencies.md). diff --git a/Documentation/docs-mobile/getting-started/installation/net-android.md b/Documentation/docs-mobile/getting-started/installation/net-android.md new file mode 100644 index 00000000000..dadf46f4c5d --- /dev/null +++ b/Documentation/docs-mobile/getting-started/installation/net-android.md @@ -0,0 +1,54 @@ +--- +title: "Install .NET for Android" +description: "Learn how to install .NET for Android so you can create native android applications." +ms.date: 11/01/2023 +--- +# Install .NET for Android + +Developing native, .NET for Android apps requires .NET 6 or higher. Various IDE's can be used, however +we recommend Visual Studio 2022 17.3 or greater, or Visual Studio Code. + + +## [Install via the Command Prompt or Terminal](#tab/commandline) + + + 1. Install the [latest .NET](https://dotnet.microsoft.com/download) for your particular platform + and follow its [installation instructions](/dotnet/core/install). + + 2. From a Command Prompt or Terminal run: + + ```dotnetcli + dotnet workload install android + ``` + + 3. In order to build Android applications you also need to install the + [Android SDK and other dependencies](dependencies.md#using-installandroiddependencies-target). + + + +## [Install via Visual Studio](#tab/visualstudio) + + + 1. Install the [latest Visual Studio](https://visualstudio.microsoft.com/downloads/). + + 2. Select the .NET Multi Platform App UI Development workload and any other workloads you want. + + ![Select .Net Multi Platform App UI WorkLoad](images/vs-install-select-maui.png) + + 3. Or select the .NET for Android SDK component from the Individual Components tab. + + ![Select .NET for Android SDK Component](images/vs-install-select-android-components.png) + + 4. Let the installer run, it may take a while depending on your Internet Connection. + + ![The Running Installer](images/vs-install-installing.png) + + 5. Once installed you can run Visual Studio. + + You will be presented with the start up screen. Select New Project: + + ![Select the New Project Menu](images/vs-new-project.png) + + 6. Look through the templates to find the Android Application Template + + ![Select the Android Application Template](images/vs-select-android-application.png) diff --git a/Documentation/docs-mobile/index.yml b/Documentation/docs-mobile/index.yml new file mode 100644 index 00000000000..680a0d16ded --- /dev/null +++ b/Documentation/docs-mobile/index.yml @@ -0,0 +1,88 @@ +### YamlMime:Hub + +#root section (Required) +title: .NET for Android documentation +summary: > + .NET for Android allows you to write Android apps using .NET languages. +brand: dotnet + +metadata: + title: .NET for Android + description: The .NET for Android guide has everything you need to learn .NET on the Android platform. + ms.service: dotnet-android + ms.topic: hub-page + author: jonpryor + ms.author: jopryo + ms.date: 04/18/2024 + +# highlightedContent section (Optional; Remove if not applicable.) +# Maximum of 8 items +highlightedContent: +# itemType: architecture | concept | deploy | download | get-started | how-to-guide | training | overview | quickstart | reference | sample | tutorial | video | whats-new + items: + # Card + - title: Install .NET for Android + itemType: get-started + url: ./getting-started/installation/index.md + +conceptualContent: +# itemType: reference + # Supports up to 3 subsections + sections: + - title: .NET for Android reference + items: + # Card + - title: Building Android Apps + summary: Building Android Apps + links: + - url: ./building-apps/build-process.md + itemType: reference + text: Build Process + - url: ./building-apps/build-targets.md + itemType: reference + text: Build Targets + - url: ./building-apps/build-properties.md + itemType: reference + text: Build Properties + - url: ./building-apps/build-items.md + itemType: reference + text: Build Items + # Card + - title: Features + summary: .NET for Android Features + links: + - url: ./features/layout-code-behind/index.md + itemType: reference + text: Layout Code Behind + - url: ./features/maven/android-maven-library.md + itemType: reference + text: "@(AndroidMavenLibrary) Build Item" + # Card + - title: Message reference + summary: Tooling error and warning message reference. + links: + - url: ./messages/index.md + itemType: reference + text: Messages reference + + +# additionalContent section (Optional; Remove if not applicable.) +# Card with links style +additionalContent: + # Supports up to 4 subsections + sections: + + - title: API reference # < 60 chars (optional) + summary: Search the .NET API documentation. # < 160 chars (optional) + items: + # Card + - title: ".NET API reference" + summary: API reference documentation for .NET + url: /dotnet/api/index.md?view=net-8.0 + # Card + - title: ".NET for Android reference" + summary: Android-specific API reference + url: /dotnet/api/?preserve-view=true&view=net-android-34.0 + + # footer (Optional; Remove if not applicable.) + footer: "Are you interested in contributing to the .NET docs? For more information, see our [contributor guide](/contribute/dotnet/dotnet-contribute)."