Build items control how a .NET for Android application
or library project is built.
They're specified within the project file, for example MyApp.csproj, within
an MSBuild ItemGroup.
Uwaga
In .NET for Android there is technically no distinction between an application and a bindings project, so build items will work in both. In practice it is highly recommended to create separate application and bindings projects. Build items that are primarily used in bindings projects are documented in the MSBuild bindings project items reference guide.
AndroidAdditionalJavaManifest
<AndroidAdditionalJavaManifest> is used in conjunction with
Java Dependency Resolution
to specify additional POM files that will be needed to verify dependencies.
These are often parent or imported POM files referenced by a Java library's POM file.
Supports Android Assets,
files that would be included in the assets folder in a Java Android project.
Starting with .NET 9 the @(AndroidAsset) build action also supports additional metadata for generating Asset Packs. The %(AndroidAsset.AssetPack) metadata can be used to automatically generate an asset pack of that name. This feature is only supported when the $(AndroidPackageFormat) is set to .aab. The following example will place movie2.mp4 and movie3.mp4 in separate asset packs.
This feature can be used to include large files in your application which would normally exceed the max
package size limits of Google Play.
If you have a large number of assets it might be more efficient to make use of the base asset pack.
In this scenario you update ALL assets to be in a single asset pack then use the AssetPack="base" metadata
to declare which specific assets end up in the base aab file. With this you can use wildcards to move most
assets into the asset pack.
In this example, movie.mp4 and some.png will end up in the base aab file, while all the other assets
will end up in the assets1 asset pack.
The additional metadata is only supported on .NET for Android 9 and above.
AndroidAarLibrary
The Build action of AndroidAarLibrary should be used to directly
reference .aar files. This build action will be most commonly used
by Xamarin Components. Namely to include references to .aar files
that are required to get Google Play and other services working.
Files with this Build action will be treated in a similar fashion to
the embedded resources found in Library projects. The .aar will be
extracted into the intermediate directory. Then any assets, resource
and .jar files will be included in the appropriate item groups.
AndroidAotProfile
Used to provide an AOT profile, for use with profile-guided AOT.
It can be also used from Visual Studio by setting the AndroidAotProfile
build action to a file containing an AOT profile.
AndroidAppBundleMetaDataFile
Specifies a file that will be included as metadata in the Android App Bundle.
The format of the flag value is <bundle-path>:<physical-file> where
bundle-path denotes the file location inside the App Bundle's metadata
directory, and physical-file is an existing file containing the raw data
to be stored.
Files with a Build action of AndroidEnvironment are used
to initialize environment variables and system properties during process startup.
The AndroidEnvironment Build action may be applied to
multiple files, and they will be evaluated in no particular order (so don't
specify the same environment variable or system property in multiple
files).
AndroidGradleProject
<AndroidGradleProject> can be used to build and consume the outputs
of Android Gradle projects created in Android Studio or elsewehere.
The Include metadata should point to the top level build.gradle or build.gradle.kts
file that will be used to build the project. This will be found in the root directory
of your Gradle project, which should also contain gradlew wrapper scripts.
%(Configuration): The name of the configuration to use to build or assemble
the project or project module specified. The default value is Release.
%(ModuleName): The name of the module or subproject that should be built.
The default value is empty.
%(OutputPath): Can be set to override the build output path of the Gradle project.
The default value is $(IntermediateOutputPath)gradle/%(ModuleName)%(Configuration)-{Hash}.
%(CreateAndroidLibrary): Output AAR files will be added as an AndroidLibrary to the project.
Metadata supported by <AndroidLibrary> like %(Bind) or %(Pack) will be forwarded if set.
The default value is true.
This build action was introduced in .NET 9.
AndroidJavaLibrary
Files with a Build action of AndroidJavaLibrary are Java
Archives ( .jar files) that will be included in the final Android
package.
It is used to specify a Java dependency that should be ignored. This can be
used if a dependency will be fulfilled in a way that Java dependency resolution
cannot detect.
XML
<!-- Include format is {GroupId}:{ArtifactId} --><ItemGroup><AndroidIgnoredJavaDependencyInclude="com.google.errorprone:error_prone_annotations"Version="2.15.0" /></ItemGroup>
The following MSBuild metadata are required:
%(Version): The version of the Java library matching the specified %(Include).
Files with a Build action of AndroidJavaSource are Java source code that
will be included in the final Android package.
Starting with .NET 7, all **\*.java files within the project directory
automatically have a Build action of AndroidJavaSource, and will be
bound prior to the Assembly build. Allows C# code to easily use
types and members present within the **\*.java files.
Set %(AndroidJavaSource.Bind) to False to disable this behavior.
AndroidLibrary
AndroidLibrary is a new build action for simplifying how
.jar and .aar files are included in projects.
This simplification means you can use AndroidLibrary everywhere.
AndroidLintConfig
The Build action 'AndroidLintConfig' should be used in conjunction with the
$(AndroidLintEnabled)
property. Files with this build action will be merged together and passed to the
android lint tooling. They should be XML files containing information on
tests to enable and disable.
The AndroidManifestOverlay build action can be used to provide
AndroidManifest.xml files to the Manifest Merger tool.
Files with this build action will be passed to the Manifest Merger along with
the main AndroidManifest.xml file and manifest files from
references. These will then be merged into the final manifest.
You can use this build action to provide changes and settings to
your app depending on your build configuration. For example, if you need to
have a specific permission only while debugging, you can use the overlay to
inject that permission when debugging. For example, given the following
overlay file contents:
Specifies the modules that get installed by bundletool command when
installing app bundles.
AndroidMavenLibrary
<AndroidMavenLibrary> allows a Maven artifact to be specified which will
automatically be downloaded and added to a .NET for Android binding project.
This can be useful to simplify maintenance of .NET for Android bindings for artifacts
hosted in Maven.
XML
<!-- Include format is {GroupId}:{ArtifactId} --><ItemGroup><AndroidMavenLibraryInclude="com.squareup.okhttp3:okhttp"Version="4.9.3" /></ItemGroup>
The following MSBuild metadata are supported:
%(Version): Required version of the Java library referenced by %(Include).
%(Repository): Optional Maven repository to use. Supported values are Central (default),
Google, or an https URL to a Maven repository.
The <AndroidMavenLibrary> item is translated to
AndroidLibrary, so any metadata supported by
<AndroidLibrary> like %(Bind) or %(Pack) are also supported.
Native libraries
are added to the build by setting their Build action to
AndroidNativeLibrary.
Note that since Android supports multiple Application Binary Interfaces
(ABIs), the build system must know the ABI the native library is
built for. There are two ways the ABI can be specified:
Path "sniffing".
Using the %(Abi) item metadata.
With path sniffing, the parent directory name of the native library is
used to specify the ABI that the library targets. Thus, if you add
lib/armeabi-v7a/libfoo.so to the build, then the ABI will be "sniffed" as
armeabi-v7a.
Items can use file blob characters for wildcards such as * and ?.
However these Items MUST be URL encoded or use
$([MSBuild]::Escape('')).
This is so MSBuild does not try to interpret them as actual file wildcards.
Items can use file blob characters for wildcards such as * and ?.
However these Items MUST use URL encoding or '$([MSBuild]::Escape(''))'.
This is so MSBuild does not try to interpret them as actual file wildcards.
For example
NOTE: *, ? and . will be replaced in the BuildApk task with the
appropriate file globs.
Added in .NET 9.
AndroidResource
All files with an AndroidResource build action are compiled into
Android resources during the build process and made accessible via $(AndroidResgenFile).
More advanced users might perhaps wish to have different resources used in
different configurations but with the same effective path. This can be achieved
by having multiple resource directories and having files with the same relative
paths within these different directories, and using MSBuild conditions to
conditionally include different files in different configurations. For
example:
The normal Content Build action is not supported (as we
haven't figured out how to support it without a possibly costly first-run
step).
Attempting to use the @(Content) Build action will result in a
XA0101 warning.
EmbeddedJar
In a .NET for Android binding project, the EmbeddedJar build action
binds the Java/Kotlin library and embeds the .jar file into the
library. When a .NET for Android application project consumes the
library, it will have access to the Java/Kotlin APIs from C# as well
as include the Java/Kotlin code in the final Android application.
You should instead use the
AndroidLibrary build action as an alternative
such as:
In a .NET for Android class library or Java binding project, the
EmbeddedNativeLibrary build action bundles a native library such
as lib/armeabi-v7a/libfoo.so into the library. When a
.NET for Android application consumes the library, the libfoo.so file
will be included in the final Android application.
In a .NET for Android binding project, the EmbeddedReferenceJar
build action embeds the .jar file into the library but does not
create a C# binding as EmbeddedJar does. When a
.NET for Android application project consumes the library, it will
include the Java/Kotlin code in the final Android application.
You can use the
AndroidLibrary build action as an alternative
such as <AndroidLibrary Include="..." Bind="false" />:
XML
<Project><ItemGroup><!-- A .jar file to bind & embed --><AndroidLibraryInclude="Library.jar" /><!-- A .jar file to only embed --><AndroidLibraryInclude="Dependency.jar"Bind="false" /></ItemGroup></Project>
JavaSourceJar
In a .NET for Android binding project, the JavaSourceJar build action
is used on .jar files that contain Java source code, that contain
Javadoc documentation comments.
%(CopyrightFile): A path to a file that contains copyright
information for the Javadoc contents, which will be appended to
all imported documentation.
%(UrlPrefix): A URL prefix to support linking to online
documentation within imported documentation.
%(UrlStyle): The "style" of URLs to generate when linking to
online documentation. Only one style is currently supported:
developer.android.com/reference@2020-Nov.
%(DocRootUrl): A URL prefix to use in place of all {@docroot}
instances in the imported documentation.
LibraryProjectZip
The LibraryProjectZip build
action binds the Java/Kotlin library and embeds the .zip or .aar
file into the library. When a .NET for Android application project
consumes the library, it will have access to the Java/Kotlin APIs from
C# as well as include the Java/Kotlin code in the final Android
application.
Files with a ProguardConfiguration build action contain options which
are used to control proguard behavior. For more information about
this build action, see
ProGuard.
These files are ignored unless the
$(EnableProguard)
MSBuild property is True.
Dołącz do serii meetup, aby tworzyć skalowalne rozwiązania sztucznej inteligencji oparte na rzeczywistych przypadkach użycia z innymi deweloperami i ekspertami.