maui: Switching from .net7.0-android to .net8.0-android causes 'missing java symbols errors' in runtime inside a .net8.0-android MAUI app
Description
In runtime I get ‘missing java symbols’ errors in regard to ‘nordicsemi-android-mcumgr-ble-1.9.2.jar’ when attempting to make csharp-to-java calls (using standard android-binding techniques) from within a .net8.0-android MAUI app. The call is really simple:
new DeviceResetter().Reset(); // this calls the underlying .aar lib
Note that this exception only occurs when I target net8.0-android to generate the nuget (while the same nuget works just fine when it gets compiled against net7.0-android instead of net8.0-android)
The error is raised from a csharp-to-java call (shown above) over to the .aar library employed in the .csproj below.
Steps to Reproduce
Here’s the csproj of the project generating the nuget in question:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsOSX Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true' ">true</IsOSX>
<IsLinux Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true' ">true</IsLinux>
<IsWindows Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true' ">true</IsWindows>
<IsUnix Condition=" '$(IsOSX)' == 'true' OR '$(IsLinux)' == 'true' ">true</IsUnix>
<TargetFramework>net8.0-android</TargetFramework>
<DebugType>pdbonly</DebugType>
<DefineConstants>$(DefineConstants);TRACE</DefineConstants>
<IsBindingProject>true</IsBindingProject>
<NoWarn>$(NoWarn);CS0108;CS0114;BG8700;BG8605;BG8606;NETSDK1202;</NoWarn>
</PropertyGroup>
<PropertyGroup>
<AndroidLinkMode>Full</AndroidLinkMode>
<AndroidSupportedAbis>armeabi-v7a;arm64-v8a</AndroidSupportedAbis>
</PropertyGroup>
<PropertyGroup>
<AndroidLibsFolder>Libraries</AndroidLibsFolder>
<AndroidLibsDependenciesFolder>$(AndroidLibsFolder)/Dependencies</AndroidLibsDependenciesFolder>
<CoreAarLibrary>$(AndroidLibsFolder)/mcumgr-wrapper.aar</CoreAarLibrary>
</PropertyGroup>
<ItemGroup>
<Folder Include="Libraries\"/>
<Folder Include="Libraries\Dependencies\" />
<Folder Include="Transforms\"/>
</ItemGroup>
<Target Name="PrintBuildInfo" BeforeTargets="PrepareForBuild">
<Message Importance="High" Text="OS: '$(OS)' "/>
<Message Importance="High" Text="Platform: '$(Platform)' "/>
<Message Importance="High" Text="PackageId: '$(PackageId)' "/>
<Message Importance="High" Text="Configuration: '$(Configuration)' "/>
<Message Importance="High" Text="PackageVersion: '$(PackageVersion)' "/>
<Message Importance="High" Text="TargetFramework: '$(TargetFramework)' "/>
<Message Importance="High" Text="DefineConstants: '$(DefineConstants)' "/>
<Message Importance="high" Text="DesignTimeBuild: '$(DesignTimeBuild)' "/>
<Message Importance="high" Text="BuildingProject: '$(BuildingProject)' "/>
<Message Importance="high" Text="MSBuildNodeCount: '$(MSBuildNodeCount)' "/>
<Message Importance="high" Text="ShouldBuildNativeLibraries: '$(ShouldBuildNativeLibraries)' "/>
</Target>
<Import Project="Foobar.Bindings.Android.NetX.targets"/>
<ItemGroup>
<!-- these dependencies have been field-tested and are known to work at least as far back as Android 10.0 -->
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.12.0.4" PrivateAssets="All" />
<!-- the mcumgr-file-uploading aspect KotlinX.Coroutines jars with version 1.7+ -->
<!-- to work as intended otherwise we get missing symbols errors in runtime -->
<PackageReference Include="Xamarin.KotlinX.Coroutines.Android" Version="1.8.0.1" />
</ItemGroup>
</Project>
The file ‘Foobar.Bindings.Android.NetX.targets’ looks like so:
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<LangVersion>10.0</LangVersion>
<!-- net8 supports android13 and it corresponds to android-api level 34.0 -->
<TargetPlatformVersion Condition=" '$(TargetFramework.ToLower().StartsWith(net8.0))' == 'true' ">34.0</TargetPlatformVersion>
<SupportedOSPlatformVersion Condition=" '$(TargetFramework.ToLower().StartsWith(net8.0))' == 'true' ">34</SupportedOSPlatformVersion>
</PropertyGroup>
<ItemGroup>
<!-- the default mechanism automagically scans aars and jars and ... messes things up when multiple aar and jars are involved resulting in cryptic crashes -->
<!-- during the build process so we reset everything back to a blank slate and then proceed to manually set up everything from scratch like we always do -->
<ReferenceJar Remove="**"/>
<TransformFile Remove="**"/>
<AndroidLibrary Remove="**"/>
<AndroidAarLibrary Remove="**"/>
<TransformFile Include="Transforms/*.xml"/>
<AndroidLibrary Include="$(CoreAarLibrary)" Bind="true" Condition=" 'Exists($(CoreAarLibrary))' == 'true' " />
<AndroidLibrary Include="$(AndroidLibsFolder)/Dependencies/slf4j-api.jar" Bind="false" />
<AndroidLibrary Include="$(AndroidLibsFolder)/Dependencies/jackson-core.jar" Bind="false" />
<AndroidLibrary Include="$(AndroidLibsFolder)/Dependencies/jackson-databind.jar" Bind="false" />
<AndroidLibrary Include="$(AndroidLibsFolder)/Dependencies/jackson-annotations.jar" Bind="false" />
<AndroidLibrary Include="$(AndroidLibsFolder)/Dependencies/jackson-dataformat-cbor.jar" Bind="false" />
<AndroidLibrary Include="$(AndroidLibsFolder)/Dependencies/nordicsemi-android-ble-2.7.3.jar" Bind="false" />
<AndroidLibrary Include="$(AndroidLibsFolder)/Dependencies/nordicsemi-android-mcumgr-ble-1.9.2.jar" Bind="false" />
<AndroidLibrary Include="$(AndroidLibsFolder)/Dependencies/nordicsemi-android-mcumgr-core-1.9.2.jar" Bind="false" />
</ItemGroup>
<Target Name="PrintBindingConfiguration" AfterTargets="CoreCompile">
<Message Importance="High" Text="**** Transform files to use for NetX-Android (@(TransformFile->Count()) in total): " />
<Message Importance="high" Text="**** " />
<Message Importance="high" Text="**** '%(TransformFile.Identity)' " />
<Message Importance="high" Text="**** " />
<Message Importance="High" Text="**** Android libraries to embed for NetX-Android (@(AndroidLibrary->Count()) in total): " />
<Message Importance="high" Text="**** " />
<Message Importance="high" Text="**** '%(AndroidLibrary.Identity)' " />
<Message Importance="high" Text="**** " />
<Error Text="No transform files found on disk! This looks fishy ... erroring out ..."
Condition=" @(TransformFile->Count()) == 0 "/>
<ItemGroup>
<MissingTransformFiles Include="@(TransformFile)" Condition=" ! Exists(%(FullPath)) " />
<MissingAndroidLibraries Include="@(AndroidLibrary)" Condition=" ! Exists(%(FullPath)) " />
</ItemGroup>
<Error Text="@(MissingTransformFiles->Count()) file(s) specified by the property 'TransformFile' were not found on disk: $(MissingTransformFiles)"
Condition=" @(MissingTransformFiles->Count()) != 0 "/>
<Error Text="@(MissingAndroidLibraries->Count()) file(s) specified by the property 'AndroidLibrary' were not found on disk: $(MissingAndroidLibraries)"
Condition=" @(MissingAndroidLibraries->Count()) != 0 "/>
</Target>
</Project>
Link to public reproduction project repository
No response
Version with bug
8.0.3 GA
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.3 GA
Affected platforms
Android
Affected platform versions
Android 10+
Did you find any workaround?
I just reverted to using .net7.0-android for the nuget-project. Works fine when the nuget is used from a .net8.0-android maui-app.
Relevant log output
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (11 by maintainers)
I can’t phathom how this can be the case considering that under net7.0 everything works flawlessly. But if I switch it to net8.0 then suddenly the libs are missing. If you download the zip files I attached for .net7.0 and .net8.0 you will clearly see that the .net8.0 ones are corrupted - the .aar contained within the .net8.0 nuget package is empty.
I can’t see what I’m doing wrong considering that things are working under net7.0 but not under net.8.0. The only thing I change is the target framework.
Here’s how we include Android libraries on both net7.0 and net8.0:
Here’s a comparison between the contents of the resulting nugets:
As you can clearly see the build system automatically populates the .net7 aar properly inside the generated nuget:
But the .net8.0 build system fails to behave in the same way even though every single bit and piece of configuration has remained the same in the .csproj and .targets file that I employ:
I have verified that the .aar/.jar files do exist on the disk at the proper time during build and they’re all indeed there:
The .net8.0 behaviour is very, very strange.