Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly configure AdMob using IntelliJ IDEA?

Tags:

android

admob

I'm trying to incorporate AdMob into my Android application. I'm using IntelliJ IDEA for development and I cannot seem to set my project up properly. At this point I've done the following:

  1. Did all the preliminary steps necessary to download the AdMob SDK.
  2. Followed the directions here, trying to augment them for IntelliJ IDEA. I've added a Single-Entry Module Library dependency to the AdMob SDK to my project.

It looks like the IDE has no problem recognizing the classes from the SDK if I try to use them in code. However, it fails to resolve them in XML. I have the following two errors:

  1. Cannot resolve symbol 'AdActivity' when I set up the ad activity in AndroidManifest.xml the instructions call for.
  2. Element com.google.ads.AdView is not allowed here when I try to add an ad view to a layout in the manner documented here.

Thank you very much in advance for your help. I hope I've been clear.

EDIT

A clarification based on Cristian's answer. It's true that the first error seems to not matter. However, the second error causes the project build to break with the following message:

.../res/layout/main.xml:7: error: Error parsing XML: unbound prefix

The XML in question is the following layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

    <com.google.ads.AdView android:id="@+id/adView"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           ads:adUnitId="MY_AD_UNIT_ID"
                           ads:adSize="BANNER"
                           ads:loadAdOnCreate="true"/>

    <ImageView android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_alignParentTop="true"
               android:layout_marginLeft="123dp"
               android:src="@drawable/logo"/>

    <ImageView android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_alignParentBottom="true"
               android:layout_alignParentRight="true"
               android:src="@drawable/cart"/>

    <Button android:id="@+id/new_shopping_list"
            android:layout_width="223dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="90dp"
            android:text="@string/new_shopping_list_btn"/>

    <Button android:id="@+id/view_all_shopping_lists"
            android:layout_width="223dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/new_shopping_list"
            android:text="@string/saved_shopping_lists_btn"/>

    <ImageView android:id="@+id/copyright_notice"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_alignParentBottom="true"
               android:layout_alignParentRight="true"
               android:layout_marginBottom="7dp"
               android:layout_marginRight="5dp"
               android:src="@drawable/copyright"/>

    <ImageView android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_above="@id/copyright_notice"
               android:layout_alignParentRight="true"
               android:layout_marginBottom="5dp"
               android:layout_marginRight="4dp"
               android:src="@drawable/techsmart_logo"/>

    <ImageButton android:id="@+id/user_guide"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_alignParentBottom="true"
                 android:layout_alignParentLeft="true"
                 android:layout_marginBottom="7dp"
                 android:layout_marginLeft="5dp"
                 android:src="@drawable/user_guide"/>

</RelativeLayout>
like image 452
Lyudmil Avatar asked Aug 30 '11 15:08

Lyudmil


1 Answers

Do not worry about those errors. AdMob library is obfuscated, thus IntelliJ cannot read the correct names of the classes. However, your application will compile and run fine. This is how one of my projects looks like, and they work fine:

enter image description here

As you can see, there are other libraries like Pontiflex or AirPush that has the same problem.

With regards to your second problem, it seems you forget to add the XML NameSpace. This answer says that you must add this one:

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
like image 96
Cristian Avatar answered Oct 08 '22 19:10

Cristian