Upgrading to the latest Google AdMob SDK causes strange errors - xamarin

I tried to upgrade to the latest Google AdMob SDK in my Xamarin.Forms app. So far I got the banner ads working but the interstitial ads throwing a error I'm not sure what it wants me todo. For the new callback parameter I added the following class:
private class LocalInterstitialAdLoadCallback : InterstitialAdLoadCallback
{
public override void OnAdLoaded(Java.Lang.Object p0)
{
if (p0 is InterstitialAd interstitialAd)
{
MainThread.BeginInvokeOnMainThread(() =>
{
interstitialAd.Show(CrossCurrentActivity.Current.Activity);
});
}
}
public override void OnAdFailedToLoad(LoadAdError p0)
{
}
}
but this yields the error below and I have no idea how to fix this.
javac.exe error JAVAC0000: error: name clash: onAdLoaded(Object) in CoreService_LocalInterstitialAdLoadCallback and onAdLoaded(AdT) in AdLoadCallback have the same erasure, yet neither overrides the other
javac.exe error JAVAC0000: public void onAdLoaded (java.lang.Object p0)
javac.exe error JAVAC0000: where AdT is a type-variable:
javac.exe error JAVAC0000: AdT extends Object declared in class AdLoadCallback
What does this even mean? Is there any sample on how to implement this properly or does someone have a hint where I can look this up? I never worked with Java which is not really helpful at this point I guess.

Related

Error XAGJS7009: System.InvalidOperationException: There can be only one type with an [Application] attribute android Xamarin

After implementing Huawei push service in my android project, I was getting crash on the occurrence of Push Notification, and error was looged
java.lang.UnsatisfiedLinkError: No implementation found for void crc6415d7e49b4cd3bc6f.MyApplication.n_onCreate()
To resolve this error, I crated MyApplication to extend the Application.
[Application]
public class MyApplication : Application
{
public MyApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}
public override void OnCreate()
{
base.OnCreate();
}
}
then I am getting
Error XAGJS7009: System.InvalidOperationException: There can be only one type with an [Application] attribute; found:,
Note
I have tried adding these lines as well
#if DEBUG
[Application(Debuggable=true)]
#else
[Application(Debuggable=false)]
#endif
but still getting the same issue
Already tried Clean and Rebuild solution
You have to delete Application file first. Open The Library project then find XPush-5.0.2.300 -> HmsPush -> Application file then delete it.
Then add below code line to your Application's OnCreate() method if you want to use feature which is relevant to it.
RegisterActivityLifecycleCallbacks(new MyLifecycleHandler());
In addition this problem will be fixed in the next version.

Resolution failed exception in Xamarin IOS prism

I have an iOS application written in Xamarin and I am getting a Unity Exceptions Resolution Failed exception when I try and run the application in iOS. However this error does not happen when I run the android version of the application. The exception is being thrown while the initalize function from prism is taking place.
Here is a snippet from my app.xaml.cs
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
this.RegisterLocal(containerRegistry);
this.RegisterServices(containerRegistry);
this.RegisterPagesForNavigation(containerRegistry);
}
This code all executes and passes.
This is the iOS initialization
Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
PullToRefreshLayoutRenderer.Init();
LoadApplication(new App(new IosInitializer()));
return base.FinishedLaunching(app, options);
}
public class IosInitializer : IPlatformInitializer
{
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.Register<IUAirshipUpdate, UAirshipUpdate>();
}
}
This code also executes
The exception being thrown is an argument null exception indicating that IModuleCatelog is not present. I do not understand why it is looking for that module and can not find it. The source code on GitHub indicates that class was registered.
This issue was caused because linker behavior for IOS application was set to full and that causes issues with Unity IOC Container.

Getting Java.Lang.NullPointerException when trying to open GPS Settings page using Xamarin

