xamarin / GooglePlayServicesComponents

Other
315 stars 146 forks source link

com.google.android.play.billingclient.version failing to compile with latest updates #890

Closed FANMixco closed 4 months ago

FANMixco commented 4 months ago

Xamarin.Android Version (eg: 6.0):

.NET 8

Operating System & Version (eg: Mac OSX 10.11):

Windows 11

Google Play Services Version

Describe your Issue

> Severity  Code    Description Project File    Line    Suppression State Error
> (active)  AMM0000 C:\Users\MyUser\Documents\GitHub\MyApp\obj\Debug\net8.0-android\lp\154\jl\AndroidManifest.xml
> Warning:  Namespace 'com.android.billingclient' used in:
> AndroidManifest.xml, AndroidManifest.xml.
> C:\Users\feder\Documents\GitHub\ToastmastersTimerAndroid\tk.supernova.timerNet\obj\Debug\net8.0-android\lp\163\jl\AndroidManifest.xml
> Warning:  Namespace 'com.google.android.gms.base' used in:
> AndroidManifest.xml, AndroidManifest.xml.
> C:\Users\MyUser\Documents\GitHub\MyApp\obj\Debug\net8.0-android\lp\156\jl\AndroidManifest.xml
> Warning:  Namespace 'com.google.firebase.encoders.json' used in:
> AndroidManifest.xml, AndroidManifest.xml.
> C:\Users\MyUser\Documents\GitHub\MyApp\obj\Debug\net8.0-android\lp\164\jl\AndroidManifest.xml
> Warning:  Namespace 'com.google.android.gms.common' used in:
> AndroidManifest.xml, AndroidManifest.xml.
> C:\Users\MyUser\Documents\GitHub\MyApp\obj\Debug\net8.0-android\lp\165\jl\AndroidManifest.xml
> Warning:  Namespace 'com.google.android.gms.location' used in:
> AndroidManifest.xml, AndroidManifest.xml.
> C:\Users\MyUser\Documents\GitHub\MyApp\obj\Debug\net8.0-android\lp\166\jl\AndroidManifest.xml
> Warning:  Namespace 'com.google.android.gms.tasks' used in:
> AndroidManifest.xml, AndroidManifest.xml.
>   Attribute
> meta-data#com.google.android.play.billingclient.version@value
> value=(6.0.1) from AndroidManifest.xml:32:77-98   is also present at
> AndroidManifest.xml:21:13-34 value=(6.1.0).   Suggestion: add
> 'tools:replace="android:value"' to <meta-data> element at
> AndroidManifest.xml:32:5-101 to override. Directory
> 'obj\Debug\net8.0-android\lp\154' is from 'billing.aar'. Directory
> 'obj\Debug\net8.0-android\lp\163' is from 'play-services-base.aar'.
> Directory 'obj\Debug\net8.0-android\lp\156' is from
> 'firebase-encoders-json.aar'. Directory
> 'obj\Debug\net8.0-android\lp\164' is from
> 'play-services-basement.aar'. Directory
> 'obj\Debug\net8.0-android\lp\165' is from
> 'play-services-location.aar'. Directory
> 'obj\Debug\net8.0-android\lp\166' is from
> 'play-services-tasks.aar'.    tk.supernova.timerNet   C:\Users\MyUser\Documents\GitHub\MyApp\obj\Debug\net8.0-android\AndroidManifest.xml 32

Relevant information

Add relevant project settings from *.csproj file:

Packages used:

  <ItemGroup>
    <PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.70" />
    <PackageReference Include="PicoXLSX" Version="3.2.1" />
    <PackageReference Include="Plugin.CurrentActivity" Version="2.1.0.4" />
    <PackageReference Include="Plugin.InAppBilling" Version="7.1.2" />
    <PackageReference Include="System.Text.Json" Version="8.0.4" />
    <PackageReference Include="Xamarin-FiveStarsRate" Version="4.1.0" />
    <PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.7.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Core" Version="1.13.1.3" />
    <PackageReference Include="Xamarin.AndroidX.DrawerLayout" Version="1.2.0.11" />
    <PackageReference Include="Xamarin.AndroidX.Preference" Version="1.2.1.8" />
  </ItemGroup>

