gpt4 book ai didi

安卓工作室 AdMob

转载 作者:太空狗 更新时间:2023-10-29 13:28:10 27 4
gpt4 key购买 nike

我已经从 Eclipse 切换到使用 Android Studio 并且一切正常,除了尝试将 AdMob 合并到我的项目中时。我已经从我之前的项目中正确设置了代码,所以只需告诉 Android Studio 使用它进行构建即可。

我一直在阅读很多关于将 .jar 添加到 libs 文件夹的问题,但我认为最新版本的 Android Studio 改变了布局。所以我只是将它拖到 .idea > 库中,然后右键单击并“添加为库”。

在项目结构中,我有两个模块,和 -。在 - 下,它显示列出的所有依赖项,包括 support-v4-18.0.0 和 GoogleAdMobAdsSdk-6.4.1,标记为 Export and Compile for Scope。

在 Android Studio 的预览窗口中,它可以正确显示 AdView,但在运行时会崩溃。我已经尝试使用“gradlew clean”并多次重建项目但没有成功。

目前,该项目可以正常工作,除非我在任何布局上都有 AdView。如果我在页面上有它,我会得到“java.lang.ClassNotFoundException: com.google.ads.AdView”指向我使用 inflater 来膨胀我的布局的那一行。

调用堆栈:

    android.view.InflateException: Binary XML file line #155: Error inflating class com.google.ads.AdView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.awestruck.pokedex.Display_Main.onCreateView(Display_Main.java:53)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
at android.view.View.measure(View.java:15279)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4832)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15279)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4832)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15279)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15279)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4832)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2271)
at android.view.View.measure(View.java:15279)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2091)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1253)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1483)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1151)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4661)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.view.LayoutInflater.createView(LayoutInflater.java:552)

它指向这条线:

        v = inflater.inflate(R.layout.display_main, container, false);

build.gradle:

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}

apply plugin: 'android'



repositories {
mavenCentral()
}

android {
compileSdkVersion 18
buildToolsVersion "18.1.0"

defaultConfig {
minSdkVersion 11
targetSdkVersion 18
}
}

dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
}

感谢您的帮助。

最佳答案

问题解决了,过了一段时间,我成功搞定了。

对于任何想要解决此问题的人,请创建一个新的 libs 文件夹并将 GoogleAdMobAdsSdk-6.4.1.jar 放入其中。并确保您的依赖项是:

dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
}

虽然我不确定文件夹到底需要放在哪里,但我只是复制粘贴了每个人的同一个文件夹,然后运行:

gradlew clean

那么希望这会起作用。

关于安卓工作室 AdMob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19374039/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com