【发布时间】:2017-03-21 14:13:40
【问题描述】:
我正在尝试向我的应用程序添加广告。不幸的是,我查找的所有内容都无法提供帮助,因为它在移动文件夹的某个版本之前。我确实安装了谷歌播放服务。我不确定我是否遗漏了什么。我读过一些东西说我需要去 play_services_ads_lite 文件夹并从那里导入 jar 文件,我相信我也这样做了。但是,我一直在使用“@integer/google_play_services_version”找到资源
这是我的任务
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.coursebook"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
这是我的主要活动
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.coursebook.MainActivity" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<fragment
android:id="@+id/navigation_drawer"
android:name="com.example.coursebook.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="@layout/fragment_navigation_drawer" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="cxxxxxxxxxxxxxxxxxxx">
</com.google.android.gms.ads.AdView>
</android.support.v4.widget.DrawerLayout>
【问题讨论】:
-
你用的是android studio吗?如果这样做,您是否在 gradle 依赖项中包含“com.google.android.gms:play-services-ads:9.8.0”?
-
不,我正在使用 eclipse
-
Eclipse 现在可以支持 Gradle 依赖了
-
好的,我已经解决了这个问题,我有另一个问题,现在我收到一个错误,膨胀类 com.google.android.gms.ads.adview 日食问题