Build settings (tools)

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <EnableLLVM>True</EnableLLVM>
    <JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
    <AndroidLinkTool>r8</AndroidLinkTool>
  </PropertyGroup>

or even better - links to the existing code:

NOTE: Please DO NOT submit screenshot images. Images are not searchable!

Minimal Repro Code Sample

If you want to speed up investigation and bug fixing: please provide minimal repro sample for tests.

Steps to Reproduce (with link to sample solution if possible):

Include any relevant Exception Stack traces, build logs, adb logs:

FANMixco commented 4 months ago

It works perfectly with the old libs:

  <ItemGroup>
    <PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.60" />
    <PackageReference Include="PicoXLSX" Version="3.2.1" />
    <PackageReference Include="Plugin.CurrentActivity" Version="2.1.0.4" />
    <PackageReference Include="Plugin.InAppBilling" Version="7.1.0" />
    <PackageReference Include="System.Text.Json" Version="8.0.3" />
    <PackageReference Include="Xamarin-FiveStarsRate" Version="4.1.0" />
    <PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.6.1.10" />
    <PackageReference Include="Xamarin.AndroidX.Core" Version="1.13.1.2" />
    <PackageReference Include="Xamarin.AndroidX.DrawerLayout" Version="1.2.0.10" />
    <PackageReference Include="Xamarin.AndroidX.Preference" Version="1.2.1.7" />
  </ItemGroup>
appdevcanada commented 4 months ago

Hi guys,

I got the same issue today after updating some packages, specifically InAppBilling, from 7.1.0 to 7.1.2. I could solve the issue by uninstalling it and installing back 7.1.0 for now...

jpobst commented 4 months ago

The full output is:

C:\code\temp\MauiApp4\obj\Debug\net8.0-android\AndroidManifest.xml(12,196): error AMM0000: C:\code\temp\MauiApp4\obj\Debug\net8.0-android\lp\185\jl\AndroidManifest.xml Warning:
    Namespace 'com.android.billingclient' used in: AndroidManifest.xml, AndroidManifest.xml.
C:\code\temp\MauiApp4\obj\Debug\net8.0-android\lp\194\jl\AndroidManifest.xml Warning:
    Namespace 'com.google.android.gms.base' used in: AndroidManifest.xml, AndroidManifest.xml.
C:\code\temp\MauiApp4\obj\Debug\net8.0-android\lp\187\jl\AndroidManifest.xml Warning:
    Namespace 'com.google.firebase.encoders.json' used in: AndroidManifest.xml, AndroidManifest.xml.
C:\code\temp\MauiApp4\obj\Debug\net8.0-android\lp\195\jl\AndroidManifest.xml Warning:
    Namespace 'com.google.android.gms.common' used in: AndroidManifest.xml, AndroidManifest.xml.
C:\code\temp\MauiApp4\obj\Debug\net8.0-android\lp\196\jl\AndroidManifest.xml Warning:
    Namespace 'com.google.android.gms.location' used in: AndroidManifest.xml, AndroidManifest.xml.
C:\code\temp\MauiApp4\obj\Debug\net8.0-android\lp\197\jl\AndroidManifest.xml Warning:
    Namespace 'com.google.android.gms.tasks' used in: AndroidManifest.xml, AndroidManifest.xml.

C:\code\temp\MauiApp4\obj\Debug\net8.0-android\AndroidManifest.xml:12:196-220 Error:
    Attribute application@label value=(MauiApp4) from AndroidManifest.xml:12:196-220
    is also present at AndroidManifest.xml:13:9-41 value=(@string/app_name).
    Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:12:3-31:17 to override.
Directory 'obj\Debug\net8.0-android\lp\185' is from 'billing.aar'.
Directory 'obj\Debug\net8.0-android\lp\194' is from 'play-services-base.aar'.
Directory 'obj\Debug\net8.0-android\lp\187' is from 'firebase-encoders-json.aar'.
Directory 'obj\Debug\net8.0-android\lp\195' is from 'play-services-basement.aar'.
Directory 'obj\Debug\net8.0-android\lp\196' is from 'play-services-location.aar'.
Directory 'obj\Debug\net8.0-android\lp\197' is from 'play-services-tasks.aar'.

