我正在尝试将 AdMob 合并到我的 Android 应用程序中。我正在使用 IntelliJ IDEA 进行开发,但似乎无法正确设置我的项目。此时我已完成以下操作:
- 已完成下载 AdMob SDK 所需的所有初步步骤。
- 遵循指示here http://code.google.com/mobile/ads/docs/android/fundamentals.html#incorporating,尝试为 IntelliJ IDEA 增强它们。我已将 AdMob SDK 的单入口模块库依赖项添加到我的项目中。
如果我尝试在代码中使用它们,IDE 似乎可以识别 SDK 中的类。但是,它无法在 XML 中解析它们。我有以下两个错误:
-
无法解析符号“AdActivity”当我设置广告活动时
AndroidManifest.xml
说明要求。
-
此处不允许使用元素 com.google.ads.AdView当我尝试以记录的方式将广告视图添加到布局时here http://code.google.com/mobile/ads/docs/android/banner_xml.html.
预先非常感谢您的帮助。我希望我已经说清楚了。
EDIT
基于克里斯蒂安的回答的澄清。确实,第一个错误似乎并不重要。但是,第二个错误导致项目构建中断,并显示以下消息:
.../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 命名空间。This https://stackoverflow.com/questions/2020542/what-is-correct-xmlns-url-for-admob-in-android-layout-xml/6092776#6092776答案说你必须添加这个:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)