2014-09-10 85 views
0

請發送測試AdMob中使用API​​的使用18(android4.2)或更高無法運行應用通過AdMob(幫助)錯誤(進口

MainActivity.java

錯誤在導入文件不存在相關的AdMob進口 com.google.android.gms.ads.AdRequest;進口 com.google.android.gms.ads.AdView;

package com.a.test; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import com.google.android.gms.ads.AdRequest; 
import com.google.android.gms.ads.AdView; 

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     AdRequest adRequest = new AdRequest.Builder() 
     .build(); 
     AdView adView = (AdView) view.findViewById(R.id.adView); 
     adView.loadAd(adRequest); 
    } 
} 

AndroidManifest .XML

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.a.test" 
    android:versionCode="1" 
    android:versionName="1.0" > 

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


    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.a.test.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name="com.google.android.gms.ads.AdActivity" 
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 

    </application> 

</manifest> 

佈局main.xml中

<RelativeLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="${packageName}.${activityClass}" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/hello_world" /> 

    <com.google.android.gms.ads.AdView android:id="@+id/adView" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          ads:adSize="BANNER" 
          ads:adUnitId="MY ID"/> 
</RelativeLayout> 
+0

您是否包含admob jar – 2014-09-10 15:48:27

+0

怎麼能得到admobsdk – user3783249 2014-09-10 15:52:46

回答

1

希望你已經引用了谷歌在項目中發揮服務庫。如果您還沒有,請確保您的/libs /文件夾中刪除了任何admob sdk jar,並在項目中引用google play服務庫版本4或更高版本。然後

在你的佈局,變化:

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 

到:

xmlns:ads="http://schemas.android.com/apk/res-auto" 

在您的清單,添加:

<meta-data 
     android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version" /> 

確保您的<application標籤中添加