I am getting the following error when trying to open GPS settings page if GPS is not enabled (within Xamarin):
Unknown identifier: StartActivity
Unhandled Exception:
Java.Lang.NullPointerException:
Can somebody please guide where am I getting wrong?
This My Interface
namespace MyApp
{
public interface GpsSettings
{
void showGpsSettings();
}
}
This the Implementation
[assembly: Xamarin.Forms.Dependency(typeof(GpsSettingsImplementation))]
namespace MyApp.Droid
{
public class GpsSettingsImplementation : Activity, GpsSettings
{
public GpsSettingsImplementation()
{
}
public void showGpsSettings()
{
var intent = new Intent(Android.Provider.Settings.ActionLocationSourceSettings);
StartActivity(intent);
}
}
}
This is how I call my function on button click
DependencyService.Get<GpsSettings>().showGpsSettings();
An existing Activity instance has a bit of work that goes on behind
the scenes when it's constructed; activities started through the
intent system (all activities) will have a Context reference added to
them when they are instantiated. This context reference is used in the
call-chain of StartActivity.
So, the Java.Lang.NullPointerException seen after invoking
StartActivity on your Test activity instance is because the Context
inside that instance has never been set. By using the new operator to
create an activity instance you've circumvented the normal way
activities are instantiated, leaving your instance in an invalid
state!
ref: https://stackoverflow.com/a/31330999/5145530
The above error can be resolved in the following manner:
[assembly: Xamarin.Forms.Dependency(typeof(GpsSettingsImplementation))]
namespace MyApp.Droid
{
public class GpsSettingsImplementation : Activity, GpsSettings
{
public GpsSettingsImplementation()
{
}
public void showGpsSettings()
{
var intent = new Intent(Android.Provider.Settings.ActionLocationSourceSettings);
intent.SetFlags(ActivityFlags.NewTask);
Android.App.Application.Context.StartActivity(intent);
}
}
}

Java.Lang.UnsatisfiedLinkError: Native method not found: onResume with Xamarin

This class definition causes an immediate runtime crash on Xamarin for Android.
public class BaseCompatActivity : Android.Support.V7.App.AppCompatActivity
{
protected override void OnResume()
{
base.OnResume();
}
}
The error message is:
Java.Lang.UnsatisfiedLinkError: Native method not found: md5e8727ee9d36911e204981187fd2b13a2.BaseCompatActivity.n_onResume:()V
I have an inheritance chain that goes like this
MainActivity > DrawerActivity > BaseCompatActivity > AppCompatActivity
If I override OnResume in MainActivity or DrawerActivity, there is no problem. It is only if I override it in BaseCompatActivity that I get that error message.
This happens when running API level 17 in the emulator. It does not happen when running on an API level 22 device.
What could be causing this mysterious behaviour?

Examples of how to use NServiceBus with NServiceBus.Ninject-CI in ASP.NET MVC 3 solution

I would like to experiment with NServiceBus using ASP.NET MVC 3. I've got a solution with NServiceBus installed, plus NinjectMVC3 and NServiceBus.Ninject-CI. Trouble is, I have no idea how to setup NServiceBus stuff in the NinjectMVC3.cs file in App_Start.
Rather annoyingly I'm having trouble finding any examples of how to use NServiceBus.Ninject-CI (I hate it when people don't bother giving examples of how to use their stuff).
Can someone help me get started please?
Load a module like this into the kernel to provide access to the bus
public class NServiceBusModule : NinjectModule
{
public override void Load()
{
this.Bind<IBus>().ToConstant(this.CreateBus()).InSingletonScope();
}
private IBus CreateBus()
{
return NServiceBus.Configure.WithWeb()
.NinjectBuilder(this.Kernel)
... // put NServiceBus config here
.CreateBus()
.Start();
}
}
Read the NServiceBus documentation about how to configure NServiveBus:
http://docs.particular.net/nservicebus/containers/ninject
http://docs.particular.net/samples/web/asp-mvc-application/
Hopefully this will help someone. I had a lot of trouble finding sample code for getting ninject working within NServiceBus.
This code below works for me in place of the more common Castle version:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
#region IWantCustomInitialization Members
public void Init()
{
Configure
.With()
.NinjectBuilder(CreateKernel())
.XmlSerializer()
.MsmqTransport();
SetLoggingLibrary.Log4Net(XmlConfigurator.Configure);
}
protected IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Load<MyCustomNinjectModule>();
return kernel;
}
#endregion
}
with the ninject module being the usual format, ie:
public class MyCustomNinjectModule : NinjectModule
{
public override void Load()
{
Bind(typeof(ILogger<>)).To(typeof(Log4NetLogger<>));
...
}
}

Resources