0
votes

I am new to android and admob. I downloaded sdk...imported play service library and done every thing written on sdk documantation. But when I add the xml snippet:

<com.google.android.gms.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"/>

I get the following message in error log

com.google.android.gms.ads.AdView failed to instantiate. I know this question have been asked earlier but none work for me. error log for above error:

    eclipse.buildId=4.4.0.I20140606-1215
    java.version=1.8.0_05
    java.vendor=Oracle Corporation
    BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
    Framework arguments:  -product org.eclipse.epp.package.standard.product
    Command-line arguments:  -os win32 -ws win32 -arch x86 -product org.eclipse.epp.package.standard.product
    com.android.ide.eclipse.adt
    Error
    Fri Jul 18 00:43:46 IST 2014
    com.google.android.gms.ads.AdView failed to instantiate.
    java.lang.VerifyError: Expecting a stackmap frame at branch target 57
    Exception Details:
    Location:
    com/google/android/gms/ads/AdView.onMeasure(II)V @20: ifnull
    Reason:
    Expected stackmap frame at this location.
    Bytecode:
0000000: 033e 0336 042a 03b6 0015 3a05 2ab6 0014
0000010: 3a06 1905 c600 2519 05b6 000b 1008 9f00
0000020: 1b2a 1905 1b1c b600 1919 05b6 000a 3e19
0000030: 05b6 0009 3604 a700 1f19 06c6 001a 2ab6
0000040: 0016 3a07 1906 1907 b600 133e 1906 1907
0000050: b600 1236 041d 2ab6 0018 b800 2a3e 1504
0000060: 2ab6 0017 b800 2a36 042a 1d1b b800 0d15
0000070: 041c b800 0db6 001a b1                 
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:363)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:190)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:802)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:778)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:805)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:778)
at android.view.LayoutInflater.inflate(LayoutInflater.java:500)
at android.view.LayoutInflater.inflate(LayoutInflater.java:381)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:395)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:329)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:332)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:517)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1584)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1309)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.changed(GraphicalEditorPart.java:725)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.onTargetChange(GraphicalEditorPart.java:1196)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.onDescriptorsChanged(LayoutEditorDelegate.java:916)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegateInitUiRootNode(LayoutEditorDelegate.java:835)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$TargetListener.updateEditor(GraphicalEditorPart.java:953)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$TargetListener.onProjectTargetChange(GraphicalEditorPart.java:909)
at com.android.ide.eclipse.adt.AdtPlugin$10.run(AdtPlugin.java:1722)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:136)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4147)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3764)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:236)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)

Also i have switched to eclipse luna from kepler is this causing the problem? my xml file:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
 android:id="@+id/mainScreen"
 >
 <LinearLayout 
     android:layout_width="480dp"
     android:layout_height="75dp"
     android:layout_alignParentBottom="true">
      <com.google.android.gms.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="_id"
                     ads:adSize="BANNER"/>   
</LinearLayout>
</RelativeLayout>

I also tried to add banner programicaly.I got following error:

Description Resource Path Location Type Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode; myApp Unknown Android Packaging Problem

EDIT I searched for above error and i found the solution here https://stackoverflow.com/a/14004090/2647040

Now it doesnt shows any error while adding banner programicaly. It does shows same error error while adding banner through xml,but ads are now being shown on the emulator.

1
Does the device you are testing on have Google Play Services installed?Uwais A
Yes i did installed it.Shagun

1 Answers

3
votes

It looks like you may have two copies of the Admob classes. You might still have the old admob sdk as a library of your app while you are trying to use the new Google Play Services classes.

If you have the old admob sdk as well as Google Play services then remove the old admob sdk from your libs folder and clean your project it should solve the bug.