Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tasks] Feature for excluding Kotlin-related files from apps #7356

Merged
merged 11 commits into from
Sep 13, 2022

Conversation

dellis1972
Copy link
Contributor

Fixes #6920

Add a new ItemGroup AndroidPackagingOptionsExclude to the common targets. This ItemGroup will contain a set of RegEx compatible patterns which will be used to exclude certain files from the final apk/aab.

The patterns will need to be Url encoded so that MSBuild does not try to interpret them.

The main purpose of this is to allow us to exclude certain Kotlin meta-data files from the final package. These files seem to be excluded by gradle so we should do the same.

…les from apps

Fixes dotnet#6920

Add a new ItemGroup `AndroidPackagingOptionsExclude` to the common
targets. This ItemGroup will contain a set of RegEx compatible patterns
which will be used to exlcude certain files from the final apk/aab.

The patterns will need to be Url encoded so that MSBuild does not try
to interpret them.

The main purpose of this is to allow us to exclude certain Kotlin meta-data
files from the final package. These files seem to be excluded by gradle
so we should do the same.
@dellis1972
Copy link
Contributor Author

We will need this too https://github.com/xamarin/monodroid/pull/1265

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, looks good if CI is green.

Documentation/guides/building-apps/build-items.md Outdated Show resolved Hide resolved
Co-authored-by: Jonathan Peppers <jonathan.peppers@gmail.com>
@jonpryor
Copy link
Member

Fixes: https://github.com/xamarin/xamarin-android/issues/6920

Certainly NuGet packages pull in Kotlin-related artifacts which
aren't required at runtime.  These artifacts contribute to `.apk`
package size.

The [recommendation for native Android developers][0] is to
explicitly exclude these artifacts by using `packagingOptions`:

	packagingOptions {
	  exclude 'DebugProbesKt.bin'
	}

Xamarin.Android and .NET SDK for Android developers don't use Gradle,
so the above snippet is not useful.

Add support for a new `@(AndroidPackagingOptionsExclude)` item group.
This contains a "search pattern" a'la the `searchPattern` parameter
of [`Directory.EnumerateFiles(path, searchPattern)`][1], in which:

  * `*` matches 0 or more characters
  * `?` matches 1 character.

The default items within `@(AndroidPackagingOptionsExclude)` are:

  * `DebugProbesKt.bin`
  * `*.kotlin_*`

Files which match the search patterns within
`@(AndroidPackagingOptionsExclude)` are *excluded* from `.aab` and
`.apk` files, reducing app size.

[0]: https://github.com/Kotlin/kotlinx.coroutines/issues/2274
[1]: https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.enumeratefiles?view=net-6.0#system-io-directory-enumeratefiles(system-string-system-string)

@jonpryor jonpryor merged commit 2726a38 into dotnet:main Sep 13, 2022
@dellis1972 dellis1972 deleted the Issue6920 branch September 13, 2022 22:34
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 14, 2022
* main:
  [Xamarin.Android.Build.Tasks] Add AndroidPackagingOptionsExclude (dotnet#7356)
  [linker] preserve Java interfaces on non-bound Java types (dotnet#7204)
  [Xamarin.Android.Build.Tasks] AndroidLinkResources and Styleables (dotnet#7306)
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Done & Blogged
Development

Successfully merging this pull request may close these issues.

Feature for excluding Kotlin-related files from apps
3 participants