- Building Xamarin apps for Android
- 1. Linking your repository
- 2. Selecting a branch
- 3. Configuring Your Build
- 3.1. Build triggers
- 3.2. Project and Configuration
- 3.3. Mono version
- 3.3.1. .NET Core version
- 3.5. Increment version number
- 3.6. Code signing
- 3.7. Launch your successful build on a real device
- 3.8. NuGet restore
- 3.9. Distribute the build
- 4. Build results
- 4.1. Build logs
- 4.2. The app (.apk)
- Supported versions and requirements
- Build Process
- Application Packages
- Shared Runtime
- Fast Deployment
- MSBuild Projects
- Binding Projects
- Resource.designer.cs Generation
- Signing Properties
- keytool Option Mapping
- Build Extension Points
- Target Definitions
- How do I create apk file for a Xamarin.Android application
- 4 Answers 4
- For even simpler/faster testing, you can:
- Important:
Building Xamarin apps for Android
To start building your first Xamarin Android app, you must:
- Connect to your repository service account (GitHub, Bitbucket, VSTS, Azure DevOps).
- Select a repository and a branch where your app lives.
- Choose the Android project you want to build.
- Set up your first build.
For the app to run on a real device, you must sign the build the build with a valid KeyStore.
1. Linking your repository
If you haven’t previously connected to your repository service account, you must do this first. Once your account is connected, select the repository where your Xamarin project is located. You must have admin and pull permissions to set up a build for a repository.
2. Selecting a branch
After selecting a repository, select the branch you want to build. By default, App Center lists all active branches.
3. Configuring Your Build
The Xamarin project must be configured before your first build.
3.1. Build triggers
By default, the build service uses Continuous Integration, so a new build is triggered every time a developer pushes to a configured branch. If you prefer to trigger new builds manually, you can change this setting in the configuration pane.
3.2. Project and Configuration
The available projects in your repository will populate if they’re located within the range of analysis. Select the correct project for your Android build and select the appropriate configuration.
For best performance, the analysis is currently limited to four directory levels including the root of your repository.
3.3. Mono version
App Center allows using different Mono environments bundled with the respective Xamarin.Android SDK for your builds. This way we maintain backward compatibility while also supporting the latest features. The default Mono version for a new branch configuration is the latest stable one. You may choose to use one of the previous Mono environments to build older versions of frameworks or libraries.
When selecting a Mono version in the build configuration, the bundled Xamarin.Android SDK version displayed right next to it. For more information about Xamarin SDK version updates, read the Xamarin release blog.
3.3.1. .NET Core version
Proper .NET Core version will be selected automatically based on Mono version used for build and can’t be overwritten. You can view the mapping of Mono to the .NET Core used by our services in the table below:
Mono | .NET Core |
---|---|
.apk. Toggle on the option for Android App Bundle to produce an .aab and an .apk . If the .csproj file contains aab in the AndroidPackageFormat property, this option will automatically be toggled on. Building an .aab is supported for Xamarin.Android 9.4 and higher. 3.5. Increment version numberWhen enabled, the version code in the AndroidManifest.xml of your app automatically increments for each build. The change happens pre build and won’t be committed to your repository. 3.6. Code signingA successful build will produce an .apk file and an additional .aab file if enabled. To release the build to the Play Store, it must be signed with a valid Keystore and Alias. To sign the builds produced from a branch, enable code signing in the configuration pane, upload your Keystore, and provide the values needed in the configuration pane. You can read more detailed code signing instructions. The .aab will be signed using the same credentials as the .apk . 3.7. Launch your successful build on a real deviceUse your newly produced .apk file to test if your app starts on a real device. This adds approximately 10 more minutes to the total build time. There’s more information in our test integration guide. 3.8. NuGet restoreIf the NuGet.config file is checked-in into the repository and sitting next to the .sln file or at the root level of your repository, App Center restores your private NuGet feeds when they’re added as shown in the example below. Credentials can be added safely by using environment variables: If you have complex configurations and need more information, refer to Configuring NuGet behavior. 3.9. Distribute the buildYou can configure each successful build from a branch to be distributed to a previously created distribution group or a store destination. You can add a new distribution group or configure a store connection from within the Distribute service. There’s always a default distribution group called «Collaborators» that includes all the users who have access to the app. If distributing to the Google Play Store, an Android App Bundle ( .aab ) is preferred and will be distributed if enabled. For App Center distribution groups and Intune store destinations, a regular .apk will be used even if an .aab is also generated. 4. Build resultsAfter a build triggers, the build will be in one of the following states:
4.1. Build logsFor a completed build (succeeded or failed), download the logs to understand more about how the build went. App Center provides an archive with the following files: The build step logs (located in the build/ directory of the archive) are helpful for understanding in which step and why the build failed. 4.2. The app (.apk)The .apk file is an Android application packaged file that stores the Android app. If the build has been correctly signed, the .apk file can be installed on a real device and deployed to the Play Store. If the build hasn’t been signed, the app can run on an emulator or be used for other purposes. Supported versions and requirementsApp Center supports Portable Class Library (PCL) and .NET Standard projects. Refer to Cloud Build Machines for versions of .NET Standard. App Center doesn’t support Components from the Xamarin Component Store and we advise using NuGet packages whenever they’re available. If you’re using a Component that can’t be replaced, contact us. See help and feedback. Источник Build ProcessThe Xamarin.Android build process is responsible for gluing everything together: generating Resource.designer.cs , supporting the @(AndroidAsset) , @(AndroidResource) , and other build actions, generating Android-callable wrappers, and generating a .apk for execution on Android devices. Application PackagesIn broad terms, there are two types of Android application packages ( .apk files) which the Xamarin.Android build system can generate: Release builds, which are fully self-contained and don’t require extra packages to execute. These are the packages that are provided to an App store. Debug builds, which are not. These package types match the MSBuild Configuration which produces the package. Shared RuntimePrior to Xamarin.Android 11.2, the shared runtime was a pair of extra Android packages which provide the Base Class Library ( mscorlib.dll , etc.) and the Android binding library ( Mono.Android.dll , etc.). Debug builds rely upon the shared runtime in lieu of including the Base Class Library and Binding assemblies within the Android application package, allowing the Debug package to be smaller. The shared runtime could be disabled in Debug builds by setting the $(AndroidUseSharedRuntime) property to False . Support for the Shared Runtime was removed in Xamarin.Android 11.2. Fast DeploymentFast deployment works by further shrinking Android application package size. This is done by excluding the app’s assemblies from the package, and instead deploying the app’s assemblies directly to the application’s internal files directory, usually located in /data/data/com.some.package . The internal files directory is not a globally writable folder, so the run-as tool is used to execute all the commands to copy the files into that directory. This process speeds up the build/deploy/debug cycle because the package is not reinstalled when only assemblies are changed. Only the updated assemblies are resynchronized to the target device. Fast deployment is known to fail on devices which block run-as , which often includes devices older than Android 5.0. Fast deployment also fails for system applications (android:sharedUserId=»android.uid.system») since run-as is also blocked for system applications. Fast deployment is enabled by default, and may be disabled in Debug builds by setting the $(EmbedAssembliesIntoApk) property to True . The Enhanced Fast Deployment mode can be used in conjunction with this feature to speed up deployments even further. This will deploy both assemblies, native libraries, typemaps and dexes to the files directory. But you should only really need to enable this if you are changing native libraries, bindings or Java code. MSBuild ProjectsThe Xamarin.Android build process is based on MSBuild, which is also the project file format used by Visual Studio for Mac and Visual Studio. Ordinarily, users will not need to edit the MSBuild files by hand – the IDE creates fully functional projects and updates them with any changes made, and automatically invoke build targets as needed. Advanced users may wish to do things not supported by the IDE’s GUI, so the build process is customizable by editing the project file directly. This page documents only the Xamarin.Android-specific features and customizations – many more things are possible with the normal MSBuild items, properties and targets. Binding ProjectsThe following MSBuild properties are used with Binding projects: Resource.designer.cs GenerationThe Following MSBuild properties are used to control generation of the Resource.designer.cs file: Signing PropertiesSigning properties control how the Application package is signed so that it may be installed onto an Android device. To allow quicker build iteration, the Xamarin.Android tasks do not sign packages during the build process, because signing is quite slow. Instead, they are signed (if necessary) before installation or during export, by the IDE or the Install build target. Invoking the SignAndroidPackage target will produce a package with the -Signed.apk suffix in the output directory. By default, the signing target generates a new debug-signing key if necessary. If you wish to use a specific key, for example on a build server, the following MSBuild properties are used: keytool Option MappingConsider the following keytool invocation: To use the keystore generated above, use the property group: Build Extension PointsThe Xamarin.Android build system exposes a few public extension points for users wanting to hook into our build process. To use one of these extension points you will need to add your custom target to the appropriate MSBuild property in a PropertyGroup . For example: Extension points include: A word of caution about extending the build process: If not written correctly, build extensions can affect your build performance, especially if they run on every build. It is highly recommended that you read the MSBuild documentation before implementing such extensions. Target DefinitionsThe Xamarin.Android-specific parts of the build process are defined in $(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets , but normal language-specific targets such as Microsoft.CSharp.targets are also required to build the assembly. The following build properties must be set before importing any language targets: All of these targets and properties can be included for C# by importing Xamarin.Android.CSharp.targets: This file can easily be adapted for other languages. Источник How do I create apk file for a Xamarin.Android applicationI am new to android development and need to create an apk file for an android application I made in Xamarin Studios so my peer can test it on his device. How can I create the apk file? 4 Answers 4For even simpler/faster testing, you can:
Important:«Use Shared Runtime» inside the project properties/Android Options must be Disabled, otherwise Mono Runtime won’t be included and your app will crash on phones where Mono isn’t installed.Example
For simple testing:
With the latest Visual Studio 2019 and the latest xamarin, I will literally walk you through all the steps:
Build your android project first. Right-click on your android project -> click «Archive. « It’ll show something like this: Let it complete its processing When it’s done, click the «Distribute» button, it’ll open a menu like this:
Источник |