我刚刚完成了我的应用程序,现在我正在尝试实施AdMob广告。我使用的是Android Studio,这就是我完成它的方式。
首先,我将Google Play服务添加为依赖
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':zip_file')
compile project(':wheel')
compile project(':shake_detector')
compile project(':facebook')
compile 'com.google.android.gms:play-services:5.2.08'
}
然后我向AndroidManifest添加了必要的东西
<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"/>
然后我将广告添加到XML
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adUnitId="ca-app-pub-1606xxxx7xx50xx0/xxxx160xx2"
ads:adSize="BANNER"/>
只要我将广告添加到XML,XML编辑器就会显示错误:
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(Class.java:2493)
at java.lang.Class.getConstructor0(Class.java:2803)
at java.lang.Class.getConstructor(Class.java:1718)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:310)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:100)
at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:172)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:206)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:131)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:755)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:373)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:393)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:337)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:332)
at com.android.tools.idea.rendering.RenderService$3.compute(RenderService.java:575)
at com.android.tools.idea.rendering.RenderService$3.compute(RenderService.java:564)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:564)
at com.android.tools.idea.rendering.RenderService.render(RenderService.java:691)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:604)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1900(AndroidLayoutPreviewToolWindowManager.java:80)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:546)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:541)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
现在,每当我尝试运行应用程序(或构建项目)时,这就是我得到的错误
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException:无法运行命令: C:\ Android Development \ Android Studio \ sdk \ build-tools \ android-4.4W \ dx.bat --dex --num-threads = 4 --output C:\ Users \ whizs_000 \ AndroidStudioProjects \ Sleepwithnaturesounds \ app \ build \ intermediates \ dex \ debug C:\ Users \ whizs_000 \ AndroidStudioProjects \ Sleepwithnaturesounds \ app \ build \ intermediates \ classes \ debug C:\ Users \ whizs_000 \ AndroidStudioProjects \ Sleepwithnaturesounds \ app \ build \ intermediates \ dependency-cache \ debug C: \ Users \ whizs_000 \ AndroidStudioProjects \ Sleepwithnaturesounds \ app \ build \ intermediates \ pre-dexed \ debug \ android-support-v4-ee598d69cced4ae2d0367cf320b535877ffadf7a.jar C:\ Users \ whizs_000 \ AndroidStudioProjects \ Sleepwithnaturesounds \ app \ build \ intermediates \ pre-dexed \ debug \ bolts-70810bd866f930573e290daf7ec3dc1948286267.jar C:\ Users \ whizs_000 \ AndroidStudioProjects \ Sleepwithnaturesounds \ app \ build \ intermediates \ pre-dexed \ debug \ classes-0c36385bc77adc652fbbca692188f2ba3a839958.jar C:\ Users \ whizs_000 \ AndroidStudioProjects \ Sleepwithnaturesounds \ app \ build \中间体\预dexed \调试\类-2599f9358b4e94ed98b20719bc88ed4c00c1bfff.jar C:\ Users \ whizs_000 \ AndroidStudioProjects \ Sleepwithnaturesounds \ app \ build \ intermediates \ pre-dexed \ debug \ classes-3a8f3fce0efbd622d28c51e87741fcdeac2d6970.jar C:\ Users \ whizs_000 \ AndroidStudioProjects \ Sleepwithnaturesounds \ app \ build \ intermediates \ pre -dexed \ debug \ classes-407783d6a24b188172e1a767d67e0a0b4dae5728.jar C:\ Users \ whizs_000 \ AndroidStudioProjects \ Sleepwithnaturesounds \ app \ build \ intermediates \ pre-dexed \ debug \ classes-8067c76d4a10c4f3c1e28bb6e233007f282b8655.jar C:\ Users \ whizs_000 \ AndroidStudioProjects \ Sleepwithnaturesounds \ app \编译\中间体\预dexed \调试\支持,v4-19.1.0-3704bce472ca0d2a13ecadbd5f94b970f7bf2d0e.jar 错误代码: 2 输出: 意外的顶级例外情况: com.android.dex.DexException:多个dex文件定义了Landroid / support / v4 / accessibilityservice / AccessibilityServiceInfoCompat $ AccessibilityServiceInfoVersionImpl; 在com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594) 在com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552) 在com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533) 在com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170) 在com.android.dx.merge.DexMerger.merge(DexMerger.java:188) 在com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439) 在com.android.dx.command.dexer.Main.runMonoDex(Main.java:287) 在com.android.dx.command.dexer.Main.run(Main.java:230) 在com.android.dx.command.dexer.Main.main(Main.java:199) 在com.android.dx.command.Main.main(Main.java:103)
知道可能出现什么问题吗?上次我正在实施广告时,我在Eclipse中这样做,所以我在AS中有点新鲜。
答案 0 :(得分:1)
[...]意外的顶级例外:com.android.dex.DexException:多个dex文件定义了Landroid / support / v4 / [...]。
这表明构建过程中包含多余/重复的库。请检查项目中的libs/
文件夹和任何包含的库。
编译'com.google.android.gms:play-services:5.2.08'
请使用版本5.0.89而不是5.2.08,因为后一版本尚未推出,使用它的应用无法在Google Play上发布。