Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[One .NET] enable C# bindings for @(AndroidLibrary)
Fixes: dotnet/maui#1475

A .NET 6 application project was failing to include C# bindings for
`.aar` files, but `.jar` files were working.

The workaround was to include:

    <LibraryProjectZip Include="myjavalibrary.aar" />

We had a test that checked this behavior for `.jar` files, but not
`.aar` files.

After reproducing the behavior in a test, I found the
`_CategorizeAndroidLibraries` MSBuild target did not automatically
setup the `@(LibraryProjectZip)` item group in .NET 6 application
projects. `@(AndroidAarLibrary)` *was* being setup, which explained
why the Java code made it to `classes.dex`, but C# bindings were
missing.

Updated the `_CategorizeAndroidLibraries` MSBuild target for this case.
  • Loading branch information
jonathanpeppers committed Jun 29, 2021
commit fdb1a62c6d90231ba38f6fee109244d91d1df74a
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ This item group populates the Build Action drop-down in IDEs.
<ItemGroup Condition=" '$(AndroidApplication)' != 'true' ">
<EmbeddedNativeLibrary Include="@(AndroidNativeLibrary)" />
</ItemGroup>
<!-- Any .NET 6 project -->
<ItemGroup Condition=" '$(UsingAndroidNETSdk)' == 'true' ">
<LibraryProjectZip Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.aar' and '%(AndroidLibrary.Bind)' == 'true' " />
</ItemGroup>
<!-- .NET 6 class libraries-->
<ItemGroup Condition=" '$(AndroidApplication)' != 'true' and '$(UsingAndroidNETSdk)' == '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' " />
<!-- .aar files should be copied to $(OutputPath) in .NET 6-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease)
new BuildItem ("EmbeddedResource", "Foo.es.resx") {
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancelar</value></data>")
},
new AndroidItem.TransformFile ("Transforms.xml") {
// Remove two methods that introduced warnings:
// Com.Balysv.Material.Drawable.Menu.MaterialMenuView.cs(214,30): warning CS0114: 'MaterialMenuView.OnRestoreInstanceState(IParcelable)' hides inherited member 'View.OnRestoreInstanceState(IParcelable?)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
// Com.Balysv.Material.Drawable.Menu.MaterialMenuView.cs(244,56): warning CS0114: 'MaterialMenuView.OnSaveInstanceState()' hides inherited member 'View.OnSaveInstanceState()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
TextContent = () => "<metadata><remove-node path=\"/api/package[@name='com.balysv.material.drawable.menu']/class[@name='MaterialMenuView']/method[@name='onRestoreInstanceState']\" /><remove-node path=\"/api/package[@name='com.balysv.material.drawable.menu']/class[@name='MaterialMenuView']/method[@name='onSaveInstanceState']\" /></metadata>",
},
new AndroidItem.AndroidLibrary ("material-menu-1.1.0.aar") {
WebContent = "https://repo.jfrog.org/artifactory/libs-release-bintray/com/balysv/material-menu/1.1.0/material-menu-1.1.0.aar"
},
}
};
proj.MainActivity = proj.DefaultMainActivity.Replace (": Activity", ": AndroidX.AppCompat.App.AppCompatActivity");
Expand Down Expand Up @@ -425,8 +434,9 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease)
FileAssert.Exists (assemblyPath);
using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) {
var typeName = "Com.Xamarin.Android.Test.Msbuildtest.JavaSourceJarTest";
var type = assembly.MainModule.GetType (typeName);
Assert.IsNotNull (type, $"{assemblyPath} should contain {typeName}");
Assert.IsNotNull (assembly.MainModule.GetType (typeName), $"{assemblyPath} should contain {typeName}");
typeName = "Com.Balysv.Material.Drawable.Menu.MaterialMenuView";
Assert.IsNotNull (assembly.MainModule.GetType (typeName), $"{assemblyPath} should contain {typeName}");
}

var rids = runtimeIdentifiers.Split (';');
Expand Down