我正在尝试将AdMob合并到我的
Android应用程序中.我正在使用IntelliJ IDEA进行开发,我似乎无法正确设置我的项目.此时我已完成以下操作:
>是否需要下载AdMob SDK所需的所有初步步骤.
>按照指示here,试图为IntelliJ IDEA增加它们.我已将AdMob SDK的单入口模块库依赖项添加到我的项目中.
如果我尝试在代码中使用它,IDE看起来像是没有问题识别SDK中的类.但是,它无法在XML中解析它们.我有以下两个错误:
>当我在AndroidManifest.xml中设置广告活动时,无法解析符号’AdActivity’.
>当我尝试以文档here的方式向广告添加广告视图时,不允许使用元素com.google.ads.AdView.
非常感谢您的帮助.我希望我已经清楚了.
编辑
根据Cristian的回答进行澄清.确实,第一个错误似乎并不重要.但是,第二个错误导致项目构建中断以下消息:
… / res / layout / main.xml:7:错误:解析XML时出错:未绑定的前缀
有问题的XML是以下布局:
<?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>
解决方法
不要担心这些错误. AdMob库被混淆,因此IntelliJ无法读取类的正确名称.但是,您的应用程序将编译并运行正常.这是我的一个项目的样子,它们工作得很好:
正如您所看到的,还有像Pontiflex或AirPush这样的其他库存在同样的问题.
关于你的第二个问题,你似乎忘了添加XML NameSpace. This回答说你必须添加这个:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"