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
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.
Here are all the arguments which the target will use when installing the dependencies:
-p:AndroidSdkDirectory="<PATH>" 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="<PATH>" 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.
Huomautus
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:
Go to Android Studio download.
Scroll down to the "Command Line Tools only" section and download the zip file for your operating system.
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.
Extract the files from the zip file into this directory. You should end up with a folder structure like
android-sdk\cmdline-tools
Open a terminal or Command Prompt.
Navigate to the android-sdk\cmdline-tools\bin directory within the directory you created.
Run the sdkmanager command to install the desired components.
For example, to install the latest platform and platform tools, use:
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.
Konsoli
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:
Liity tapaamissarjaan ja luo skaalattavia tekoälyratkaisuja, jotka perustuvat reaalimaailman käyttötapauksiin muiden kehittäjien ja asiantuntijoiden kanssa.
Luo .NET-projekti ja opi lisäämään paketteja ja hallitsemaan pakettien riippuvuuksia projektissasi. .NET Core CLI- ja NuGet-rekisterin avulla voit lisätä kirjastoja ja työkaluja C#-sovelluksiisi Visual Studio Coden kautta.
Luo päästä päähän -ratkaisuja Microsoft Azuressa, jotta voit luoda Azure-funktioita, ottaa käyttöön ja hallita verkkosovelluksia, kehittää Azure-tallennustilaa hyödyntäviä ratkaisuja ja paljon muuta.