Xamarin.Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
Перейти к файлу
Jonathan Pryor 0b75ce8911
[xabuild] Remove Mono.Posix use (#1352)
We would like to migrate to using `msbuild` to build everything on
Jenkins, instead of `xbuild`.

Before doing so, we updated the [xamarin-android-msbuild][0] job so
that it mirrored the [xamarin-android][1] job, updating it to build
and run unit tests. (Unit tests were previously skipped on the
`xamarin-android-msbuild` job because unit test execution takes
awhile, and behavior under MSBuild *should* be identical to that under
`xbuild`, so there wasn't a perceived need to spend time on them.)

It is at that point that [everything stopped working][2]:

	/Users/builder/jenkins/workspace/xamarin-android-msbuild/tools/scripts/../../bin/Debug/bin/xabuild.exe.dll /p:Configuration=Debug /p:MonoDroidInstallDirectory=/Users/builder/jenkins/workspace/xamarin-android-msbuild/tools/scripts/../../bin/Debug /v:diag Xamarin.Android-Tests.sln
	...
	Stacktrace:

	  at <unknown> <0xffffffff>
	  at (wrapper managed-to-native) object.__icall_wrapper_mono_gc_alloc_vector (intptr,intptr,intptr)
	  at (wrapper alloc) object.AllocVector (intptr,intptr)
	  at System.Collections.Hashtable.rehash (int,bool)
	  at System.Collections.Hashtable.expand ()
	  at System.Collections.Hashtable.Insert (object,object,bool)
	  at System.Collections.Hashtable.set_Item (object,object)
	  at System.Environment.GetEnvironmentVariables ()
	  at Microsoft.Build.Internal.CommunicationsUtilities.GetEnvironmentVariables ()
	  at Microsoft.Build.Execution.BuildParameters.Initialize (Microsoft.Build.Collections.PropertyDictionary`1<Microsoft.Build.Execution.ProjectPropertyInstance>,Microsoft.Build.Evaluation.ProjectRootElementCache,Microsoft.Build.Evaluation.ToolsetProvider)
	  at Microsoft.Build.Execution.BuildParameters..ctor (Microsoft.Build.Evaluation.ProjectCollection)
	  at Microsoft.Build.Execution.ProjectInstance..ctor (Microsoft.Build.Construction.ProjectRootElement,System.Collections.Generic.IDictionary`2<string, string>,string,int,Microsoft.Build.Evaluation.ProjectCollection,Microsoft.Build.BackEnd.SdkResolution.ISdkResolverService,int)
	  at Microsoft.Build.Construction.SolutionProjectGenerator.CreateTraversalInstance (string,bool,System.Collections.Generic.List`1<Microsoft.Build.Construction.ProjectInSolution>)
	  at Microsoft.Build.Construction.SolutionProjectGenerator.CreateSolutionProject (string,bool)
	  at Microsoft.Build.Construction.SolutionProjectGenerator.Generate ()
	  at Microsoft.Build.Construction.SolutionProjectGenerator.Generate (Microsoft.Build.Construction.SolutionFile,System.Collections.Generic.IDictionary`2<string, string>,string,Microsoft.Build.Framework.BuildEventContext,Microsoft.Build.BackEnd.Logging.ILoggingService,System.Collections.Generic.IReadOnlyCollection`1<string>,Microsoft.Build.BackEnd.SdkResolution.ISdkResolverService,int)
	  at Microsoft.Build.Execution.ProjectInstance.GenerateSolutionWrapper (string,System.Collections.Generic.IDictionary`2<string, string>,string,Microsoft.Build.BackEnd.Logging.ILoggingService,Microsoft.Build.Framework.BuildEventContext,System.Collections.Generic.IReadOnlyCollection`1<string>,Microsoft.Build.BackEnd.SdkResolution.ISdkResolverService,int)
	  at Microsoft.Build.Execution.ProjectInstance.LoadSolutionForBuild (string,Microsoft.Build.Collections.PropertyDictionary`1<Microsoft.Build.Execution.ProjectPropertyInstance>,string,Microsoft.Build.Execution.BuildParameters,Microsoft.Build.BackEnd.Logging.ILoggingService,Microsoft.Build.Framework.BuildEventContext,bool,System.Collections.Generic.IReadOnlyCollection`1<string>,Microsoft.Build.BackEnd.SdkResolution.ISdkResolverService,int)
	  at Microsoft.Build.Execution.BuildManager.LoadSolutionIntoConfiguration (Microsoft.Build.BackEnd.BuildRequestConfiguration,Microsoft.Build.BackEnd.BuildRequest)
	  at Microsoft.Build.Execution.BuildManager.HandleNewRequest (int,Microsoft.Build.BackEnd.BuildRequestBlocker)
	  at Microsoft.Build.Execution.BuildManager.IssueRequestToScheduler (Microsoft.Build.Execution.BuildSubmission,bool,Microsoft.Build.BackEnd.BuildRequestBlocker)
	  at Microsoft.Build.Execution.BuildManager/<>c__DisplayClass63_1.<ExecuteSubmission>b__0 ()
	  at Microsoft.Build.Execution.BuildManager.ProcessWorkQueue (System.Action)
	  at Microsoft.Build.Execution.BuildManager.<BeginBuild>b__50_0 (System.Action)
	  at System.Threading.Tasks.Dataflow.ActionBlock`1<TInput_REF>.ProcessMessage (System.Action`1<TInput_REF>,System.Collections.Generic.KeyValuePair`2<TInput_REF, long>)
	  at System.Threading.Tasks.Dataflow.ActionBlock`1/<>c__DisplayClass5<TInput_REF>.<.ctor>b__0 (System.Collections.Generic.KeyValuePair`2<TInput_REF, long>)
	  at System.Threading.Tasks.Dataflow.Internal.TargetCore`1<TInput_REF>.ProcessMessagesLoopCore ()
	  at System.Threading.Tasks.Dataflow.Internal.TargetCore`1<TInput_REF>.<ProcessAsyncIfNecessary_Slow>b__3 (object)
	  at System.Threading.Tasks.Task.InnerInvoke ()
	  at System.Threading.Tasks.Task.Execute ()
	  at System.Threading.Tasks.Task.ExecutionContextCallback (object)
	  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
	  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
	  at System.Threading.Tasks.Task.ExecuteWithThreadLocal (System.Threading.Tasks.Task&)
	  at System.Threading.Tasks.Task.ExecuteEntry (bool)
	  at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem ()
	  at System.Threading.ThreadPoolWorkQueue.Dispatch ()
	  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback ()
	  at (wrapper runtime-invoke) <Module>.runtime_invoke_bool (object,intptr,intptr,intptr)

	Native stacktrace:

		0   mono                                0x000000010b3c1251 mono_handle_native_crash + 257
		1   mono                                0x000000010b45d9f6 altstack_handle_and_restore + 70
		2   mono                                0x000000010b593fd4 sgen_client_par_object_get_size + 4
		3   mono                                0x000000010b594e6b pin_objects_in_nursery + 667
		4   mono                                0x000000010b5942a0 collect_nursery + 512
		5   mono                                0x000000010b590dea sgen_perform_collection + 442
		6   mono                                0x000000010b58662b sgen_alloc_obj_nolock + 763
		7   mono                                0x000000010b583997 mono_gc_alloc_vector + 119
		8   ???                                 0x000000010bac87f5 0x0 + 4490823669
		9   mscorlib.dll.dylib                  0x000000010d79596f System_Collections_Hashtable_rehash_int_bool + 95
		10  ???                                 0x000000010f213323 0x0 + 4548801315
		11  ???                                 0x000000010f29e123 0x0 + 4549370147
		12  ???                                 0x000000010f29ce73 0x0 + 4549365363
		13  ???                                 0x000000010f29cb1b 0x0 + 4549364507
		14  ???                                 0x000000010f23aa2b 0x0 + 4548962859
		15  ???                                 0x000000010f238fc3 0x0 + 4548956099
		16  ???                                 0x000000010f2384d3 0x0 + 4548953299
		17  ???                                 0x000000010f237fbb 0x0 + 4548951995
		18  ???                                 0x000000010f237853 0x0 + 4548950099
		19  ???                                 0x000000010f237463 0x0 + 4548949091
		20  ???                                 0x000000010f237262 0x0 + 4548948578
		21  ???                                 0x000000010f23710b 0x0 + 4548948235
		22  ???                                 0x000000010f236eab 0x0 + 4548947627
		23  ???                                 0x000000010f235f6b 0x0 + 4548943723
		24  mscorlib.dll.dylib                  0x000000010d6679b6 System_Threading_Tasks_Task_ExecutionContextCallback_object + 70
		25  mscorlib.dll.dylib                  0x000000010d63d651 System_Threading_ExecutionContext_Run_System_Threading_ExecutionContext_System_Threading_ContextCallback_object_bool + 33
		26  mscorlib.dll.dylib                  0x000000010d667767 System_Threading_Tasks_Task_ExecuteEntry_bool + 231
		27  mscorlib.dll.dylib                  0x000000010d644ab9 System_Threading__ThreadPoolWaitCallback_PerformWaitCallback + 9
		28  mono                                0x000000010b3163d7 mono_jit_runtime_invoke + 1383
		29  mono                                0x000000010b50e1f4 do_runtime_invoke + 84
		30  mono                                0x000000010b532ac6 worker_callback + 966
		31  mono                                0x000000010b53519c worker_thread + 348
		32  mono                                0x000000010b530080 start_wrapper + 704
		33  libsystem_pthread.dylib             0x00007fff8ff5199d _pthread_body + 131
		34  libsystem_pthread.dylib             0x00007fff8ff5191a _pthread_body + 0
		35  libsystem_pthread.dylib             0x00007fff8ff4f351 thread_start + 13

The #mono team investigated, and determined that the crash was due to
memory corruption caused by `Mono.Unix.Native.Syscall.stat()`.

Specifically, the [`Mono.Posix.dll` package][3] which `xabuild.exe`
was using is *ancient* (5+ years old), and -- more importantly --
comes from a time *before* the `Mono.Unix.Native.Stat.st_atime_nsec`
and related fields existed. Consequently, the `Stat` size within
`Mono.Posix.dll` differed -- 24 bytes smaller! -- than what
`libMonoPosixHelper.dylib` expected, wherein `libMonoPosixHelper.dylib`
is coming from the `build-tools/mono-runtimes` build (significantly
newer than `Mono.Posix.dll`).

The `Mono.Posix` nuget package is thus incompatible with our current
use case.

Alternatively, we could update the mono bundle to include the built
`build/net45/mac/Mono.Posix.dll` file, but I have "bootstrap"
concerns, and am not convinced that I want to wait until after
`build-tools/mono-runtimes` has finished building in order to use
`xabuild.exe` in all scenarios.

Thus, to fix the above memory corruption, *remove* use of
`Mono.Posix.dll` from `xabuild.exe`, and instead directly P/Invoke the
needed POSIX functions, specifically **symlink**(2) and **perror**(3).

[0]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-msbuild/
[1]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/
[2]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-msbuild/761/
[3]: https://www.nuget.org/packages/Mono.Posix/4.0.0
2018-02-28 17:46:32 -05:00
.github [issues] Add GitHub Issue Template 2017-12-05 11:00:40 -05:00
Documentation [Xamarin.Android.Build.Tasks] Add Support for CodeBehind for layout files (#1238) 2018-02-09 11:29:47 -05:00
build-tools [mono-runtimes] Fix bundle usage 2018-02-15 12:27:55 -05:00
external Bump to xamarin-android-api-compatibility/master/2c689ef2 2018-02-22 16:43:49 +09:00
samples/HelloWorld [build] Remove autogenerated resource files and clean a bit (#831) 2017-09-08 11:26:12 -04:00
src [proguard] Preserve ManagedPeer class (#1351) 2018-02-28 17:19:01 -05:00
tests [tests] Bump minSdkVersion to 14 (#1330) 2018-02-23 12:06:17 -05:00
tools [xabuild] Remove Mono.Posix use (#1352) 2018-02-28 17:46:32 -05:00
.gitattributes [build] Use .csproj files, not .mdproj files (#1271) 2018-02-05 09:30:23 -05:00
.gitignore [tests] migrate test targets to MSBuild (#949) 2017-11-08 15:38:27 -05:00
.gitmodules Bump to xamarin-android-api-compatibility/master/2c689ef2 2018-02-22 16:43:49 +09:00
Before.Xamarin.Android.sln.targets [tests] migrate test targets to MSBuild (#949) 2017-11-08 15:38:27 -05:00
Configuration.Override.props.in [Xamarin.Android.Build.Tasks] Support new manifest attributes for API-24 (#128) 2016-08-01 09:12:20 -04:00
Configuration.props Bump $(ProductVersion) to 8.3.99 2018-02-16 16:07:12 -05:00
Dockerfile Add Dockerfile. (#204) 2016-09-02 12:37:12 -04:00
LICENSE [LICENSE] Add the libzip license. (#112) 2016-07-08 18:55:08 +02:00
Makefile Fix build with msbuild on Linux (#1270) 2018-02-05 15:31:33 +01:00
README.md [docs] Add Commercial Xamarin.Android 8.2 Download Location 2018-01-08 09:58:38 -05:00
Xamarin.Android-Tests.sln [BCL-Tests] New unit test runner (#1075) 2018-01-11 16:38:19 -05:00
Xamarin.Android.sln [build] Use .csproj files, not .mdproj files (#1271) 2018-02-05 09:30:23 -05:00
product.snk [Mono.Android, Mono.Android.Export] Sign assemblies. (#29) 2016-05-10 16:29:33 +01:00

README.md

Xamarin.Android banner

Xamarin.Android

Xamarin.Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#.

Gitter

Build Status

Platform Status
OSS macOS OSS macOS x86_64
OSS Ubuntu OSS Linux/Ubuntu x86_64
OSS Windows OSS Windows x86_64

Downloads

Platform Status
Commercial Xamarin.Android 7.3 (d15-2) for macOS Commercial Xamarin.Android 7.3, macOS
Commercial Xamarin.Android 7.4 (d15-3) for macOS Commercial Xamarin.Android 7.4, macOS
Commercial Xamarin.Android 8.0 (d15-4) for macOS & Windows+Visual Studio 2017 Commercial Xamarin.Android 8.0, macOS+VS2017
Commercial Xamarin.Android 8.1 (d15-5) for macOS & Windows+Visual Studio 2017 Commercial Xamarin.Android 8.1, macOS+VS2017
Commercial Xamarin.Android 8.2 (d15-6) for macOS & Windows+Visual Studio 2017 Commercial Xamarin.Android 8.1, macOS+VS2017
Commercial Xamarin.Android 8.2.99 (master) for macOS & Windows+Visual Studio 2017 Commercial Xamarin.Android 8.2.99, macOS

Build Requirements

Building Xamarin.Android requires:

The make prepare build step (or /t:Prepare on Windows) will check that all required dependencies are present. If you would like make prepare to automatically install required dependencies, set the $(AutoProvision) MSBuild property to True and (if necessary) set the $(AutoProvisionUsesSudo) property to True. (This is not supported on all operating systems.)

If $(AutoProvision) is False (the default) and a dependency is missing, then the build will fail and an error message will be displayed attempting to provide install instructions to obtain the missing dependency, e.g.:

error : Could not find required program '7za'. Please run: brew install 'p7zip'.

Mono MDK

Latest Mono is required to build on OS X and Linux. The build will tell you if your version is outdated.

Java Development Kit

The Java Development Kit may be downloaded from the Oracle Java SE Downloads page.

Autotools

Autotools -- including autoconf and automake -- are required to build the Mono runtimes.

On OS X, autotools are distributed with Mono.framework.

If you run into issues regarding autoconf or automake try to install it with brew via:

brew install automake

Android NDK, SDK

Note: A xamarin-android checkout maintains its own Android NDK + SDK to ensure consistent builds and build behavior, permitting reproducible builds and providing greater flexibility around when we need to perform Android SDK + NDK updates. The Android SDK and NDK are maintained by default via two directories in your home directory:

  • $(AndroidToolchainCacheDirectory): Where downloaded files are cached. Defaults to the $HOME/android-archives directory.
  • $(AndroidToolchainDirectory): Where the Android NDK and SDK are installed. Defaults to the $HOME/android-toolchain directory.

Developers may use these directories for their own use, but please DO NOT update or alter the contents of the $(AndroidToolchainDirectory), as that may prevent the xamarin-android build from working as expected.

The files that will be downloaded and installed are controlled by build-tools/android-toolchain/android-toolchain.projitems via the @(AndroidNdkItem) and @(AndroidSdkItem) item groups, and the URL to download files from is controlled by the $(AndroidUri) property.

Build Configuration

The Xamarin.Android build is heavily dependent on MSBuild, with the intention that it should (eventually?) be possible to build the project simply by checking out the repo, loading Xamarin.Android.sln into an IDE, and Building the solution. (This isn't currently possible, and may never be, but it's the vision.)

However, some properties may need to be altered in order to suit your requirements, such as the location of a cache directory to store the Android SDK and NDK.

To modify the build process, copy Configuration.Override.props.in to Configuration.Override.props, and edit the file as appropriate. Configuration.Override.props is <Import/>ed by Configuration.props and will override any default values specified in Configuration.props.

Overridable MSBuild properties include:

  • $(AutoProvision): Automatically install required dependencies, if possible.

  • $(AutoProvisionUsesSudo): Use sudo when installing dependencies.

  • $(AndroidApiLevel): The Android API level to bind in src/Mono.Android. This is an integer value, e.g. 15 for API-15 (Android 4.0.3).

  • $(AndroidFrameworkVersion): The Xamarin.Android $(TargetFrameworkVersion) version which corresponds to $(AndroidApiLevel). This is usually the Android version number with a leading v, e.g. v4.0.3 for API-15.

  • $(AndroidSupportedHostJitAbis): The Android ABIs for which to build a host JIT and Xamarin.Android base class libraries (mscorlib.dll/etc.). The "host JIT" is used e.g. with the Xamarin Studio Designer, to render Xamarin.Android apps on the developer's machine. There can also be support for cross-compiling mono for a different host, e.g. to build Windows libmonosgen-2.0.dll from OS X. Supported host values include:

    • Darwin
    • Linux
    • mxe-Win64: Cross-compile Windows 64-bit binaries from Unix.

    The default value is $(HostOS), where $(HostOS) is based on probing various environment variables and filesystem locations. On OS X, the default would be Darwin.

  • $(AndroidSupportedTargetAotAbis): The Android ABIs for which to build the Mono AOT compilers. The AOT compilers are required in order to set the $(AotAssemblies) app configuration property to True.

  • $(AndroidSupportedTargetJitAbis): The Android ABIs for which to build the the Mono JIT for inclusion within apps. This is a :-separated list of ABIs to build. Supported values are:

    • armeabi
    • armeabi-v7a
    • arm64-v8a
    • x86
    • x86_64
  • $(AndroidToolchainCacheDirectory): The directory to cache the downloaded Android NDK and SDK files. This value defaults to $(HOME)\android-archives.

  • $(AndroidToolchainDirectory): The directory to install the downloaded Android NDK and SDK files. This value defaults to $(HOME)\android-toolchain.

  • $(HostCc), $(HostCxx): The C and C++ compilers to use to generate host-native binaries.

  • $(IgnoreMaxMonoVersion): Skip the enforcement of the $(MonoRequiredMaximumVersion) property. This is so that developers can run against the latest and greatest. But the build system can enforce the min and max versions. The default is true however on jenkins we pass /p:IgnoreMaxMonoVersion=False by default.

  • $(JavaInteropSourceDirectory): The Java.Interop source directory to build and reference projects from. By default, this is external/Java.Interop directory, maintained by git submodule update.

  • $(MakeConcurrency): make(1) parameters to use intended to influence the number of CPU cores used when make(1) executes. By default this uses -jCOUNT, where COUNT is obtained from sysctl hw.ncpu.

  • $(MonoRequiredMinimumVersion): The minimum system mono version that is supported in order to allow a build to continue. Policy is to require a system mono which corresponds vaguely to the external/mono version. This is not strictly required; older mono versions may work, they just are not tested, and thus not guaranteed or supported.

  • $(MonoRequiredMaximumVersion): The max system mono version that is required. This is so that we can ensure a stable build environment by making sure we dont install unstable versions.

  • $(MonoSgenBridgeVersion): The Mono SGEN Bridge version to support. Valid values include:

    • 4: Mono 4.6 support.
    • 5: Mono 4.8 and above support. This is the default.

Build

Xamarin.Android can be built on Linux, macOS, and Windows.

Linux and macOS

To build Xamarin.Android, first prepare the project:

make prepare

This will perform git submodule update, and any other pre-build tasks that need to be performed. After this process is completed, ensure there is no existing git changes in the external folder.

On the main repo, you can use git status to ensure a clean slate.

Next, run make:

make

The default make all target will only build a subset of runtime ABIs and $(TargetFrameworkVersion)s. If you want a complete environment -- all the ABIs, all the API levels -- then instead use:

make jenkins

Unit tests are built in a separate target:

make all-tests

Windows

To build Xamarin.Android, ensure you are using MSBuild version 15+ and run:

msbuild Xamarin.Android.sln /t:Prepare
msbuild Xamarin.Android.sln

These are roughly the same as how make prepare and make are used on other platforms.

Unit tests are built on Windows via:

msbuild Xamarin.Android-Tests.sln /p:XAIntegratedTests=False 

NOTE: there is not currently an equivalent of make jenkins on Windows.

Troubleshooting: Ensure you check your MSBuild version(msbuild -version) and path for the proper version of MSBuild.

Linux build notes

If you have the binfmt_misc module enabled with any of Mono or Wine installed and you plan to cross-build the Windows compilers and tools (by enabling the mxe-Win32 or mxe-Win64 host targets) as well as LLVM+AOT targets, you will need to disable binfmt_misc for the duration of the build or the Mono/LLVM configure scripts will fail to detect they are cross-compiling and they will produce Windows PE executables for tools required by the build.

To disable binfmt_misc you need to issue the following command as root:

echo 0 > /proc/sys/fs/binfmt_misc/status

and to enable it again, issue the following command:

echo 1 > /proc/sys/fs/binfmt_misc/status

macOS Build Notes

The android-toolchain.projitems, libzip.projitems, and monodroid.projitems project files, among others, use the @(RequiredProgram) build action to check for the existence of a program within $PATH during the build. If a required program doesn't exist, then the build will fail and a suggested brew install command line will be provided to install the missing commands.

Brew Programs

Suggested brew install commands:

brew install cmake
brew install libtool
brew install p7zip
brew install gdk-pixbuf
brew install gettext
brew install coreutils
brew install findutils
brew install gnu-tar
brew install gnu-sed
brew install gawk
brew install gnutls
brew install gnu-indent
brew install gnu-getopt
brew install intltool
brew install scons
brew install wget
brew install xz

If any program is still not found, try to ensure it's linked via:

brew link <package name>

Using Your Build

Once the build has finished, tools/scripts/xabuild may be used on Unix-like platforms to build projects. See the Samples section for example usage.

Windows users will need to use the setup-windows.exe tool as described in Documentation/UsingJenkinsBuildArtifacts.md.

Using Jenkins Build Artifacts

Please see Documentation/UsingJenkinsBuildArtifacts.md for details on using prebuilt Xamarin.Android binaries.

Build Output Directory Structure

There are two configurations, Debug and Release, controlled by the $(Configuration) MSBuild property.

The bin\Build$(Configuration) directory, e.g. bin\BuildDebug, contains artifacts needed for building the repository. They should not be needed for later execution.

The bin\$(Configuration) directory, e.g. bin\Debug, contains redistributable artifacts, such as tooling and runtimes. This directory acts as a local installation prefix, in which the directory structure mirrors that of the OS X Xamarin.Android.framework directory structure:

  • bin\$(Configuration)\lib\xamarin.android\xbuild\Xamarin\Android: MSBuild-related support files and required runtimes used by the MSBuild tooling.
  • bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\MonoAndroid: Xamarin.Android profiles.
  • bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\MonoAndroid\v1.0: Xamarin.Android Base Class Library assemblies such as mscorlib.dll.
  • bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\MonoAndroid\*: Contains Mono.Android.dll for a given Xamarin.Android $(TargetFrameworkVersion).

Xamarin.Android $(TargetFrameworkVersion)s

Xamarin.Android uses the MSBuild $(TargetFrameworkVersion) mechanism to provide a separate Mono.Android.dll binding assembly for each API level.

This means there is no single Mono.Android.dll, there is instead a set of them.

This complicates the "mental model" for the Mono.Android project, as a project can have only one output, not many (...within reason...). As such, building the Mono.Android project will only generate a single Mono.Android.dll.

To control which API level is bound, set the $(AndroidApiLevel) and $(AndroidFrameworkVersion) properties. $(AndroidApiLevel) is the Android API level, usually a number, while $(AndroidFrameworkVersion) is the Xamarin.Android $(TargetFrameworkVersion).

The default values will target Android API-25, Android 7.1.

For example, to generate Mono.Android.dll for API-19 (Android 4.4):

cd src/Mono.Android
xbuild /p:AndroidApiLevel=19 /p:AndroidFrameworkVersion=v4.4
# creates bin\Debug\lib\xamarin.android\xbuild-frameworks\MonoAndroid\v4.4\Mono.Android.dll

Samples

The HelloWorld sample may be built with the xabuild script:

$ tools/scripts/xabuild /t:SignAndroidPackage samples/HelloWorld/HelloWorld.csproj

xabuild /t:SignAndroidPackage will generate an .apk file, which may be installed onto an Android device with the adb install command:

$ adb install samples/HelloWorld/bin/Debug/com.xamarin.android.helloworld-Signed.apk

HelloWorld may be launched manually through the Android app launcher, or via adb shell am:

$ adb shell am start com.xamarin.android.helloworld/example.MainActivity

Contributing

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information, see the .NET Foundation Code of Conduct.

Mailing Lists

To discuss this project, and participate in the design, we use the android-devel@lists.xamarin.com mailing list.

Coding Guidelines

We use Mono's Coding Guidelines.

Reporting Bugs

We use Github Issues to track issues within this repository.

For general Xamarin.Android experience issues within Visual Studio 2017 or Visual Studio for Mac, please use the Report a Problem feature inside the IDE. You can find this by going to Help > Report a Problem within your IDE.

Maintainer FAQ

See DevelopmentTips.md.