Skip to content

Commit

Permalink
[Xamarin.Android.Glide] add multitargeting for .NET 6 (#1261)
Browse files Browse the repository at this point in the history
* Install latest .NET 6 & stable Xamarin.Android on CI
* Use Xamarin.Legacy.Sdk.
* Build with `dotnet build`
* Use `[assembly: AssemblyMetadata("IsTrimmable", "True")]`
* Use the same pattern as AndroidX, putting `.aar`/`.jar` files loose inside the NuGet package
* Set legacy compatibility properties mentioned here:

https://github.com/xamarin/xamarin-android/blob/5f408ebb22df51b598c62f776ee0f82f92661b58/Documentation/guides/OneDotNetBindingProjects.md

This also updates any AndroidX dependencies so that they are using the
new versions that *also* multitarget for .NET 6.
  • Loading branch information
jonathanpeppers committed Sep 16, 2021
1 parent 643cbc2 commit a245afa
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 137 deletions.
36 changes: 19 additions & 17 deletions Android/Glide/build.cake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var TARGET = Argument ("t", Argument ("target", "ci"));

var NUGET_PATCH = ".1";
var NUGET_PATCH = ".2";

var GLIDE_VERSION = "4.12.0";
var GLIDE_NUGET_VERSION = GLIDE_VERSION + NUGET_PATCH;
Expand All @@ -19,20 +19,23 @@ var RECYCLERVIEW_NUGET_VERSION = RECYCLERVIEW_VERSION + NUGET_PATCH;
var RECYCLERVIEW_URL = $"https://repo1.maven.org/maven2/com/github/bumptech/glide/recyclerview-integration/{RECYCLERVIEW_VERSION}/recyclerview-integration-{RECYCLERVIEW_VERSION}.aar";

Task ("externals")
.WithCriteria (!FileExists ("./externals/glide.aar"))
.WithCriteria (!FileExists ("./externals/glide/classes.jar"))
.Does (() =>
{
if (!DirectoryExists ("./externals/"))
CreateDirectory ("./externals");
// Download Dependencies
DownloadFile (GLIDE_URL, "./externals/glide.aar");
Unzip ("./externals/glide.aar", "./externals/glide/");
DownloadFile(GIFDECODER_URL, "./externals/gifdecoder.aar");
Unzip ("./externals/gifdecoder.aar", "./externals/gifdecoder/");
DownloadFile(DISKLRUCACHE_URL, "./externals/disklrucache.jar");
DownloadFile(RECYCLERVIEW_URL, "./externals/recyclerview-integration.aar");
Unzip ("./externals/recyclerview-integration.aar", "./externals/recyclerview-integration/");
// Update .csproj nuget versions
XmlPoke("./source/Xamarin.Android.Glide/Xamarin.Android.Glide.csproj", "/Project/PropertyGroup/PackageVersion", GLIDE_NUGET_VERSION);
Expand All @@ -45,27 +48,26 @@ Task("libs")
.IsDependentOn("externals")
.Does(() =>
{
MSBuild("./source/Xamarin.Android.Glide.sln", c => {
c.Configuration = "Release";
c.Restore = true;
c.MaxCpuCount = 0;
c.Properties.Add("DesignTimeBuild", new [] { "false" });
});
DotNetCoreRestore ("./source/Xamarin.Android.Glide.sln");
DotNetCoreMSBuild ("./source/Xamarin.Android.Glide.sln",
new DotNetCoreMSBuildSettings()
.SetConfiguration("Release")
);
});

Task("nuget")
.IsDependentOn("libs")
.Does(() =>
{
MSBuild ("./source/Xamarin.Android.Glide.sln", c => {
c.Configuration = "Release";
c.MaxCpuCount = 0;
c.Targets.Clear();
c.Targets.Add("Pack");
c.Properties.Add("PackageOutputPath", new [] { MakeAbsolute(new FilePath("./output")).FullPath });
c.Properties.Add("PackageRequireLicenseAcceptance", new [] { "true" });
c.Properties.Add("DesignTimeBuild", new [] { "false" });
});
DotNetCoreMSBuild ("./source/Xamarin.Android.Glide.sln",
new DotNetCoreMSBuildSettings()
.WithTarget("Pack")
.SetConfiguration("Release")
.WithProperty ("PackageOutputPath", MakeAbsolute(new FilePath("./output")).FullPath)
.WithProperty ("PackageRequireLicenseAcceptance", "true")
.WithProperty ("NoBuild", "true")
);
});

Task("samples")
Expand Down
28 changes: 28 additions & 0 deletions Android/Glide/source/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project>
<PropertyGroup>
<TargetFrameworks>MonoAndroid9.0;MonoAndroid10.0;net6.0-android</TargetFrameworks>
<IsBindingProject>true</IsBindingProject>
<Authors>Microsoft</Authors>
<Owners>Microsoft</Owners>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageProjectUrl>https://go.microsoft.com/fwlink/?linkid=864954</PackageProjectUrl>
<PackageLicenseUrl>https://go.microsoft.com/fwlink/?linkid=865026</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<!-- .NET 6+ generates Resource.designer.cs files for bindings projects which we do not want -->
<AndroidGenerateResourceDesigner>false</AndroidGenerateResourceDesigner>
<!-- .NET 6+ packages support back to API-21 -->
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<!-- see: https://github.com/xamarin/xamarin-android/blob/5f408ebb22df51b598c62f776ee0f82f92661b58/Documentation/guides/OneDotNetBindingProjects.md -->
<AndroidBoundInterfacesContainConstants>false</AndroidBoundInterfacesContainConstants>
<AndroidBoundInterfacesContainTypes>false</AndroidBoundInterfacesContainTypes>
<AndroidBoundInterfacesContainStaticAndDefaultInterfaceMethods>false</AndroidBoundInterfacesContainStaticAndDefaultInterfaceMethods>
</PropertyGroup>
<ItemGroup>
<GlideBuildFolders Include="build\monoandroid9.0" />
<GlideBuildFolders Include="build\monoandroid10.0" />
<GlideBuildFolders Include="build\net6.0-android31.0" />
<GlideBuildFolders Include="buildTransitive\monoandroid9.0" />
<GlideBuildFolders Include="buildTransitive\monoandroid10.0" />
<GlideBuildFolders Include="buildTransitive\net6.0-android31.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
[assembly: Android.LinkerSafe]
#if !NET
[assembly: Android.LinkerSafe]
#endif
[assembly: System.Reflection.AssemblyMetadata("IsTrimmable", "True")]
Original file line number Diff line number Diff line change
@@ -1,45 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="MSBuild.Sdk.Extras">
<Project Sdk="Xamarin.Legacy.Sdk">
<PropertyGroup>
<TargetFrameworks>MonoAndroid9.0;MonoAndroid10.0</TargetFrameworks>
<IsBindingProject>true</IsBindingProject>
<AssemblyName>Xamarin.Android.Glide.DiskLruCache</AssemblyName>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<AndroidUseIntermediateDesignerFile>True</AndroidUseIntermediateDesignerFile>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<RootNamespace>Bumptech.Glide.DiskLruCache</RootNamespace>
<AndroidClassParser>class-parse</AndroidClassParser>
<AndroidCodegenTarget>XAJavaInterop1</AndroidCodegenTarget>
</PropertyGroup>

<PropertyGroup>
<PackageId>Xamarin.Android.Glide.DiskLruCache</PackageId>
<Title>Glide Disk LRU Cache for Xamarin.Android</Title>
<PackageDescription>Xamarin.Android bindings for Glide Disk LRU Cache</PackageDescription>
<Authors>Microsoft</Authors>
<Owners>Microsoft</Owners>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageProjectUrl>https://go.microsoft.com/fwlink/?linkid=864954</PackageProjectUrl>
<PackageLicenseUrl>https://go.microsoft.com/fwlink/?linkid=865026</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageVersion>4.12.0.1</PackageVersion>
<PackageVersion>4.12.0.2</PackageVersion>
</PropertyGroup>

<ItemGroup>
<TransformFile Include="Transforms\*.xml" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\externals\disklrucache.jar">
<Link>disklrucache.jar</Link>
</None>
<None Include="..\..\externals\disklrucache.jar" Pack="True" PackagePath="jar" />
<None Include="$(PackageId).targets" Pack="True" PackagePath="@(GlideBuildFolders)" />
<None Include="..\..\External-Dependency-Info.txt" Pack="True" PackagePath="THIRD-PARTY-NOTICES.txt" />
</ItemGroup>

<ItemGroup>
<EmbeddedJar Include="..\..\externals\disklrucache.jar" />
<InputJar Include="..\..\externals\disklrucache.jar" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<ItemGroup>
<AndroidJavaLibrary Condition=" '$(AndroidApplication)' == 'true' " Include="$(MSBuildThisFileDirectory)..\..\jar\disklrucache.jar">
<AndroidXSkipAndroidXMigration>true</AndroidXSkipAndroidXMigration>
</AndroidJavaLibrary>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
[assembly: Android.LinkerSafe]
#if !NET
[assembly: Android.LinkerSafe]
#endif
[assembly: System.Reflection.AssemblyMetadata("IsTrimmable", "True")]
Original file line number Diff line number Diff line change
@@ -1,49 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="MSBuild.Sdk.Extras">
<Project Sdk="Xamarin.Legacy.Sdk">
<PropertyGroup>
<TargetFrameworks>MonoAndroid9.0;MonoAndroid10.0</TargetFrameworks>
<IsBindingProject>true</IsBindingProject>
<AssemblyName>Xamarin.Android.Glide.GifDecoder</AssemblyName>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<AndroidUseIntermediateDesignerFile>True</AndroidUseIntermediateDesignerFile>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<RootNamespace>Bumptech.Glide.GifDecoder</RootNamespace>
<AndroidClassParser>class-parse</AndroidClassParser>
<AndroidCodegenTarget>XAJavaInterop1</AndroidCodegenTarget>
</PropertyGroup>

<PropertyGroup>
<PackageId>Xamarin.Android.Glide.GifDecoder</PackageId>
<Title>Glide GIF Decoder for Xamarin.Android</Title>
<PackageDescription>Xamarin.Android bindings for Glide GIF Decoder</PackageDescription>
<Authors>Microsoft</Authors>
<Owners>Microsoft</Owners>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageProjectUrl>https://go.microsoft.com/fwlink/?linkid=864954</PackageProjectUrl>
<PackageLicenseUrl>https://go.microsoft.com/fwlink/?linkid=865026</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageVersion>4.12.0.1</PackageVersion>
<PackageVersion>4.12.0.2</PackageVersion>
</PropertyGroup>

<ItemGroup>
<TransformFile Include="Transforms\*.xml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.Annotation" Version="1.2.0.1" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\externals\gifdecoder.aar">
<Link>gifdecoder.aar</Link>
</None>
<None Include="..\..\externals\gifdecoder.aar" Pack="True" PackagePath="aar" />
<None Include="$(PackageId).targets" Pack="True" PackagePath="@(GlideBuildFolders)" />
<None Include="..\..\External-Dependency-Info.txt" Pack="True" PackagePath="THIRD-PARTY-NOTICES.txt" />
</ItemGroup>

<ItemGroup>
<LibraryProjectZip Include="..\..\externals\gifdecoder.aar" />
<InputJar Include="..\..\externals\gifdecoder\classes.jar" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<ItemGroup>
<AndroidAarLibrary Include="$(MSBuildThisFileDirectory)..\..\aar\gifdecoder.aar">
<AndroidXSkipAndroidXMigration>true</AndroidXSkipAndroidXMigration>
</AndroidAarLibrary>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#if !NET
[assembly: Android.LinkerSafe]
#endif
[assembly: System.Reflection.AssemblyMetadata("IsTrimmable", "True")]
Original file line number Diff line number Diff line change
@@ -1,45 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="MSBuild.Sdk.Extras">
<Project Sdk="Xamarin.Legacy.Sdk">
<PropertyGroup>
<TargetFrameworks>MonoAndroid9.0;MonoAndroid10.0</TargetFrameworks>
<IsBindingProject>true</IsBindingProject>
<AssemblyName>Xamarin.Android.Glide.RecyclerViewIntegration</AssemblyName>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<AndroidUseIntermediateDesignerFile>True</AndroidUseIntermediateDesignerFile>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<RootNamespace>Bumptech.Glide.Integration.RecyclerView</RootNamespace>
<AndroidClassParser>class-parse</AndroidClassParser>
<AndroidCodegenTarget>XAJavaInterop1</AndroidCodegenTarget>
</PropertyGroup>

<PropertyGroup>
<PackageId>Xamarin.Android.Glide.RecyclerViewIntegration</PackageId>
<Title>Glide RecyclerView integration for Xamarin.Android</Title>
<PackageDescription>Xamarin.Android bindings for Glide RecyclerView integration</PackageDescription>
<Authors>Microsoft</Authors>
<Owners>Microsoft</Owners>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageProjectUrl>https://go.microsoft.com/fwlink/?linkid=864954</PackageProjectUrl>
<PackageLicenseUrl>https://go.microsoft.com/fwlink/?linkid=865026</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageVersion>4.12.0.1</PackageVersion>
<PackageVersion>4.12.0.2</PackageVersion>
</PropertyGroup>

<ItemGroup>
<TransformFile Include="Transforms\*.xml" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\externals\recyclerview-integration.aar">
<Link>recyclerview-integration.aar</Link>
</None>
<None Include="..\..\externals\recyclerview-integration.aar" Pack="True" PackagePath="aar" />
<None Include="$(PackageId).targets" Pack="True" PackagePath="@(GlideBuildFolders)" />
<None Include="..\..\External-Dependency-Info.txt" Pack="True" PackagePath="THIRD-PARTY-NOTICES.txt" />
</ItemGroup>

<ItemGroup>
<LibraryProjectZip Include="..\..\externals\recyclerview-integration.aar" />
<InputJar Include="..\..\externals\recyclerview-integration\classes.jar" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<ItemGroup>
<AndroidAarLibrary Include="$(MSBuildThisFileDirectory)..\..\aar\recyclerview-integration.aar">
<AndroidXSkipAndroidXMigration>true</AndroidXSkipAndroidXMigration>
</AndroidAarLibrary>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
[assembly: Android.LinkerSafe]
#if !NET
[assembly: Android.LinkerSafe]
#endif
[assembly: System.Reflection.AssemblyMetadata("IsTrimmable", "True")]
Original file line number Diff line number Diff line change
@@ -1,45 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="MSBuild.Sdk.Extras">
<Project Sdk="Xamarin.Legacy.Sdk">
<PropertyGroup>
<TargetFrameworks>MonoAndroid9.0;MonoAndroid10.0</TargetFrameworks>
<IsBindingProject>true</IsBindingProject>
<AssemblyName>Xamarin.Android.Glide</AssemblyName>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<AndroidUseIntermediateDesignerFile>True</AndroidUseIntermediateDesignerFile>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<RootNamespace>Bumptech.Glide</RootNamespace>
<AndroidClassParser>class-parse</AndroidClassParser>
<AndroidCodegenTarget>XAJavaInterop1</AndroidCodegenTarget>
</PropertyGroup>

<PropertyGroup>
<PackageId>Xamarin.Android.Glide</PackageId>
<Title>Glide for Xamarin.Android</Title>
<PackageDescription>Xamarin.Android bindings for Glide</PackageDescription>
<Authors>Microsoft</Authors>
<Owners>Microsoft</Owners>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageProjectUrl>https://go.microsoft.com/fwlink/?linkid=864954</PackageProjectUrl>
<PackageLicenseUrl>https://go.microsoft.com/fwlink/?linkid=865026</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageVersion>4.12.0.1</PackageVersion>
<PackageVersion>4.12.0.2</PackageVersion>
</PropertyGroup>

<ItemGroup>
<TransformFile Include="Transforms\*.xml" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\externals\glide.aar">
<Link>glide.aar</Link>
</None>
<None Include="..\..\externals\glide.aar" Pack="True" PackagePath="aar" />
<None Include="$(PackageId).targets" Pack="True" PackagePath="@(GlideBuildFolders)" />
<None Include="..\..\External-Dependency-Info.txt" Pack="True" PackagePath="THIRD-PARTY-NOTICES.txt" />
</ItemGroup>

<ItemGroup>
<LibraryProjectZip Include="..\..\externals\glide.aar" />
<InputJar Include="..\..\externals\glide\classes.jar" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<ItemGroup>
<AndroidAarLibrary Include="$(MSBuildThisFileDirectory)..\..\aar\glide.aar">
<AndroidXSkipAndroidXMigration>true</AndroidXSkipAndroidXMigration>
</AndroidAarLibrary>
</ItemGroup>
</Project>

0 comments on commit a245afa

Please sign in to comment.