java.lang.NoClassDefFoundError:com.google.android.gms.ads.AdView错误

时间:2014-05-07 16:00:53

标签: android admob

我看过类似的问题,但他们无法解决我的问题。我已经安装了Google Play SDK,作为库导入到我的应用中。按照Admob的说明,我已经编写了以下代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.oguz.nfcdatareaderwriter.MainPage$PlaceholderFragment" >


<Button
    android:id="@+id/writeNFC"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/openingMessage"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="116dp"
    android:text="Write Custom Data to a Card" />

<TextView
    android:id="@+id/openingMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="174dp"
    android:text=".."
    android:textAppearance="?android:attr/textAppearanceLarge" />



</RelativeLayout>

主要活动:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_main_page);

      // Create an ad.
    adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId(AD_UNIT_ID);

    // Add the AdView to the view hierarchy. The view will have no size
    // until the ad is loaded.
    RelativeLayout layout = (RelativeLayout) findViewById(R.id.relative);
    layout.addView(adView);

    // Create an ad request. Check logcat output for the hashed device ID to
    // get test ads on a physical device.
    AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .addTestDevice("4df1dccd39006f0f")
        .build();

    // Start loading the ad in the background.
    adView.loadAd(adRequest);
}

2 个答案:

答案 0 :(得分:4)

如果您收到NoClassDefFoundError,那么您没有正确包含GooglePlayServices库,或者您已设法使用Proguard或类似方法排除类。尝试重做这些步骤。

答案 1 :(得分:2)

对我来说,将AdMob与Eclipse LUNA以及最后一个SDK和ADT一起使用非常困难。

我发现您必须按照以下顺序订购Java Build Path(右键单击属性):

Android Dependecies checked, Android xxx Unchecked, Android Private Librairies Checked

并在你的libs文件夹中控制google-play-services.jar在里面!