Forum Xamarin.Forms

Trying to implement Ads in a Forms project (Android for now, iOS down the road)

JKnottJKnott Member ✭✭✭

I'm trying to implement ads in my app, and eventually in-app purchases (to register a full version upgrade from free)

I've been following the tutorial from this site
https://www.c-sharpcorner.com/article/google-admob-display-ads-in-xamarin-forms/

I've created my AdMob Account, and added my app, I have the adUnitID, and from what I can tell that part is completed properly.

The problem I am having is when I try to compile the code, I get missing AndroidX assemblies,

Here is the specific error I am getting

Could not find 8 Android X assemblies, make sure to install the following NuGet packages:
 - Xamarin.AndroidX.Lifecycle.LiveData
 - Xamarin.Google.Android.Material
 - Xamarin.AndroidX.Legacy.Support.V4

(Please note it says 8 but only lists 3 assemblies)

I've tried installing those assemblies. Once they are installed I get two errors when I try to build.

one is
1>C:\Users\jesse\OneDrive\Documents\Source\...\obj\Debug\90\lp\124\jl\res\values\values.xml(1778): error APT2000: expected enum but got (raw string) slide.

Which is this line in the code

<item name="animationMode">slide</item>

And the other error is
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Aapt2.targets(164,3): error APT2062: failed linking references.

This is the linking reference it refers to.

<Aapt2Link
      Condition=" '$(_AndroidResourceDesignerFile)' != '' And '$(_AndroidUseAapt2)' == 'True' "
      ContinueOnError="$(DesignTimeBuild)"
      DaemonMaxInstanceCount="$(Aapt2DaemonMaxInstanceCount)"
      DaemonKeepInDomain="$(_Aapt2DaemonKeepInDomain)"
      ResourceNameCaseMap="$(_AndroidResourceNameCaseMap)"
      AssemblyIdentityMapFile="$(_AndroidLibrayProjectAssemblyMapFile)"
      ImportsDirectory="$(_LibraryProjectImportsDirectoryName)"
      UseShortFileNames="$(UseShortFileNames)"
      OutputImportDirectory="$(_AndroidLibrayProjectIntermediatePath)"
      OutputFile="$(ResgenTemporaryDirectory)\resources.apk"
      PackageName="$(_AndroidPackage)"
      ApplicationName="$(_AndroidPackage)"
      JavaPlatformJarPath="$(JavaPlatformJarPath)"
      JavaDesignerOutputDirectory="$(ResgenTemporaryDirectory)"
      CompiledResourceFlatFiles="@(_CompiledFlatFiles)"
      ManifestFiles="$(ResgenTemporaryDirectory)\AndroidManifest.xml"
      AdditionalAndroidResourcePaths="@(_LibraryResourceDirectories)"
      YieldDuringToolExecution="$(YieldDuringToolExecution)"
      ResourceSymbolsTextFile="$(IntermediateOutputPath)R.txt"
      ResourceDirectories="$(MonoAndroidResDirIntermediate)"
      ExtraArgs="$(AndroidAapt2LinkExtraArgs)"
      ToolPath="$(Aapt2ToolPath)"
      ToolExe="$(Aapt2ToolExe)"
      UncompressedFileExtensions="$(AndroidStoreUncompressedFileExtensions)"
      ProguardRuleOutput="$(_Aapt2ProguardRules)"
  />

If I change the SDK version to Android10, all of the errors go away, the package gets deployed, but will not show up in the app launcher, and will not start when I try to debug it.

I'm terrified at what it's going to be like to add the in app purchase for my app... (actually just considering making a separate app in the store and making a new build target / alternate code base to build it from)

Please, there has to be some way to implement ads in a Xamarin.Forms app, that supports Android 9...

Anyone who's implemented AdMob to a Xamarin.Forms app (I don't even care if it supports iOS for now. I would be nice for the future, but for now I just want to get my Android app up and running)

Please help!?

Best Answer

  • JKnottJKnott Member ✭✭✭
    Accepted Answer

    Well, I have figured out the first issue, the Android.Manifest.xml file had a bad line in it.

    Evidently I took the data from the site too literally. I was doubling the Application tag, and not just adding the activity that was needed.

    I've got this cleared for now, but am having a new problem.

    I'll post that one to a new question.

Answers

  • JKnottJKnott Member ✭✭✭
    Accepted Answer

    Well, I have figured out the first issue, the Android.Manifest.xml file had a bad line in it.

    Evidently I took the data from the site too literally. I was doubling the Application tag, and not just adding the activity that was needed.

    I've got this cleared for now, but am having a new problem.

    I'll post that one to a new question.

  • mdrouillardmdrouillard Member ✭✭
    edited January 13

    I am running into the same problem, but trying to use Firebase cloud messaging in the android project.

    1) I've got a similar error with the projects after adding Xamarin.GooglePlayServices.Base

    Severity Code Description Project File Line Suppression State
    Warning Could not find 23 Android X assemblies, make sure to install the following NuGet packages:
    - Xamarin.AndroidX.Lifecycle.LiveData
    - Xamarin.AndroidX.Browser
    - Xamarin.Google.Android.Material
    - Xamarin.AndroidX.Legacy.Support.V4
    You can also copy-and-paste the following snippet into your .csproj file:



    2) Manually installed the 4 missing packages

    3) Enabled AAT2 in Android Options in the project

    4) Stuck here:

    If someone knows the answer, PLEASE HELP. I tried upgrading to Android 10.0 and SDK, checked my AndroidManifest.xml as this guy did above; and still no luck.

  • mdrouillardmdrouillard Member ✭✭

    More context:

    Some snackbar control has this slide value in the generated values.xml file; what controls this generated output?

  • JKnottJKnott Member ✭✭✭

    @mdrouillard Hey there, I'm sorry to hear you're having the same issue, but also glad that the thread is getting a bump. From my limited understanding the slide is referring to a method of animating the ads when they get displayed. I can't say that as a definitive answer, but believe it's the case. Should I ever figure this out (I've moved to other parts of the code for the time being) I will come back and post any solutions or answers I find.

    Cheers!

  • mdrouillardmdrouillard Member ✭✭
    edited January 13

    Thanks @JKnott essentially it appears I can't use Firebase at all in my Xamarin project for push notifications now based on this, will have to revert the code. Which is a shame unless I come up with a solution.

    But I do think you're right this is related to the Snackbar which is a rotating ad from the AdMob stuff I have.

  • JKnottJKnott Member ✭✭✭

    No doubt. I am suffering from that I don't have a free taster version of my app, so my base is literally only 6 (including my test base). I want to get ads running so I can at least monetize a free version so I can at least get more users and make some even if minor income from the app.

    Here's to hoping for a simple and easy solution!

  • JKnottJKnott Member ✭✭✭

    @mdrouillard Well this has to be something of a sign...
    I am now getting the exact SAME ERROR.
    Here's the thing. I have NO Firebase or even any AdMob stuff in my code anymore.
    The only thing I've done is to update my libraries....

    What did you do to get this to go away in your code? I need to see if I can replicate your process whatever it was.

    Thanks!

  • mdrouillardmdrouillard Member ✭✭

    @JKnott Oh no! LOL.. So I managed to resolve the issue by backtracking the version of Xamarin.GooglePlayServices.Base:

    Dropped it back to 71.1610.4

  • JKnottJKnott Member ✭✭✭

    Yikes! that's what I was worried about. I don't have that or any of the google firebase, or admob libs. I'm going to have to take a look at rebuilding the project. I tried an archive version of the project, and it worked just fine.
    Thanks for the feedback!

Sign In or Register to comment.