Firebase ads: java.lang.InstantiationError: com.google.android.gms.internal.zznv

Firebase ads: java.lang.InstantiationError: com.google.android.gms.internal.zznv

将 AdMob 添加到我的 Android 应用程序让我抓狂 :o

Firebase 已经 运行(身份验证、数据库、...)。

我也添加了 gradle 对广告的依赖。
我完全按照 Google 说明进行操作。
我有两个问题:

  1. 我的 xml 布局文件中的 AdView 容器无法在预览中呈现。它说:

The following classes could not be instantiated: com.google.android.gms.ads.AdView

Exception Details java.lang.NoClassDefFoundError: Could not initialize class com.google.android.gms.internal.zzeh   at com.google.android.gms.internal.zzez.  at com.google.android.gms.internal.zzez.  at com.google.android.gms.internal.zzez.  at com.google.android.gms.ads.BaseAdView.  at com.google.android.gms.ads.AdView.  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)

  1. 如果我尝试在我的代码中初始化广告,它会在此代码行中崩溃:

MobileAds.initialize(getApplicationContext(), "ca-app-pub-XXXXXXXXXXXXXXXXX");

E/UncaughtException: java.lang.InstantiationError: com.google.android.gms.internal.zznv at com.google.android.gms.internal.zzeh.(Unknown Source) at com.google.android.gms.internal.zzeh.(Unknown Source) at com.google.android.gms.internal.zzfb.zza(Unknown Source) at com.google.android.gms.ads.MobileAds.initialize(Unknown Source) at com.google.android.gms.ads.MobileAds.initialize(Unknown Source) at de.philweb.myweightlog.MainActivity.onCreate(MainActivity.java:233)

我尝试了在 SO 上找到的所有内容。像 MultiDex 和添加 AdsActivity 来显示,没有成功。现在我真的需要你的帮助:(

谢谢大家, 菲尔

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.philweb.myweightlog">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/MyAppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
        </intent-filter>
    </activity>
    <!-- ATTENTION: This was auto-generated to add Google Play services to your project for App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information.
    -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

</application>

这是我的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"

    defaultConfig {
        applicationId "de.philweb.myweightlog"
        minSdkVersion 16
        targetSdkVersion 22
//        multiDexEnabled true
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
//    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.0.1' //22.2.0'
    compile 'com.android.support:support-v4:25.0.1' //22.2.0'
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.google.firebase:firebase-crash:10.0.1'
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.google.firebase:firebase-ads:10.0.1'
    compile 'com.google.firebase:firebase-appindexing:10.0.1'
//    compile 'com.android.support:multidex:1.0.1'

    compile 'com.android.support:design:25.0.1'
    compile 'com.firebaseui:firebase-ui:1.0.0'

    compile "com.androidplot:androidplot-core:1.4.0"
    compile 'com.darwinsys:hirondelle-date4j:1.5.1'
    compile('com.mikepenz:materialdrawer:5.8.0@aar') {
        transitive = true
    }
}

apply plugin: 'com.google.gms.google-services'
<uses-permission android:name="android.permission.INTERNET"/>

将其放入清单中。

包含库的大小和数量需要 Multidex。你说你试图启用它。请注意 three steps are required,包括对清单的更改。

此外,当使用 10.0.1 版的 Firebase 库时,您必须使用 1.0.1 版的 Firebase UI:

compile 'com.firebaseui:firebase-ui:1.0.1'

Firebase UI docs 包含 table 个兼容版本。