-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[One .NET] use .aar instead of @(EmbeddedResource) (#5131)
Fixes: #2441 Implements: Documentation/proposals/OneDotNetEmbeddedResources.md The creation of the `@(EmbeddedResource)` files: * `__AndroidEnvironment__*` * `__AndroidLibraryProjects__.zip` * `__AndroidNativeLibraries__.zip` * `*.jar` ...has moved to `Xamarin.Android.Legacy.targets`. For One .NET, add a new `_CreateAar` MSBuild target and `<CreateAar/>` MSBuild task which now creates `.aar` files in `$(OutputPath)` for class libraries. The `_ResolveAars` MSBuild target will locate `.aar` files next to .NET assemblies and use them if found. The MSBuild targets/tasks for consuming `@(EmbeddedResource)` files in assemblies remains in place for backwards compatibility. The only change was to support the new `.netenv` directory inside `.aar` files. The `_CategorizeAndroidLibraries` MSBuild target handles setting up the new, simplified `@(AndroidLibrary)` item group. I added several tests for these scenarios. Other changes: * A new `<ExtractJarsFromAar/>` MSBuild task is needed for `@(LibraryProjectZip)` items for Java bindings. This task extracts `.jar` files to `$(IntermediateOutputPath)library_project_jars` and `annotations.zip` items to `$(IntermediateOutputPath)library_project_annotations`. * The `@(LibraryProjectZip)` item group now works in .NET 5+. We no longer need the `LibraryProjectZip` test category, as these tests pass. Several of these tests needed to set `ProjectName` as they had two projects named `UnnamedProject.csproj`. * `<ResolveLibraryProjectImports/>` needs to store the full file *and* the extension in `obj\$(Configuration)\lp\map.cache` now as you would commonly have both a `Foo.dll` and `Foo.aar`. I had to adjust `AssemblyIdentityMap` to account for this. * `.aar` files can no longer assume `%(AndroidSkipResourceProcessing)` is `false` by default. `.aar` files coming from Xamarin.Android class libraries could have custom views that need to be fixed up at build time in the main Xamarin.Android application project. * When the nested, inner build for the `_ComputeFilesToPublishForRuntimeIdentifiers` MSBuild target runs, I further trimmed down which targets run. `IncrementalClean` was running multiple times and deleting files! * Fixed where `Files.ExtractAll()` was extracting a `.DS_Store` file in the root of `.aar` files.
- Loading branch information
1 parent
c814358
commit fcd7cf8
Showing
33 changed files
with
981 additions
and
291 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...n/proposals/OneDotNetEmbeddedResources.md → ...tion/guides/OneDotNetEmbeddedResources.md
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
121 changes: 121 additions & 0 deletions
121
....Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AndroidLibraries.targets
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<!-- | ||
*********************************************************************************************** | ||
Microsoft.Android.Sdk.AndroidLibraries.targets | ||
This file contains the .NET 5-specific targets related to | ||
@(AndroidLibrary) items and .aar files generation for class library | ||
projects. | ||
*********************************************************************************************** | ||
--> | ||
<Project> | ||
|
||
<UsingTask TaskName="Xamarin.Android.Tasks.CreateAar" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" /> | ||
<UsingTask TaskName="Xamarin.Android.Tasks.ExtractJarsFromAar" AssemblyFile="$(_XamarinAndroidBuildTasksAssembly)" /> | ||
|
||
<ItemGroup> | ||
<AvailableItemName Include="AndroidLibrary" /> | ||
</ItemGroup> | ||
<ItemDefinitionGroup> | ||
<AndroidLibrary> | ||
<Bind>false</Bind> | ||
<Pack>true</Pack> | ||
</AndroidLibrary> | ||
</ItemDefinitionGroup> | ||
<PropertyGroup> | ||
<_AarCacheFile>$(IntermediateOutputPath)$(TargetName).aar.cache</_AarCacheFile> | ||
<_AarOutputPath>$(OutputPath)$(TargetName).aar</_AarOutputPath> | ||
</PropertyGroup> | ||
|
||
<Target Name="_CategorizeAndroidLibraries"> | ||
<ItemGroup Condition=" '$(AndroidApplication)' == 'true' "> | ||
<AndroidAarLibrary Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.aar' " /> | ||
<AndroidJavaLibrary Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.jar' " /> | ||
<AndroidNativeLibrary Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.so' " /> | ||
</ItemGroup> | ||
<ItemGroup Condition=" '$(AndroidApplication)' != 'true' "> | ||
<AndroidAarLibrary Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.aar' and '%(AndroidLibrary.Bind)' != 'true' " /> | ||
<LibraryProjectZip Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.aar' and '%(AndroidLibrary.Bind)' == 'true' " /> | ||
<AndroidJavaLibrary Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.jar' and '%(AndroidLibrary.Bind)' != 'true' " /> | ||
<EmbeddedJar Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.jar' and '%(AndroidLibrary.Bind)' == 'true' " /> | ||
<EmbeddedNativeLibrary Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.so' " /> | ||
<None Include="@(LibraryProjectZip)" CopyToOutputDirectory="PreserveNewest" Link="%(Filename)%(Extension)" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="_ResolveAars" Condition=" '$(AndroidApplication)' == 'true' "> | ||
<ItemGroup> | ||
<_AarSearchDirectory Include="@(_ReferencePath->'%(RootDir)%(Directory)')" /> | ||
<_AarSearchDirectory Include="@(_ReferenceDependencyPaths->'%(RootDir)%(Directory)')" /> | ||
<_AarDistinctDirectory Include="@(_AarSearchDirectory->Distinct())" /> | ||
<_AarFromLibraries Include="%(_AarDistinctDirectory.Identity)*.aar" /> | ||
</ItemGroup> | ||
<ItemGroup Condition=" '@(_AarFromLibraries->Count())' != '0' "> | ||
<AndroidAarLibrary Include="@(_AarFromLibraries)" Exclude="@(AndroidAarLibrary)" /> | ||
<!-- | ||
NOTE: %(AndroidSkipResourceProcessing) is required for located .aar's; there could be custom views. | ||
Update in a second step, in case there is was an existing @(AndroidAarLibrary) with the same path. | ||
--> | ||
<AndroidAarLibrary Update="@(_AarFromLibraries)" AndroidSkipResourceProcessing="false" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="_CreateAarCache" | ||
Condition=" '$(AndroidApplication)' != 'true' "> | ||
<ItemGroup> | ||
<_CreateAarInputs Include="@(AndroidAsset)" /> | ||
<_CreateAarInputs Include="@(_AndroidResourceDest)" /> | ||
<_CreateAarInputs Include="@(AndroidEnvironment)" /> | ||
<_CreateAarInputs Include="@(EmbeddedJar)" /> | ||
<_CreateAarInputs Include="@(EmbeddedNativeLibrary)" /> | ||
</ItemGroup> | ||
<Hash | ||
ItemsToHash="@(_CreateAarInputs)" | ||
IgnoreCase="false"> | ||
<Output TaskParameter="HashResult" PropertyName="_AarDependencyHash" /> | ||
</Hash> | ||
<WriteLinesToFile | ||
Condition=" '$(_AarDependencyHash)' != '' " | ||
Lines="$(_AarDependencyHash)" | ||
File="$(_AarCacheFile)" | ||
Overwrite="True" | ||
WriteOnlyWhenDifferent="True" | ||
/> | ||
<ItemGroup Condition=" '$(_AarDependencyHash)' != '' "> | ||
<_CreateAarInputs Include="$(_AarCacheFile)" /> | ||
<FileWrites Include="$(_AarCacheFile)" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="_CreateAar" | ||
Condition=" '$(AndroidApplication)' != 'true' " | ||
DependsOnTargets="_CreateAarCache" | ||
Inputs="@(_CreateAarInputs)" | ||
Outputs="$(_AarOutputPath)"> | ||
<CreateAar | ||
AssetDirectory="$(MonoAndroidAssetsPrefix)" | ||
AndroidAssets="@(AndroidAsset)" | ||
AndroidResources="@(_AndroidResourceDest)" | ||
AndroidEnvironment="@(AndroidEnvironment)" | ||
JarFiles="@(AndroidJavaLibrary);@(EmbeddedJar)" | ||
NativeLibraries="@(EmbeddedNativeLibrary)" | ||
OutputFile="$(_AarOutputPath)" | ||
/> | ||
<ItemGroup> | ||
<FileWrites Include="$(_AarOutputPath)" /> | ||
<None Include="$(_AarOutputPath)" Pack="true" PackagePath="lib\$(TargetFramework)" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="_ExtractAar" | ||
Inputs="@(LibraryProjectZip)" | ||
Outputs="$(_AndroidStampDirectory)_ExtractAar.stamp"> | ||
<ExtractJarsFromAar | ||
OutputJarsDirectory="$(IntermediateOutputPath)library_project_jars" | ||
OutputAnnotationsDirectory="$(IntermediateOutputPath)library_project_annotations" | ||
Libraries="@(LibraryProjectZip)" | ||
/> | ||
<Touch Files="$(_AndroidStampDirectory)_ExtractAar.stamp" AlwaysCreate="true" /> | ||
</Target> | ||
|
||
</Project> |
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
Oops, something went wrong.