I've added Xamarin.Firebase.Ads to my Xamarin.Forms Android project and set it up with the test IDs - Test Banner is showing correctly on emulator. My private IDs are still not approved etc. When I deploy the app to any Android device, app crashes at the start up. App will crash even when I remove all code and leave only the Xamarin.Firebase.Ads in the References. Same goes for Xamarin.Firebase.Ads.Lite - all virtual devices showed no problems but app still crashes on actual device.
- MainActivity.cs - before Init()
Android.Gms.Ads.MobileAds.Initialize(ApplicationContext, "ca-app-pub-xxxx/xxxx");
- Android MAnifest.xml
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="xxx xxx" android:theme="@style/MainTheme" android:icon="@drawable/MainIcon">
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
</provider>
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxx~xxxx"/>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
I have a splash screen, which works fine without the Ads (it shows up first, then the app crashes), MainActivity is pointing to custom theme Theme = "@style/MyTheme.Splash" then MainActivity loads actual theme in OnCreate
SetTheme(Resource.Style.MainTheme);
Main Page has:
public class AdMobView : View { } <local:AdMobView x:Name="ADView" WidthRequest="320" HeightRequest="50" />
- AdMobRender:
public class AdMobViewRenderer : ViewRenderer<AdMobView, AdView> { public AdMobViewRenderer(Context context) : base(context) { } private AdView CreateAdView() { var adView = new AdView(Context) { AdSize = AdSize.Banner, AdUnitId = "ca-app-pub-xxxx/xxxx", LayoutParameters = new LinearLayout.LayoutParams(LayoutParams.MatchParent,LayoutParams.MatchParent) }; adView.LoadAd(new AdRequest.Builder().Build()); return adView; } protected override void OnElementChanged(ElementChangedEventArgs<AdMobView> e) { base.OnElementChanged(e); if (e.NewElement != null && Control == null) { SetNativeControl(CreateAdView()); } } }
I'm using:
VS19 Xamarin.Forms 4.8.0.1269
Xamarin.Essentials 1.5.3.2
Xamarin.Firebase.Lite 71.1601.4
Target Android Ver: 9.0 - 28 API
Min Version: 21 API
Thanks.
EDIT: Clean solution with only AddMod does not crash on actual devices. I can run my app in Debug Mode via VS19 on actual device without crashing - Released/Signed app still crashes on actual device.