-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] Add @(AndroidPackagingOptionsInclude) (#…
…8459) Context: #8456 Context: 2726a38 Context: xamarin/monodroid@43583d0 Commit 2726a386added the `@(AndroidPackagingOptionsExclude)` ItemGroup, which is used to exclude certain files from the final apk. xamarin/monodroid@43583d02 updated the `_BuildApkFastDev` target so that `@(AndroidPackagingOptionsExclude)` was provided to `<BuildApk/>`. `@(AndroidPackagingOptionsExclude)` was initially designed to filter out Kotlin based meta data: <AndroidPackagingOptionsExclude Include="$([MSBuild]::Escape('*.kotlin_*'))" /> However, it turns out the default file glob of `*.kotlin_*` is too restrictive, removing e.g. `kotlin/reflect/reflect.kotlin_builtins`, which can result in runtime errors (see #8456): java.lang.AssertionError: Built-in class kotlin.Any is not found at kotlin.reflect.jvm.internal.impl.builtins.KotlinBuiltIns$3.invoke(KotlinBuiltIns.java:93) The "obvious" workaround is to `%(Remove)` the offending item: <ItemGroup> <AndroidPackagingOptionsExclude Remove="$([MSBuild]::Escape('*.kotlin_*'))" /> </ItemGroup> Unfortunately this doesn't work, because of the order in which `<ItemGroups/>`s are evaluated by MSBuild. At the time the `.csproj` is evaluated, `Xamarin.Android.Common.targets` has not yet been loaded, and thus `@(AndroidPackagingOptionsExclude)` has not yet been set. The "less obvious but works" workaround is to change the item group within a target: <Target Name="_UpdateAndroidPackagingOptionsExclude" AfterTargets="AfterBuild"> <ItemGroup> <AndroidPackagingOptionsExclude Remove="$([MSBuild]::Escape('*.kotlin_*'))" /> <AndroidPackagingOptionsExclude Include="$([MSBuild]::Escape('*.kotlin_m*'))" /> </ItemGroup> </Target> This is not very intuitive. Make this easier by moving the definition of the default `@(AndroidPackagingOptionsExclude)` values into `AutoImport.props`, which happens before the `.csproj` is read. This allows the more "obvious" `%(Remove)` usage to work as expected. The next problem is that the default file glob of `*.kotlin_*` was too expansive, excluding the `*.kotlin_builtins` files which we now know are important. We could try changing the default glob to something else, such as the `*.kotlin_m*` value used by `_UpdateAndroidPackagingOptionsExclude`, but this can mean that files we didn't want to include are now included. Partially rethink things by introducing a new `@(AndroidPackagingOptionsInclude)` item group, which contains file globs. Any packaging artifact which matches the `@(AndroidPackagingOptionsInclude)` file glob will be included, before `@(AndroidPackagingOptionsInclude)` has a chance to exclude it. `@(AndroidPackagingOptionsInclude)` will be public, and can be used by NuGet packages such as [Xamarin.Kotlin.Reflect][0] to ensure that specific files are included. This can be done in the NuGet by providing a `.targets` file which adds items to `@(AndroidPackagingOptionsInclude)`. [0]: https://www.nuget.org/packages/Xamarin.Kotlin.Reflect
- Loading branch information
1 parent
b869d27
commit 81001af
Showing
6 changed files
with
125 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters