xamarin / GooglePlayServicesComponents

Other
315 stars 146 forks source link

Xamarin.Firebase.Ads does not display Ad and reports app_id error #382

Closed darrylsk closed 4 years ago

darrylsk commented 4 years ago

Xamarin.Android Version:

Q 10.0 - API 29

Operating System & Version:

Windows 10

Google Play Services Version

Describe your Issue

When attempting to use Xamarin.Firebase.Ads to create a banner ad in my application, the banner ad fails to display, and the log_cat contains an error indicating missing app_id (error details attached below)

Relevant information

Xamarin Forms application built using Visual Studio 2019 Enterprise v16.7.2 The application works in debug and release mode on both the emulator and on a real phone (Samsug Galaxy A51 running Q 10)

Relevant project settings from *.csproj file:

Packages used:

<PackageReference Include="Xamarin.Forms" Version="4.8.0.1269" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
<PackageReference Include="Xamarin.AndroidX.Work.Runtime" Version="2.3.4.3" />

Build settings (tools)

<AndroidDexTool>d8</AndroidDexTool>
<AndroidLinkTool>r8</AndroidLinkTool>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidEnableDesugar>true</AndroidEnableDesugar>

SDK

Xamarin.Android SDK version 11.0.2.0

or even better - links to the existing code:

Minimal Repro Code Sample

In MainActivity.cs

    [Activity(Label = "House Money Trader", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {

        protected override void OnCreate(Bundle savedInstanceState)
        {
            // Initialise the AdMob Advertising widget.
            Android.Gms.Ads.MobileAds.Initialize(ApplicationContext, FactoryDefaults.ApplicationMobId);

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            LoadApplication(new App());

           Scheduler.ConfigureWorkManager();
        }

        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }

In AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.skmetrics.housemoney" android:installLocation="auto">
  <uses-sdk android:minSdkVersion="28" android:targetSdkVersion="29" />
  <application android:label="HouseMoney.Android" android:icon="@drawable/hmt_launcher_custom">
    <meta-data
      android:name="com.google.android.gms.ads.APPLICATION_ID"
      android:value="appid" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
    <activity android:name="com.google.android.gms.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
              android:theme="@android:style/Theme.Translucent" />
  </application>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
</manifest>

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

  1. Install the NuGet package "Xamarin.Firebase.Ads v71.1601.4" in the Andriod project of the solution.
  2. Build (Debug or Release) - solution builds successfully
  3. Click the Run button in Visual Studio. The emulator starts, the project deploys successfully. The debugger connects to the emulator and starts the application.
  4. Click the Browse Tab. The add fails to display. An error appears in the log_cat.

Log_cat excerpt

09-03 19:18:52.547: E/FA(16300): GoogleService failed to initialize, status: 10, Missing google app id value from from string resources with name google_app_id. 09-03 19:18:52.549: I/FA(16300): App measurement is starting up, version: 14711 09-03 19:18:52.549: I/FA(16300): To enable debug logging run: adb shell setprop log.tag.FA VERBOSE 09-03 19:18:52.549: I/FA(16300): To enable faster debug mode event logging run: 09-03 19:18:52.549: I/FA(16300): adb shell setprop debug.firebase.analytics.app com.companyname.originallist 09-03 19:18:52.554: E/FA(16300): Missing google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI 09-03 19:18:52.559: E/FA(16300): Uploading is not possible. App measurement disabled 09-03 19:18:52.657: D/Mono(16300): DllImport searching in: '__Internal' ('(null)'). 09-03 19:18:52.657: D/Mono(16300): Searching for 'java_interop_jnienv_get_object_field'.

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

Android_logcat_20200903-02.txt

darrylsk commented 4 years ago

The procedure outlined in the document "https://goog.gl/NAOOOI", referenced in the error message, is not intended for a xamarin app built with visual studio, so is not helpful. I've added a repo exhibiting the problem to github.

https://github.com/darrylsk/HouseMoneyTrader.git

The app_id has been removed from the repo. To test, add a valid app_id in MainActivity.cs and AndroidManifest.xml

darrylsk commented 4 years ago

The issue seems to have resolved. I did not change any code but received a Windows update and a Resharper update. Not sure if they are related. The build is still a little shaky and sometimes takes a couple of tries. Strange.