在我的项目中添加 AdMob?

Adding AdMob in my project?

我正在尝试在我的项目中添加 AdMob。问题是当我尝试构建项目时抛出一个关于 AndroidManifest 的 minSdkVersion 的异常。在我的 AndroidManifest 中,我将 minSdkVersion 设置为 8,并尝试将 minSdkVersion 更改为 9,但仍然无效。

我该如何解决?

异常

/home/fernando/workspace_2/app/src/main/AndroidManifest.xml
Error:(7, 5) uses-sdk:minSdkVersion 8 cannot be smaller than version 9 declared in library /home/fernando/workspace_2/app/build/intermediates/exploded-aar/com.google.android.gms/play-services/6.5.87/AndroidManifest.xml
Error:(7, 5) Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version 9 declared in library /home/fernando/workspace_2/app/build/intermediates/exploded-aar/com.google.android.gms/play-services/6.5.87/AndroidManifest.xml
    Suggestion: use tools:overrideLibrary="com.google.android.gms" to force usage

AndroidManifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="br.com.package.myapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <android:uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <android:uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <activity
            android:name=".act.SplashView"
            android:label="@string/app_name"
            android:configChanges="keyboardHidden|orientation"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".act.LoginView" />
        <activity android:name=".act.CadastrarView" />
        <activity android:name=".act.EsqueciSenha" />
        <activity android:name=".menu.CustomDrawerLayout"/>
        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />


    </application>

</manifest>

Gradle 依赖

compile 'com.google.android.gms:play-services:6.+'

我解决了这个问题。

我做到了

defaultConfig {
        applicationId "br.com.package.myapp"
        minSdkVersion 9
        targetSdkVersion 21
    }