xamarin / AndroidX

AndroidX bindings for .NET for Android
MIT License
173 stars 42 forks source link

Use `<AndroidLibrary>` rather than `.targets` files. #890

Open jpobst opened 1 month ago

jpobst commented 1 month ago

Previously, our template would create bindings using <InputJar>, then manually add the jar/aar and any Proguard files to the .nupgk, and then use a .targets file to add these payloads to the Android application.

This was likely done for 2 reasons:

In .NET times, both of these issues have been resolved, and we can replace our custom hacks with the built-in <AndroidLibrary> build item, reducing the maintenance burden of custom solutions.


Note there is an issue with resources if the name of the included .aar is different from what our previous package versions named it:

error APT2260: resource style/TextAppearance.Compat.Notification.Info (aka com.companyname.BuildAllDotNet:style/TextAppearance.Compat.Notification.Info) not found. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]
error APT2260: resource style/TextAppearance.Compat.Notification.Info (aka com.companyname.BuildAllDotNet:style/TextAppearance.Compat.Notification.Info) not found. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]
error APT2260: resource style/TextAppearance.Compat.Notification.Info (aka com.companyname.BuildAllDotNet:style/TextAppearance.Compat.Notification.Info) not found. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]
error APT2260: resource style/TextAppearance.Compat.Notification (aka com.companyname.BuildAllDotNet:style/TextAppearance.Compat.Notification) not found. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]
error APT2260: resource style/TextAppearance.Compat.Notification (aka com.companyname.BuildAllDotNet:style/TextAppearance.Compat.Notification) not found. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]
error APT2260: resource style/TextAppearance.Compat.Notification (aka com.companyname.BuildAllDotNet:style/TextAppearance.Compat.Notification) not found. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]
error APT2260: resource style/TextAppearance.Compat.Notification.Time (aka com.companyname.BuildAllDotNet:style/TextAppearance.Compat.Notification.Time) not found. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]
error APT2260: resource style/TextAppearance.Compat.Notification.Time (aka com.companyname.BuildAllDotNet:style/TextAppearance.Compat.Notification.Time) not found. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]
error APT2260: resource style/TextAppearance.Compat.Notification.Time (aka com.companyname.BuildAllDotNet:style/TextAppearance.Compat.Notification.Time) not found. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]
error APT2260: resource style/TextAppearance.Compat.Notification.Title (aka com.companyname.BuildAllDotNet:style/TextAppearance.Compat.Notification.Title) not found. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]
error APT2260: resource style/TextAppearance.Compat.Notification.Title (aka com.companyname.BuildAllDotNet:style/TextAppearance.Compat.Notification.Title) not found. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]
error APT2260: resource style/TextAppearance.Compat.Notification.Title (aka com.companyname.BuildAllDotNet:style/TextAppearance.Compat.Notification.Title) not found. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]
error APT2062: failed linking references. [/Users/runner/work/1/s/samples/dotnet/BuildAllDotNet/BuildAllDotNet.csproj]

I was unable to find the root cause of this, so I added a workaround to rename the Java library the same as we previously used. (@(art.MavenGroupId).@(art.MavenArtifactId).[jar|aar])

jpobst commented 1 month ago

Original package example:

image

New package example:

image

A future PR will try to remove the .targets file completely by moving the remaining line to a common base package.