Specifically:

C:\code\temp\MauiApp4\obj\Debug\net8.0-android\AndroidManifest.xml:12:196-220 Error:
    Attribute application@label value=(MauiApp4) from AndroidManifest.xml:12:196-220
    is also present at AndroidManifest.xml:13:9-41 value=(@string/app_name).
    Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:12:3-31:17 to override.

Looking for label= in the /lp directory only yields a single result:

<!-- net8.0-android\lp\0\jl\AndroidManifest.xml -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="angtrim.com.fivestarslibrary"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="29" />

    <application
        android:allowBackup="true"
        android:label="@string/app_name" >
    </application>

</manifest>

This is from https://www.nuget.org/packages/Xamarin-FiveStarsRate.

I don't see how changing https://www.nuget.org/packages/Plugin.InAppBilling would cause this to start erroring.

@dellis1972 This appears to be an Android Manifest Merger issue. Can you assist here?

jpobst commented 4 months ago

Actually, this seems unrelated to BillingClient.

Adding just:

<PackageReference Include="Xamarin-FiveStarsRate" Version="4.1.0" />

to the MAUI template causes the error:

C:\code\temp\MauiApp4\obj\Debug\net8.0-android\AndroidManifest.xml(12,196): error AMM0000: 
    Attribute application@label value=(MauiApp4) from AndroidManifest.xml:12:196-220
    is also present at AndroidManifest.xml:13:9-41 value=(@string/app_name).
    Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:12:3-29:17 to override.
jpobst commented 4 months ago

If you only add:

<PackageReference Include="Plugin.InAppBilling" Version="7.1.2" />

to the MAUI template, you get a different error:

C:\code\temp\MauiApp4\obj\Debug\net8.0-android\AndroidManifest.xml:13:77-98 Error:
    Attribute meta-data#com.google.android.play.billingclient.version@value value=(6.0.1) from AndroidManifest.xml:13:77-98
    is also present at AndroidManifest.xml:21:13-34 value=(6.1.0).
    Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:13:5-101 to override.

This is caused because com.android.billingclient:billing has updated its version number in the AndroidManifest.xml it ships:

<!-- billing-6.0.1 -->
<meta-data
            android:name="com.google.android.play.billingclient.version"
            android:value="6.0.1" />

<!-- billing-6.1.0 -->
<meta-data
            android:name="com.google.android.play.billingclient.version"
            android:value="6.1.0" />

However, Plugin.InAppBilling has hardcoded this version as 6.0.1:

https://github.com/jamesmontemagno/InAppBillingPlugin/blob/ccdd3c9cd098e632f012e43b96c0a74ce6a4fe4f/src/Plugin.InAppBilling/AssemblyIncludes.android.cs#L1

I think Plugin.InAppBilling will need to do one of the following:

It looks like they already have an issue for this: https://github.com/jamesmontemagno/InAppBillingPlugin/issues/615.

dellis1972 commented 4 months ago

The work around is right in the error message.

'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:13:5-101 to override

See https://github.com/dotnet/android/blob/main/Documentation/docs-mobile/building-apps/build-items.md#androidmanifestoverlay and https://developer.android.com/build/manage-manifests

jpobst commented 4 months ago

The work around is right in the error message.

Having learned a little bit more about manifests while investigating today, I think it works by default in an .NET for Android application because the attribute values match:

<!-- .NET for Android template value -->
<application android:label="@string/app_name" ... />

<!-- NuGet library value -->
<application
        android:allowBackup="true"
        android:label="@string/app_name" >

However the MAUI template uses a different android:label, triggering the error:

<!-- MAUI template value -->
<application android:label="MauiApp4" ... />

Arguably, a NuGet library should not be shipping an AndroidManifest.xml that is trying to dictate the name of the entire application. 😉

jamesmontemagno commented 4 months ago

It is an issue with: https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/src/Plugin.InAppBilling/AssemblyIncludes.android.cs

jamesmontemagno commented 4 months ago

i will remove this and folks should add manually