Admob安卓工作室,崩溃的应用程序

时间:2014-05-13 21:52:32

标签: android admob

我已经通过项目结构将admob .jar文件放在我的项目中:

enter image description here

我将admob横幅中的代码添加到我的布局文件中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#e5e5e5"

    android:orientation="vertical" >

    <com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adUnitId="taken out for stack"
        ads:adSize="BANNER"
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
        ads:loadAdOnCreate="true"/>


    <ListView
        android:id="@+id/yourTasteStatistics"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:dividerHeight="0px"
        android:divider="@null"

        >
    </ListView>


</LinearLayout>

但是当我打开带有广告的片段时,我的应用会自动崩溃...任何想法我必须在这里缺少哪一步?

这是输出:

05-13 17:56:44.053  12606-12606/com.beerportfolio.freeBP E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.beerportfolio.freeBP, PID: 12606
    android.view.InflateException: Binary XML file line #14: Error inflating class com.google.ads.AdView
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java)
            at android.view.LayoutInflater.inflate(LayoutInflater.java)
            at android.view.LayoutInflater.inflate(LayoutInflater.java)
            at com.beerportfolio.freeBP.BeerPage.onCreateView(BeerPage.java:30)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1097)
            at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1895)
            at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1514)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:958)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
            at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
            at android.os.Handler.handleCallback(Handler.java)
            at android.os.Handler.dispatchMessage(Handler.java)
            at android.os.Looper.loop(Looper.java)
            at android.app.ActivityThread.main(ActivityThread.java)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: DexPathList[[zip file "/data/app/com.beerportfolio.freeBP-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.beerportfolio.freeBP-1, /vendor/lib, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java)
            at java.lang.ClassLoader.loadClass(ClassLoader.java)
            at java.lang.ClassLoader.loadClass(ClassLoader.java)
            at android.view.LayoutInflater.createView(LayoutInflater.java)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java)
            at android.view.LayoutInflater.inflate(LayoutInflater.java)
            at android.view.LayoutInflater.inflate(LayoutInflater.java)
            at com.beerportfolio.freeBP.BeerPage.onCreateView(BeerPage.java:30)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1097)
            at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1895)
            at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1514)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:958)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
            at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
            at android.os.Handler.handleCallback(Handler.java)
            at android.os.Handler.dispatchMessage(Handler.java)
            at android.os.Looper.loop(Looper.java)
            at android.app.ActivityThread.main(ActivityThread.java)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
            at dalvik.system.NativeStart.main(Native Method)

第30行就是片段视图膨胀的地方。如果它不喜欢我的admob广告,那么它会在那里崩溃。

更新

如评论中所述,我使用的是过时的库。然后,我按照此链接获取有关如何更新以使用Google Play服务的说明。

https://developer.android.com/google/play-services/setup.html?hl=pt-br

我的问题出在这一步:

apply plugin: 'android'
...

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:4.3.23'
}

当我将其添加到我的等级时,gradle无法同步。我的成绩现在看起来像这样:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
        compile 'com.google.android.gms:play-services:4.3.23'

    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

并告诉我这个错误:

Error:(9, 0) Build script error, unsupported Gradle DSL method found: 'compile()'!

Possible causes could be:  
  - you are using Gradle version where the method is absent (<a href="open_gradle_settings">Fix Gradle settings</a>)
  - you didn't apply Gradle plugin which provides the method (<a href="apply_gradle_plugin">Apply Gradle plugin</a>)
  - or there is a mistake in a build script (<a href="goto_source">Goto source</a>)

1 个答案:

答案 0 :(得分:1)

您的依赖项块位于错误的位置。看起来您在顶级目录中编辑了build.gradle。

改为打开应用程序模块中的那个。那里应该有一个android块等。或者只是使用android studio中的项目结构对话框进行编辑。