Skip to content

Xamarin.AndroidX.Compose.Runtime.Annotation.Android and Xamarin.AndroidX.SavedState.SavedState.Compose incorrectly include .aar files as AndroidJavaLibrary instead of AndroidAarLibrary in .targets files #1383

@jakob-grabner

Description

@jakob-grabner

Android framework version

net10.0-android

Affected platform version

net10.0

Description

The .targets files shipped in both build/ and buildTransitive/ for this package include the file aar/runtime-annotation-android.aar using the AndroidJavaLibrary MSBuild item type:

build/net10.0-android36.0/Xamarin.AndroidX.Compose.Runtime.Annotation.Android.targets

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <AndroidJavaLibrary Condition=" '$(AndroidApplication)' == 'true' " Include="$(MSBuildThisFileDirectory)..\..\aar\*.aar" />
  </ItemGroup>
</Project>

AndroidJavaLibrary is intended for .jar files. The correct item type for .aar files is AndroidAarLibrary. Using AndroidJavaLibrary for an .aar causes any tools that iterate over that item list expecting plain Java bytecode to fail, and silently drops any resources, AndroidManifest.xml entries, and native libs contained in the AAR.

Xamarin.AndroidX.SavedState.SavedState.Compose has the same issue.

Steps to Reproduce

Just look into package
https://nuget.info/packages/Xamarin.AndroidX.SavedState.SavedState.Compose/1.4.0.2
Check build/net10.0-android36.0/Xamarin.AndroidX.SavedState.SavedState.Compose.targets
https://nuget.info/packages/Xamarin.AndroidX.Compose.Runtime.Annotation.Android/1.10.4.1
Check build/net10.0-android36.0/Xamarin.AndroidX.Compose.Runtime.Annotation.Android.targets

Did you find any workaround?

<Target Name="FixAarLibraries" BeforeTargets="ResolveAssemblyReferences;_ResolveLibraryProjectImports" Condition="$(TargetFramework.Contains('-android'))">
	<ItemGroup>
		<AndroidAarLibrary Include="@(AndroidJavaLibrary)" Condition="'%(Extension)' == '.aar' And $([System.String]::Copy('%(Identity)').Contains('xamarin.androidx.compose.runtime.annotation.android'))" />
		<AndroidJavaLibrary Remove="@(AndroidJavaLibrary)" Condition="'%(Extension)' == '.aar' And $([System.String]::Copy('%(Identity)').Contains('xamarin.androidx.compose.runtime.annotation.android'))" />
		<AndroidAarLibrary Include="@(AndroidJavaLibrary)" Condition="'%(Extension)' == '.aar' And $([System.String]::Copy('%(Identity)').Contains('xamarin.androidx.savedstate.savedstate.compose'))" />
		<AndroidJavaLibrary Remove="@(AndroidJavaLibrary)" Condition="'%(Extension)' == '.aar' And $([System.String]::Copy('%(Identity)').Contains('xamarin.androidx.savedstate.savedstate.compose'))" />
	</ItemGroup>
</Target>

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions