Skip to content

net client: the fat-bundling of google libs makes building a net10-android app very difficult #180

Description

@softlion

Adding the OpenIa.Maui nuget (version 1.1.1) to a net10-android app breaks the build process:

<PackageReference Include="OpenIap.Maui" Version="1.1.1" />

The build process results in duplication errors like:

javac.exe error JAVAC0000:  error: class string is already defined in class R 

That is because the openiap nuget package includes google android bindings that are aready available through other nuget packages like Xamarin.GooglePlayServices.* (which are maui nugets, the xamarin name is misleading).

And for example including the nuget Xamarin.GooglePlayServices.Games.V2 will result in a duplication of these embedded libs.

So instead of fat bundling the google libs, add the existing matching nugets.

Workaround

To be able to build the android app using the 1.1.1 version of OpenIap I had to add this target to the dotnet 10 project:

 <Target Name="RemoveOpenIapDuplicateAars" BeforeTargets="_ResolveLibraryProjectImports"
            Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
        <ItemGroup>
            <!-- Drop only OpenIap's bundled AARs that duplicate this app's existing bindings
                 (play-services base/basement/tasks via Xamarin.GooglePlayServices.*, transport-* via
                 Xamarin.Google.Android.DataTransport.*). play-services-location, billing*, and openiap*
                 are kept — nothing else provides them. StartsWith('play-services-base') covers basement too. -->
            <AndroidAarLibrary Remove="@(AndroidAarLibrary)"
                Condition="$([System.String]::Copy('%(Identity)').Contains('openiap.maui')) AND (
                    $([System.String]::Copy('%(Filename)').StartsWith('play-services-base')) OR
                    $([System.String]::Copy('%(Filename)').StartsWith('play-services-tasks')) OR
                    $([System.String]::Copy('%(Filename)').StartsWith('transport-')) )" />
            <!-- OpenIap.Maui.Bindings.Android.aar embeds its own gson, duplicating the GoogleGson binding
                 pulled in transitively (R8: "com.google.gson.* defined multiple times"). Drop the standalone
                 GoogleGson AAR so only one gson is dexed; the embedded copy serves the Java consumers.
                 No C# code here uses Com.Google.Gson (we use System.Text.Json), so this is safe — but
                 confirm gson-dependent paths at runtime on device (sub-task 7). -->
            <AndroidAarLibrary Remove="@(AndroidAarLibrary)"
                Condition="$([System.String]::Copy('%(Identity)').ToLower().Contains('googlegson'))" />
        </ItemGroup>
    </Target>

But I'm still not sure the android app will run.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions