Xamarin.Google.Android.Play.App.Update : 2.1.0.9
Opened this issue · 0 comments
This issue has been moved from a ticket on Developer Community.
[severity:It bothers me. A fix would be nice]
DotNet-8.0-Android : In-App Update Build Failing
Using Nuget package Xamarin.Google.Android.Play.Core.AppUpdate (Version: 2.1.0.9)
Build Is Failing with this error:
1. Home_AppUpdateInstallUpdateListner is not abstract and does not override abstract method onStateUpdate(InstallState) in StateUpdatedListener
public class Home_AppUpdateInstallUpdateListner
2. name clash: onStateUpdate(Object) in Home_AppUpdateInstallUpdateListner and onStateUpdate(InstallState) in StateUpdatedListener have the same erasure, yet neither overrides the other public void onStateUpdate (java.lang.Object p0)
Code I'm Using : FileName : Home.cs
using Xamarin.Google.Android.Play.Core.AppUpdate;
using Xamarin.Google.Android.Play.Core.AppUpdate.Install;
using Xamarin.Google.Android.Play.Core.AppUpdate.Install.Model;
public IAppUpdateManager? AppUpdateManager;
private AppUpdateInstallUpdateListner? MyInstallUpdateListner;
public const int AppUpdateTypeSupported = AppUpdateType.Flexible;
protected override void OnCreate(Bundle? savedInstanceState)
{
base. OnCreate(savedInstanceState);
HomeLayout = BindingHome.Inflate(LayoutInflater);
SetContentView(HomeLayout.Root);
try
{
OneSignal.Notifications.RequestPermissionAsync(true);
App.SetUserId();
AppUpdateManager = AppUpdateManagerFactory.Create(this);
MyInstallUpdateListner = new AppUpdateInstallUpdateListner(AppUpdateManager);
AppUpdateManager.RegisterListener(MyInstallUpdateListner);
var AppUpdateInfoTask = AppUpdateManager.GetAppUpdateInfo();
AppUpdateInfoTask.AddOnSuccessListener(new InAppUpdateSuccessListener(AppUpdateManager, this));
}
catch (Exception Ex) { App.ReportError(Ex); }
}
public class InAppUpdateSuccessListener(IAppUpdateManager? AppUpdateManager, Activity? Home) : Java.Lang.Object, IOnSuccessListener
{
private readonly IAppUpdateManager? AppUpdateManager = AppUpdateManager;
private readonly Activity? Home = Home;
public void OnSuccess(Java.Lang.Object result)
{
if (result is not AppUpdateInfo EInfo)
{
return;
}
if (EInfo.InstallStatus() == InstallStatus.Downloaded)
{
AppUpdateManager?. CompleteUpdate();
return;
}
int IAvailability = EInfo.UpdateAvailability();
if ((IAvailability.Equals(UpdateAvailability.UpdateAvailable) ||
IAvailability.Equals(UpdateAvailability.DeveloperTriggeredUpdateInProgress)) &&
EInfo.IsUpdateTypeAllowed(AppUpdateType.Immediate))
{
AppUpdateOptions? Options = AppUpdateOptions.NewBuilder(AppUpdateTypeSupported). Build();
AppUpdateManager?. StartUpdateFlow(EInfo, Home, Options);
}
}
}
public class AppUpdateInstallUpdateListner(IAppUpdateManager? AppUpdateManager) : Java.Lang.Object, IInstallStateUpdatedListener
{
public IAppUpdateManager? AppUpdateManager = AppUpdateManager;
public void OnStateUpdate(Java.Lang.Object p0)
{
if (p0 is not InstallState state)
{
return;
}
if (state. InstallStatus() == InstallStatus.Downloaded)
{
AppUpdateManager?. CompleteUpdate();
}
}
}
Original Comments
Feedback Bot on 14/08/2024, 03:38 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Dean Ellis [MSFT] on 10/10/2024, 11:24 AM:
Hi
There is a problem with Binding generics in C#. Unfortunately the API you want to use has generics.
To work around this you can take a look at something we did for Asset Delivery https://github.com/xamarin/GooglePlayServicesComponents/blob/main/source/com.google.android.play/asset.delivery.extensions/extensions-aar/src/main/java/xamarin/google/android/play/core/assetpacks/AssetPackStateUpdateListenerWrapper.java.
The idea is you write a Wrapper class which exposes a non generic API to C#. You can then add this java file to your project with a AndroidJavaSource
build action. It will bind it just before the build and your new API should show up.
The source code I have linked to should give you an idea of what to do.
Dean Ellis [MSFT] on 10/10/2024, 07:03 PM:
I put together a sample for you
package xamarin.google.android.play.core.install;
import com.google.android.play.core.install.InstallStateUpdatedListener;
import com.google.android.play.core.install.InstallState;public class InstallStateUpdatedListenerWrapper {
private InstallStateUpdatedListener installStateUpdatedListener = state -> {
onStateUpdate (state);
};<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">onStateUpdate</span><span class="hljs-params">(InstallState state)</span> </span>{ <span class="hljs-keyword">if</span> (stateUpdateListener != <span class="hljs-keyword">null</span>) stateUpdateListener.OnStateUpdate(state); } <span class="hljs-function"><span class="hljs-keyword">public</span> InstallStateUpdatedListener <span class="hljs-title">GetListener</span><span class="hljs-params">()</span> </span>{ <span class="hljs-keyword">return</span> installStateUpdatedListener; } <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">InstallStateListener</span> </span>{ <span class="hljs-comment">/** * Called when an the State is Updated * * <span class="hljs-doctag">@param</span> state The Install Session State. */</span> <span class="hljs-function"><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">void</span> <span class="hljs-title">OnStateUpdate</span> <span class="hljs-params">(InstallState state)</span></span>; } <span class="hljs-keyword">private</span> InstallStateListener stateUpdateListener = <span class="hljs-keyword">null</span>; <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setStateUpdateListener</span> <span class="hljs-params">(InstallStateListener listener)</span> </span>{ stateUpdateListener = listener; }
}
and the C# side will be
var installListener = new InstallStateUpdatedListenerWrapper();
installListener.StateUpdate += (sender, args) => {
// do stuff.
};
I did however have to add this to my csproj
<Target Name="_Foo" AfterTargets="ResolveAndroidTooling" BeforeTargets="_CompileBindingJava">
<ItemGroup>
<_ReferenceJavaLibs Include="$(AndroidSdkBuildToolsPath)core-lambda-stubs.jar" />
</ItemGroup>